Skip to content

Commit ec27938

Browse files
bakkotptomato
andcommitted
Avoid nonstandard use of names for types in wit-0.3.0-draft
Co-authored-by: Philip Chimento <[email protected]>
1 parent 3850f9d commit ec27938

File tree

5 files changed

+31
-27
lines changed

5 files changed

+31
-27
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,24 @@ default-monotonic-clock: monotonic-clock
7878
let stop: Instant = monotonic_clock::now(clock);
7979

8080
let elapsed: Instant = stop - start;
81+
// NOTE: should be `elapsed: Duration`?
8182
```
8283

8384

8485
#### Telling the current human time:
8586

8687
```rust
87-
let the_current_time = wall_clock::now();
88+
let the_current_time = system_clock::now();
8889

8990
println!("it has been {} seconds and {} nanoseconds since the Unix epoch!", the_current_time.seconds, the_current_time.nanoseconds);
9091
```
9192

9293
#### Retrieving the timezone:
9394

9495
```rust
95-
let datetime: Datetime = wall_clock::now();
96+
let instant: Instant = system_clock::now();
9697

97-
let timezone_display: TimezoneDisplay = timezone::display(datetime);
98+
let timezone_display: TimezoneDisplay = timezone::display(instant);
9899

99100
println!("the timezone is {}", timezone_display.name);
100101
```
@@ -105,14 +106,14 @@ default-monotonic-clock: monotonic-clock
105106

106107
In POSIX, `clock_gettime` uses a single `timespec` type to represent timestamps
107108
from all clocks, with two fields: seconds and nanoseconds. However, in applications
108-
that just need to measure elapsed time, and don't need to care about wall clock
109+
that just need to measure elapsed time, and don't need to care about absolute
109110
time, working with seconds and nanoseconds as separate fields adds extra code size
110111
and complexity. For these use cases, a single 64-bit nanoseconds value, which can
111112
measure up to about 584 years, is sufficient and simpler.
112113

113-
For wall clock time, it's still useful to have both seconds and nanoseconds, both
114+
For system time, it's still useful to have both seconds and nanoseconds, both
114115
to be able to represent dates in the far future, and to reflect the fact that
115-
code working with wall clock time will often want to treat seconds and fractions
116+
code working with system time will often want to treat seconds and fractions
116117
of seconds differently.
117118

118119
And so, this API uses different data types for different types of clocks.

wit-0.3.0-draft/monotonic-clock.wit

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package wasi:[email protected];
99
/// successive reads of the clock will produce non-decreasing values.
1010
@since(version = 0.3.0)
1111
interface monotonic-clock {
12-
/// An instant in time, in nanoseconds. An instant is relative to an
12+
/// A monotonic clock point in nanoseconds. A clock point is relative to an
1313
/// unspecified initial value, and can only be compared to instances from
1414
/// the same monotonic-clock.
1515
@since(version = 0.3.0)
@@ -24,17 +24,17 @@ interface monotonic-clock {
2424
/// The clock is monotonic, therefore calling this function repeatedly will
2525
/// produce a sequence of non-decreasing values.
2626
@since(version = 0.3.0)
27-
now: func() -> instant;
27+
now: func() -> monotonic-clock-point;
2828

2929
/// Query the resolution of the clock. Returns the duration of time
3030
/// corresponding to a clock tick.
3131
@since(version = 0.3.0)
3232
resolution: func() -> duration;
3333

34-
/// Wait until the specified instant has occurred.
34+
/// Wait until the specified clock point has occurred.
3535
@since(version = 0.3.0)
3636
wait-until: func(
37-
when: instant,
37+
when: monotonic-clock-point,
3838
);
3939

4040
/// Wait for the specified duration has elapsed.

wit-0.3.0-draft/wall-clock.wit renamed to wit-0.3.0-draft/system-clock.wit

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
package wasi:clocks@0.3.0;
2-
/// WASI Wall Clock is a clock API intended to let users query the current
3-
/// time. The name "wall" makes an analogy to a "clock on the wall", which
4-
/// is not necessarily monotonic as it may be reset.
2+
/// WASI System Clock is a clock API intended to let users query the current
3+
/// time. The clock is not necessarily monotonic as it may be reset.
54
///
65
/// It is intended to be portable at least between Unix-family platforms and
76
/// Windows.
87
///
9-
/// A wall clock is a clock which measures the date and time according to
10-
/// some external reference.
8+
/// An "instant", or "exact time", is a point in time without regard to any time
9+
/// zone: just the time since a particular external reference point, often
10+
/// called an "epoch".
1111
///
1212
/// External references may be reset, so this clock is not necessarily
1313
/// monotonic, making it unsuitable for measuring elapsed time.
1414
///
1515
/// It is intended for reporting the current date and time for humans.
1616
@since(version = 0.3.0)
17-
interface wall-clock {
18-
/// A time and date in seconds plus nanoseconds.
17+
interface system-clock {
18+
/// An exact time in seconds plus nanoseconds.
1919
@since(version = 0.3.0)
20-
record datetime {
20+
record instant {
2121
seconds: u64,
2222
nanoseconds: u32,
2323
}
@@ -36,11 +36,14 @@ interface wall-clock {
3636
/// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16
3737
/// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time
3838
@since(version = 0.3.0)
39-
now: func() -> datetime;
39+
now: func() -> instant;
4040

4141
/// Query the resolution of the clock.
4242
///
4343
/// The nanoseconds field of the output is always less than 1000000000.
4444
@since(version = 0.3.0)
45-
resolution: func() -> datetime;
45+
resolution: func() -> instant;
46+
// NOTE: This return value doesn't represent an exact time, so maybe is not
47+
// a correct use of the Instant type. Would it make sense to have a
48+
// system-clock::duration analogous to monotonic-clock::duration?
4649
}

wit-0.3.0-draft/timezone.wit

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ package wasi:[email protected];
33
@unstable(feature = clocks-timezone)
44
interface timezone {
55
@unstable(feature = clocks-timezone)
6-
use wall-clock.{datetime};
6+
use system-clock.{instant};
77

8-
/// Return information needed to display the given `datetime`. This includes
8+
/// Return information needed to display the given `instant`. This includes
99
/// the UTC offset, the time zone name, and a flag indicating whether
1010
/// daylight saving time is active.
1111
///
12-
/// If the timezone cannot be determined for the given `datetime`, return a
12+
/// If the timezone cannot be determined for the given `instant`, return a
1313
/// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight
1414
/// saving time.
1515
@unstable(feature = clocks-timezone)
16-
display: func(when: datetime) -> timezone-display;
16+
display: func(when: instant) -> timezone-display;
1717

1818
/// The same as `display`, but only return the UTC offset.
1919
@unstable(feature = clocks-timezone)
20-
utc-offset: func(when: datetime) -> s32;
20+
utc-offset: func(when: instant) -> s32;
2121

22-
/// Information useful for displaying the timezone of a specific `datetime`.
22+
/// Information useful for displaying the timezone of a specific `instant`.
2323
///
2424
/// This information may vary within a single `timezone` to reflect daylight
2525
/// saving time adjustments.

wit-0.3.0-draft/world.wit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ world imports {
55
@since(version = 0.3.0)
66
import monotonic-clock;
77
@since(version = 0.3.0)
8-
import wall-clock;
8+
import system-clock;
99
@unstable(feature = clocks-timezone)
1010
import timezone;
1111
}

0 commit comments

Comments
 (0)