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

Update *.witx files for the witx 0.9 syntax #13

Merged
merged 20 commits into from
Feb 18, 2021

Conversation

alexcrichton
Copy link
Contributor

This is a preparatory PR to follow-up from WebAssembly/WASI#395

This commit merges the current WASI main branch into this repository and then adds a commit on top which updates the *.witx files to follow the new conventions, notably around type names and result types.

linclark and others added 17 commits January 25, 2021 11:30
Move constants to a separate list in `Document`
Remove the `Type::Flags` variant in favor of a witx-specific way to
define a bitflags with a number of constants.
Instead of having a separate variant for `Char8` and `Usize` instead
store boolean flags on `U8` and `U32` whether they're intended for these
language-specific purposes. This additionally changes to require `@witx`
when parsing `char8` to ensure usage is flagged as witx-specific.
This updates the Proposals.md page, fixing a few broken links, and
updating the names of the proposals to match the actual proposal
repositories.
…st` (#392)

* Add a wast-like testsuite for the witx tool

As the functionality of `witx` grows this will hopefully make adding
tests for new functionality as well as new kinds of tests easier. The
goal is to make it very easy to drop a test file with various directives
to exercise the functionality of `witx` and its internals.

For now the testsuite is quite simple, simply asserting whether
documents are either valid or invalid. My hope, though, is that this can
be expanded over time with more styles of assertions directives.

* Migrate union test to `union.witxt`

* Add documentation/roundtrip testing to all documents

* Translate multi-module test suite to `*.witxt`

* Move wasi tests into `witxt` test suites

* Convert representation tests to `*.witxt`

* Rebased onto origin/main
@alexcrichton
Copy link
Contributor Author

It's also worth noting that this probably shouldn't get merged until WebAssembly/WASI#395 is merged, at which point in time I'll rebase.

* Take another step towards interface types

This commit is another large refactoring on the tail of #391 which is
intended to help march one step closer to using pure interface types for
specifying WASI and using `*.witx` files. Contained here is a large
amount of refactoring of the `*.witx` files, the internals of the `witx`
crate, and how code generators are supposed to work.

At the `*.witx` level, some notable changes have been made:

* All functions returning results now return `(expected ok? (error
  $errno))`. This helps signify that the intention of all functions is
  that they return a packaged value which is either a successful result
  or the erroneous error code on failure. ABI-wise nothing has changed,
  but this is intended to model more closely what the interface-types
  API of this would be.

* The `flags` type in `*.witx` now desugars as a struct-of-bools rather
  than simply an `int`. This doesn't have any effect on the ABI today,
  but it does change the AST and type-level representation of these types.

All existing `*.witx` files in this repository have been updated for all
phases with these new forms. To reiterate, though, no details of the ABI
have changed (or at least not intentionally). Everything should still be
ABI-compatible with before.

Under the hood for code generators this is a very large breaking change.
The intention of this commit is to start moving code generators relying
on `witx` into the direction that we'll end up with interface types.
Namely the `coretypes` module is entirely replaced with a new `abi`
module with the intention of handling lots more high-level details of
translation than the previous module did.

The `InterfaceFunc` type now sports two new methods: `call_wasm` and
`call_interface`. These two methods represent the two halves of
lifting/lowering operations performed by code generators. The
`call_wasm` function takes interface types values (or whatever they are
represented as in the source language) and converts them to wasm types
to call a wasm import. The wasm import's return values are then
"deserialized" back into the language's interface types values too. The
`call_interface` function is the opposite, it assumes that you're coming
from wasm values and calling, e.g., a host function with interface values.

The `abi` module is refactored with an `Instruction` `enum` which lists
out what are the current set of "adapter instructions". These adapter
instructions are intended to somewhat model the eventual idea of adapter
functions and their instructions, but for now they're pretty specific to
WASI as-is today. All instructions currently model what WASI currently
does, sometimes in very specific manners. It's expected that the
`Instruction` type will be in flux as we tweak the ABI of WASI over
time, but the current set of instructions will likely only be expanded
because of maintaining compatibility with the current snapshot.

The expected usage of `Instruction` is that code generators will
implement how to generate code for each `Instruction`. This should be a
very low-level operation (generating code per instruction) and should be
in theory quite easy to implement. Not all code generators need to
implement all instructions depending on their use case. Additionally
WASI as-is today doesn't always exercise all types of instructions.

The next steps after a PR like this include starting to define a new ABI
for WASI which supports all types in all positions rather than the
current ABI which supports only a limited subset of types in some
positions. The intention is that this new ABI may add a new instruction
or two but will generally not be a large breaking change for all
existing code generators. Some new additions are expected but other than
that existing code generators updated to use this PR will require little
effort to support new ABIs.

* Add more documentation and some more tests for shorthand syntax

* Bump to 0.9.0 and bump wast dependency

* Support variants as arguments

Same as records, they use pointers

* Fix a typo
@alexcrichton
Copy link
Contributor Author

Ok should be good for merging now. The changes specific to this proposal are in 2706bce

Copy link
Collaborator

@abrown abrown left a comment

Choose a reason for hiding this comment

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

Makes sense to me (except for the (expected ...) stuff but I think it looks roughly like we are defining the two sides of a result; perhaps it should be more symmetrical, e.g., (result $r (expected $thing) (error $errno))?).

@abrown abrown merged commit 8adc5b9 into WebAssembly:main Feb 18, 2021
@alexcrichton
Copy link
Contributor Author

@alexcrichton alexcrichton deleted the witx-next branch February 18, 2021 18:00
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