-
Notifications
You must be signed in to change notification settings - Fork 19
Avoid nonstandard use of names for types in wit-0.3.0-draft #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,38 @@ | ||
package wasi:clocks@0.3.0-rc-2025-09-16; | ||
/// WASI Wall Clock is a clock API intended to let users query the current | ||
/// time. The name "wall" makes an analogy to a "clock on the wall", which | ||
/// is not necessarily monotonic as it may be reset. | ||
/// WASI System Clock is a clock API intended to let users query the current | ||
/// time. The clock is not necessarily monotonic as it may be reset. | ||
/// | ||
/// It is intended to be portable at least between Unix-family platforms and | ||
/// Windows. | ||
/// | ||
/// A wall clock is a clock which measures the date and time according to | ||
/// some external reference. | ||
/// | ||
/// External references may be reset, so this clock is not necessarily | ||
/// monotonic, making it unsuitable for measuring elapsed time. | ||
/// | ||
/// It is intended for reporting the current date and time for humans. | ||
@since(version = 0.3.0-rc-2025-09-16) | ||
interface wall-clock { | ||
/// A time and date in seconds plus nanoseconds. | ||
interface system-clock { | ||
/// An "instant", or "exact time", is a point in time without regard to any | ||
/// time zone: just the time since a particular external reference point, | ||
/// often called an "epoch". | ||
/// Note that even if the seconds field is negative, incrementing | ||
/// nanoseconds always represents moving forwards in time. | ||
/// For example, `{ -1 seconds, 999999999 nanoseconds }` represents the | ||
/// instant one nanosecond before the epoch. | ||
/// For more on various different ways to represent time, see | ||
/// https://tc39.es/proposal-temporal/docs/timezone.html | ||
@since(version = 0.3.0-rc-2025-09-16) | ||
record datetime { | ||
seconds: u64, | ||
record instant { | ||
seconds: s64, | ||
nanoseconds: u32, | ||
Comment on lines
+25
to
26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is correct IMO, but might be worth a note that nanoseconds are unsigned because even negative seconds values are still conceptually "positive" exact times. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I was just thinking of this as, the way you'd represent one nanosecond before the epoch would be { -1 seconds, +999_999_999 nanoseconds }. I'm not sure what you mean by 'conceptually "positive" exact times'. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, I think of it in the same way as you. What I meant is Dec 31 1969 isn't "negative" in any way other than being before the epoch, which is arbitrary. The (wrong) alternative interpretation would be to think of { seconds, nanoseconds } as a "duration" before the epoch, e.g. -1.999999999 nanoseconds. That would result in Dec 31 1969 23:59:58.000000001. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a note which hopefully clarifies:
|
||
} | ||
|
||
/// A duration of time, in seconds plus nanoseconds. | ||
@since(version = 0.3.0-rc-2025-09-16) | ||
type duration = { | ||
bakkot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
seconds: u64, | ||
nanoseconds: u32, | ||
}; | ||
bakkot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// Read the current value of the clock. | ||
/// | ||
/// This clock is not monotonic, therefore calling this function repeatedly | ||
|
@@ -36,11 +47,11 @@ interface wall-clock { | |
/// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 | ||
/// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time | ||
@since(version = 0.3.0-rc-2025-09-16) | ||
now: func() -> datetime; | ||
now: func() -> instant; | ||
|
||
/// Query the resolution of the clock. | ||
/// | ||
/// The nanoseconds field of the output is always less than 1000000000. | ||
@since(version = 0.3.0-rc-2025-09-16) | ||
get-resolution: func() -> datetime; | ||
get-resolution: func() -> duration; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We originally avoided the term "system clock", but I think it's ok to use now.
Background: we wanted WASI to deemphasize the idea of "the system", because that may suggest a level of monolithicity that we don't want to require. However, if "wall clock" isn't suitable, I'm guessing we won't find any other names that have the desired meaning without risk of being mistaken. So unless we think of some brilliant alternative name, I think "system clock" is the least-problematic option.