Skip to content

Enable more than one handle type in *.witx #421

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

Merged
merged 1 commit into from
Mar 30, 2021

Conversation

alexcrichton
Copy link
Contributor

This commit reworks how handle types work at the representation level in
*.witx file to follow the expected design of resources in the
interface types specification. Previously handle types were simply
(handle), which meant that there could only be one actual handle type
in the world (structurally at least). After this commit, however, there
can be multiple handle types.

First abstract types must be introduced as a resource, for example:

(resource $fd)

This declares that the module exports a type named $fd and it's
abstract in that the representation is not known. At the interface layer
you can't pass an $fd directly because it's representation is not
known. To do that, however, you can do:

(param $x (handle $fd))

The handle type now refers to a particular resource that it refers
to. Values of type handle T can exist and are what's passed at the
boundaries.

This is all largely just an internal structuring concern at this point.
This has no ramifications for WASI which still has an $fd type for
functions that is represented with an i32. This is largely a
forward-looking change to allow multiple types of resources defined by
different modules and all used by one another.

This commit also updates use syntax where use will pull from either
the type or the resource namespace. Furthermore a new (use ($foo as $bar) ...) syntax was added to locally renamed something within a module.

This commit reworks how handle types work at the representation level in
`*.witx` file to follow the expected design of resources in the
interface types specification. Previously handle types were simply
`(handle)`, which meant that there could only be one actual handle type
in the world (structurally at least). After this commit, however, there
can be multiple handle types.

First abstract types must be introduced as a `resource`, for example:

    (resource $fd)

This declares that the module exports a type named `$fd` and it's
abstract in that the representation is not known. At the interface layer
you can't pass an `$fd` directly because it's representation is not
known. To do that, however, you can do:

    (param $x (handle $fd))

The `handle` type now refers to a particular `resource` that it refers
to. Values of type `handle T` can exist and are what's passed at the
boundaries.

This is all largely just an internal structuring concern at this point.
This has no ramifications for WASI which still has an `$fd` type for
functions that is represented with an `i32`. This is largely a
forward-looking change to allow multiple types of resources defined by
different modules and all used by one another.

This commit also updates `use` syntax where `use` will pull from either
the type or the resource namespace. Furthermore a new `(use ($foo as
$bar) ...)` syntax was added to locally renamed something within a module.
Copy link
Member

@sunfishcode sunfishcode left a comment

Choose a reason for hiding this comment

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

Looks great!

It appears that handles aren't yet displayed in the docs.md; would it be a lot of work to add that? In any case though, I don't think it's urgent, because the doc comments on the handle types are where the main documentation is.

@alexcrichton
Copy link
Contributor Author

Ah that's true, although it wouldn't be too hard to add documentation for resource types. If/when the documentation moves there I'm happy to update the docs generator to do so!

@alexcrichton alexcrichton merged commit 834679b into WebAssembly:main Mar 30, 2021
@alexcrichton alexcrichton deleted the nominal-handle-types branch March 30, 2021 18:41
cratelyn pushed a commit to cratelyn/WASI that referenced this pull request Jun 21, 2021
@cratelyn cratelyn mentioned this pull request Jun 21, 2021
alexcrichton pushed a commit that referenced this pull request Jun 21, 2021
* Revert "Enable more than one `handle` type in `*.witx` (#421)"

This reverts commit 834679b.

* Revert "Implement a new `use` syntax (#415)"

This reverts commit fc3da39.
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.

3 participants