Skip to content

Commit 771f199

Browse files
committed
Implement a new use syntax
This commit implements a new `use` syntax which changes (use "foo.witx") to (use $some $type $names from $foo) This change ended up being much larger than originally intended. While at a surface level switching this style of `use` statements isn't too bad it has large ramifications on the mental model of how to interpret and work with `*.witx` files. This necessitated some internal refactorings which ended up as a bit of a yak shave. The other changes here are: * The `polyfill` module is removed. I confirmed with Pat that this isn't used anymore and this came about trying to update it from the below refactorings. * The `render` module is removed. Documents can no longer be serialized to a standalone s-expression because they can refer to other documents in a structured manner. It's also believed there are no current users of this functionality. * The `representation` module was removed since it was largely only used by the `polyfill` module. * The `Document` type was renamed to `Module`, and the ability for a document to contain multiple modules has been removed. When working with multiple modules this must now be done so explicitly instead of having it all lumped into one parsed object. This means that `Module` is now a list of types and a list of functions. * Documentation has changed to document a set of modules instead of a single module. Additionally this is nontrivially changed to load types transitively from all modules referenced to ensure that all relevant types are documented. * Internal refactorings in the validation phase have been done to streamline a few things and consolidate where possible with this new structuring. * `InterfaceFunc` is now named `Function` * `InterfaceFuncParam` is now named `Param` * `Module` has a `name` (as before) which is now inferred from the filename it's loaded from. * `Module` has a `ModuleId` now to represent types that are defined in other modules, where `ModuleId` is intended to be a unique identifier amongst a set of modules. For now it's just a path name but can likely get more fancy in the future if needed. All `*.witx` files have been updated to the new syntax in this repository. Lots of changes look like they happened to the proposal documentation, but that's just because the documentation order of types has been shuffled around. I've checked to make sure no actual items were lost from the documentation. Closes #378 Closes #379
1 parent a9671af commit 771f199

39 files changed

+3761
-5117
lines changed

phases/ephemeral/docs.md

Lines changed: 527 additions & 553 deletions
Large diffs are not rendered by default.

