Skip to content

Commit f1a63db

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 6bb5146 commit f1a63db

File tree

5 files changed

+45
-34
lines changed

5 files changed

+45
-34
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,30 +71,30 @@ default-monotonic-clock: monotonic-clock
7171
```
7272

7373
```rust
74-
let start: Instant = monotonic_clock::now(clock);
74+
let start: Mark = monotonic_clock::now(clock);
7575

7676
// some stuff
7777

78-
let stop: Instant = monotonic_clock::now(clock);
78+
let stop: Mark = monotonic_clock::now(clock);
7979

80-
let elapsed: Instant = stop - start;
80+
let elapsed: Duration = stop - start;
8181
```
8282

8383

8484
#### Telling the current human time:
8585

8686
```rust
87-
let the_current_time = wall_clock::now();
87+
let the_current_time = system_clock::now();
8888

8989
println!("it has been {} seconds and {} nanoseconds since the Unix epoch!", the_current_time.seconds, the_current_time.nanoseconds);
9090
```
9191

9292
#### Retrieving the timezone:
9393

9494
```rust
95-
let datetime: Datetime = wall_clock::now();
95+
let instant: Instant = system_clock::now();
9696

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

9999
println!("the timezone is {}", timezone_display.name);
100100
```
@@ -105,14 +105,14 @@ default-monotonic-clock: monotonic-clock
105105

106106
In POSIX, `clock_gettime` uses a single `timespec` type to represent timestamps
107107
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
108+
that just need to measure elapsed time, and don't need to care about absolute
109109
time, working with seconds and nanoseconds as separate fields adds extra code size
110110
and complexity. For these use cases, a single 64-bit nanoseconds value, which can
111111
measure up to about 584 years, is sufficient and simpler.
112112

113-
For wall clock time, it's still useful to have both seconds and nanoseconds, both
113+
For system time, it's still useful to have both seconds and nanoseconds, both
114114
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
115+
code working with system time will often want to treat seconds and fractions
116116
of seconds differently.
117117

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

wit-0.3.0-draft/monotonic-clock.wit

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ 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 mark on a monotonic clock is a number of nanoseconds since an
1313
/// unspecified initial value, and can only be compared to instances from
1414
/// the same monotonic-clock.
1515
@since(version = 0.3.0)
16-
type instant = u64;
16+
type mark = u64;
1717

1818
/// A duration of time, in nanoseconds.
1919
@since(version = 0.3.0)
@@ -24,20 +24,20 @@ 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() -> mark;
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
get-resolution: func() -> duration;
3333

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

40-
/// Wait for the specified duration has elapsed.
40+
/// Wait for the specified duration.
4141
@since(version = 0.3.0)
4242
wait-for: async func(
4343
how-long: duration,
Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
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.
11-
///
128
/// External references may be reset, so this clock is not necessarily
139
/// monotonic, making it unsuitable for measuring elapsed time.
1410
///
1511
/// It is intended for reporting the current date and time for humans.
1612
@since(version = 0.3.0)
17-
interface wall-clock {
18-
/// A time and date in seconds plus nanoseconds.
13+
interface system-clock {
14+
/// An "instant", or "exact time", is a point in time without regard to any
15+
/// time zone: just the time since a particular external reference point,
16+
/// often called an "epoch".
17+
/// Note that even if the seconds field is negative, incrementing
18+
/// nanoseconds always represents moving forwards in time.
19+
/// For example, `{ -1 seconds, 999999999 nanoseconds }` represents the
20+
/// instant one nanosecond before the epoch.
21+
/// For more on various different ways to represent time, see
22+
/// https://tc39.es/proposal-temporal/docs/timezone.html
1923
@since(version = 0.3.0)
20-
record datetime {
21-
seconds: u64,
24+
record instant {
25+
seconds: s64,
2226
nanoseconds: u32,
2327
}
2428

29+
/// A duration of time, in seconds plus nanoseconds.
30+
@since(version = 0.3.0)
31+
type duration = {
32+
seconds: u64,
33+
nanoseconds: u32,
34+
};
35+
2536
/// Read the current value of the clock.
2637
///
2738
/// This clock is not monotonic, therefore calling this function repeatedly
@@ -36,11 +47,11 @@ interface wall-clock {
3647
/// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16
3748
/// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time
3849
@since(version = 0.3.0)
39-
now: func() -> datetime;
50+
now: func() -> instant;
4051

4152
/// Query the resolution of the clock.
4253
///
4354
/// The nanoseconds field of the output is always less than 1000000000.
4455
@since(version = 0.3.0)
45-
get-resolution: func() -> datetime;
56+
get-resolution: func() -> duration;
4657
}

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)