WebAssembly / WASI

WebAssembly System Interface
Other
4.81k stars 249 forks source link

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

Closed alexcrichton closed 3 years ago

alexcrichton commented 3 years ago

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.

alexcrichton commented 3 years ago

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!