phases/ephemeral/witx/wasi_ephemeral_args.witx

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,20 @@
33
;; This is a `witx` file. See [here](https://github.com/WebAssembly/WASI/tree/master/docs/witx.md)
44
;; for an explanation of what that means.
55

6-
(use "typenames.witx")
6+
(use $errno $size from $typenames)
77

8-
(module $wasi_ephemeral_args
9-
;;; Linear memory to be accessed by WASI functions that need it.
10-
(import "memory" (memory))
11-
12-
;;; Read command-line argument data.
13-
;;; The size of the array should match that returned by `sizes_get`.
14-
;;; Each argument is expected to be `\0` terminated.
15-
(@interface func (export "get")
16-
(param $argv (@witx pointer (@witx pointer (@witx char8))))
17-
(param $argv_buf (@witx pointer (@witx char8)))
18-
(result $error (expected (error $errno)))
19-
)
8+
;;; Read command-line argument data.
9+
;;; The size of the array should match that returned by `sizes_get`.
10+
;;; Each argument is expected to be `\0` terminated.
11+
(@interface func (export "get")
12+
(param $argv (@witx pointer (@witx pointer (@witx char8))))
13+
(param $argv_buf (@witx pointer (@witx char8)))
14+
(result $error (expected (error $errno)))
15+
)
2016

21-
;;; Return command-line argument data sizes.
22-
(@interface func (export "sizes_get")
23-
;;; Returns the number of arguments and the size of the argument string
24-
;;; data, or an error.
25-
(result $error (expected (tuple $size $size) (error $errno)))
26-
)
17+
;;; Return command-line argument data sizes.
18+
(@interface func (export "sizes_get")
19+
;;; Returns the number of arguments and the size of the argument string
20+
;;; data, or an error.
21+
(result $error (expected (tuple $size $size) (error $errno)))
2722
)

phases/ephemeral/witx/wasi_ephemeral_clock.witx

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,26 @@
55
;; This is a `witx` file. See [here](https://github.com/WebAssembly/WASI/tree/master/docs/witx.md)
66
;; for an explanation of what that means.
77

8-
(use "typenames.witx")
8+
(use $errno $clockid $timestamp from $typenames)
99

10-
(module $wasi_ephemeral_clock
11-
;;; Linear memory to be accessed by WASI functions that need it.
12-
(import "memory" (memory))
13-
14-
;;; Return the resolution of a clock.
15-
;;; Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks,
16-
;;; return `errno::inval`.
17-
;;; Note: This is similar to `clock_getres` in POSIX.
18-
(@interface func (export "res_get")
19-
;;; The clock for which to return the resolution.
20-
(param $id $clockid)
21-
;;; The resolution of the clock.
22-
(result $error (expected $timestamp (error $errno)))
23-
)
10+
;;; Return the resolution of a clock.
11+
;;; Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks,
12+
;;; return `errno::inval`.
13+
;;; Note: This is similar to `clock_getres` in POSIX.
14+
(@interface func (export "res_get")
15+
;;; The clock for which to return the resolution.
16+
(param $id $clockid)
17+
;;; The resolution of the clock.
18+
(result $error (expected $timestamp (error $errno)))
19+
)
2420

25-
;;; Return the time value of a clock.
26-
;;; Note: This is similar to `clock_gettime` in POSIX.
27-
(@interface func (export "time_get")
28-
;;; The clock for which to return the time.
29-
(param $id $clockid)
30-
;;; The maximum lag (exclusive) that the returned time value may have, compared to its actual value.
31-
(param $precision $timestamp)
32-
;;; The time value of the clock.
33-
(result $error (expected $timestamp (error $errno)))
34-
)
21+
;;; Return the time value of a clock.
22+
;;; Note: This is similar to `clock_gettime` in POSIX.
23+
(@interface func (export "time_get")
24+
;;; The clock for which to return the time.
25+
(param $id $clockid)
26+
;;; The maximum lag (exclusive) that the returned time value may have, compared to its actual value.
27+
(param $precision $timestamp)
28+
;;; The time value of the clock.
29+
(result $error (expected $timestamp (error $errno)))
3530
)

phases/ephemeral/witx/wasi_ephemeral_environ.witx

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,20 @@
33
;; This is a `witx` file. See [here](https://github.com/WebAssembly/WASI/tree/master/docs/witx.md)
44
;; for an explanation of what that means.
55

6-
(use "typenames.witx")
6+
(use $size $errno from $typenames)
77

8-
(module $wasi_ephemeral_environ
9-
;;; Linear memory to be accessed by WASI functions that need it.
10-
(import "memory" (memory))
11-
12-
;;; Read environment variable data.
13-
;;; The sizes of the buffers should match that returned by `sizes_get`.
14-
;;; Key/value pairs are expected to be joined with `=`s, and terminated with `\0`s.
15-
(@interface func (export "get")
16-
(param $environ (@witx pointer (@witx pointer (@witx char8))))
17-
(param $environ_buf (@witx pointer (@witx char8)))
18-
(result $error (expected (error $errno)))
19-
)
8+
;;; Read environment variable data.
9+
;;; The sizes of the buffers should match that returned by `sizes_get`.
10+
;;; Key/value pairs are expected to be joined with `=`s, and terminated with `\0`s.
11+
(@interface func (export "get")
12+
(param $environ (@witx pointer (@witx pointer (@witx char8))))
13+
(param $environ_buf (@witx pointer (@witx char8)))
14+
(result $error (expected (error $errno)))
15+
)
2016

21-
;;; Return environment variable data sizes.
22-
(@interface func (export "sizes_get")
23-
;;; Returns the number of environment variable arguments and the size of the
24-
;;; environment variable data.
25-
(result $error (expected (tuple $size $size) (error $errno)))
26-
)
17+
;;; Return environment variable data sizes.
18+
(@interface func (export "sizes_get")
19+
;;; Returns the number of environment variable arguments and the size of the
20+
;;; environment variable data.
21+
(result $error (expected (tuple $size $size) (error $errno)))
2722
)

0 commit comments

Comments
 (0)