Skip to content
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

witx: a wasi_unstable description based on module types. #74

Merged
merged 26 commits into from
Sep 12, 2019

Conversation

sunfishcode
Copy link
Member

This sketches out a description of the current wasi_unstable API, using a syntax which anticipates the "module types" syntax recently proposed to the CG, though it does use a few extensions which can be easily lowered, and which mostly anticipate the Interface Types proposal.

This is derived from the WatIDL proposal, though it differs in a few ways:

  • It doesn't yet do anything special for capabilities, for now. File descriptors are just integers, for now. But the idea is that we could add OCAP concepts later.

  • It uses a new (flags ...) construct in place of structs of Bool fields, to describe flags values. This allows us to explicitly declare the underlying wasm type for flags values.

  • Types used by the API are declared outside of the moduletype, because we're using wat syntax as much as possible, and there, (type ...) inside a module declares an entry in the type section, which isn't what's intended here.

The extensions to module types are:

  • It uses string, array, and {s,u}{8,16,32,64} types, which are expected to be provided in some form by the Interface Types proposal. For now though, they can all be lowered in straightforward ways, by assuming that string is always just UTF-8.

  • It adds typename declarations, which can name any wasm type, and of the extra types mentioned in the previous item, or struct, enum, or flags.

  • It declares functions with multiple return values, which for now will need to be lowered to output (pointer) parameters.

This sketches out a description of the current wasi_unstable API, using a syntax which anticipates the "module types" syntax [recently proposed to the CG](https://github.com/WebAssembly/meetings/blob/master/2019/CG-08-06.md#discuss-new-proposal-that-introduces-types-for-modules-and-instances-and-text-format-thereof-as-initially-discussed-in-design1289), though it does use a few extensions which can be easily lowered, and which mostly anticipate the [Interface Types](WebAssembly/interface-types#47 (comment)) proposal.

This is derived from [the WatIDL proposal](WebAssembly#64), though it differs in a few ways:
 - It doesn't yet do anything special for capabilities, for now. File descriptors are just integers, for now. But the idea is that we could add OCAP concepts later.

 - It uses a new `(flags ...)` construct in place of structs of Bool fields, to describe flags values. This allows us to explicitly declare the underlying wasm type for flags values.

 - Types used by the API are declared outside of the moduletype, because we're using wat syntax as much as possible, and there, `(type ...)` inside a module declares an entry in the type section, which isn't what's intended here.

The extensions to module types are:
 - It uses `string`, `array`, and `{s,u}{8,16,32,64}` types, which are expected to be provided in some form by the Interface Types proposal.  For now though, they can all be lowered in straightforward ways, by assuming that `string` is always just UTF-8.

 - It adds `typename` declarations, which can name any wasm type, and of the extra types mentioned in the previous item, or `struct`, `enum`, or `flags`.

 - It declares functions with multiple return values, which for now will need to be lowered to output (pointer) parameters.
sunfishcode and others added 18 commits September 4, 2019 15:13
This replaces the "data" type. It'll be desirable to use higher-level
types to describe what iovec/ciovec do, however to avoid getting into
IDL design questions, for now just use explicit pointer and length
values to keep things simple.
Only use `(typename ...)` to declare named types; don't use it for
inline types.
It isn't logically part of the `wasi_unstable` module. It's part of the
platform-level ABI.
We're not currently using a method-oriented API, so instead of saying
"self", say "fd", which is what these parameters are.
This adds new constructs, (@WitX pointer T), and (@WitX const_pointer T),
and uses them to describe raw pointers to linear memory buffers. For
now, these can be treated essentially the same as $uintptr_t, though in
the future we may do something more sophisticated.
@sunfishcode sunfishcode changed the title A wasi_unstable description based on module types. witx: a wasi_unstable description based on module types. Sep 5, 2019
(param $fd $fd_t)
(result $error $errno_t)
;; The buffer where the description is stored.
(result $buf $prestat_t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like prestat_t is not defined (related to #51).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot! I've now added it.

@pchickey
Copy link
Contributor

There are a handful of fixes in https://github.com/fastly/lucet/pull/275/files#diff-1ac8557cf1c286d69d13ccaa4b21d291 that get these files to "validate", at least as far as lucet-idl is concerned. Most of the changes were either typo fixes, or changing the ordering of typenames so that all types are defined before use.

We don't necessarily have to enforce that names are defined before use, but it does make implementation a bit easier, and it has precedent in wasm.

The wat format allows forward references to '$' identifiers, so we'll
probably have to support this eventually too, but for now, reorder
things to make it easy to process.
@sunfishcode
Copy link
Member Author

@pchickey Thanks! I've now made an attempt to merge your changes into the PR here.

The wat format does allow '$' names to be used before defined in the file, so we should eventually support that. That said, it's not urgent, and I've incorporated your reordering changes in the PR here as well for now.

cjihrig added a commit to nodejs/uvwasi that referenced this pull request Sep 11, 2019
The type schema was confirmed in
WebAssembly/WASI#74
sunfishcode added a commit that referenced this pull request Sep 12, 2019
This PR takes the `witx` concept from #74 and creates a directory
structure around it for enabling phased development of new APIs
and changes to existing APIs.

See the README.md changes for details.
@sunfishcode
Copy link
Member Author

Ok, I've addressed all the feedback so far. I'm taking the liberty of merging this now, so that we can more easily continue iterating on it.

@sunfishcode sunfishcode merged commit 8b06a84 into WebAssembly:master Sep 12, 2019
@sunfishcode sunfishcode deleted the moduletype branch September 12, 2019 18:45
sunfishcode added a commit to sunfishcode/WASI that referenced this pull request Sep 13, 2019
This PR takes the `witx` concept from WebAssembly#74 and creates a directory
structure around it for enabling phased development of new APIs
and changes to existing APIs.

See the README.md changes for details.
sunfishcode added a commit that referenced this pull request Sep 18, 2019
* Create a structure for phased development.

This PR takes the `witx` concept from #74 and creates a directory
structure around it for enabling phased development of new APIs
and changes to existing APIs.

See the README.md changes for details.

* Apply the validation fix from #90 to the new copies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants