-
Notifications
You must be signed in to change notification settings - Fork 90
Adding a use
directive to *.wit
#140
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
Comments
Great job writing up the whole story here! This all looks right to me with two nits: In the first In the "Worlds and interface wasi-fs {
...
}
world foo {
import wasi-fs: wasi-fs
} so that we don't have to have any special meaning of |
Ah yes good point I haven't internalized URLs much, but makes sense. Otherwise though good point on |
Ok I've attempted to formalize this, plus some other items, in #141 |
Currently as specified the
*.wit
format doesn't have ause
directive or any similar ability to import/share definitions from other files. A historical implementation of this existed inwit-bindgen
but was removed since it was never really fully fleshed out and working as one might expect. I wanted to open this issue, though, to serve as a place to talk about it.@lukewagner, @fibonacci1729, and I just had a long chat about a possible design here and I wanted to additionally write down our current thinking for what this might look like. The current plan is for @fibonacci1729 and I to pair up and implement this both in
wit-parser
in thewasm-tools
repository as well as through a PR here describing the semantics.Interfaces and
use
Here the
http-backend
interface has ause
directive which refers to types defined in the previous interface,http-types
. The ordering of the interfaces doesn't matter here so you could also do:although
use
statements do not support cyclic references, they must form a DAG still. Theuse
directive can, for now, only appear ininterface
andworld
blocks, not the top-level. This may be added at a future date, however. Names can also be renamed in ause
:Additionally anything
use
'd is considered an export of the interface which means thatuse
-s can be chained together:This will also enable splitting one
*.wit
file into multiple*.wit
files:Here the
from
target is quoted to represent any filename being loaded from. The precise contents of the string are sort of nebulous for now and are eventually intended to be URL-like but for now will just be path names for local resolution. Note the usage ofdefault interface
intypes.wit
which indicates that when"types"
is used from it knows which interface to pick by default. A non-default interface can be selected with:For now only types can be referred to by
use
. Eventually it might make sense to add functions as well but that's seen as a possible future feature.Worlds and
use
World directives can be specified with strings now to refer to other files:
and this is equivalent to:
In a
world
itsuse
statements must refer to interfaces as opposed to types. Unlikeinterface
s they're not imported/export but rather are just available for use inimport
orexport
directives.Translation to a component type
The intention is that a
use
statement basically equates to analias
in a component. For example:would translate to:
Note here that
my-world
only importedthread
but ended up also importingtypes
in the final component. This is due to theuse
of thetypes
interface inthread
. Note that the string"types"
comes from the name of the interfacetypes
. For cases where conflicts arise the import strings must be explicitly disambiguated:Resolution
Resolution of
use
statements is intended to follow a rough algorithm that looks like:use
statements and interface dependencies in worlds. This will involve reading external files, recursively, and collecting everything together. Note that at this point it should be possible to emit another*.wit
file equivalent to the first. Note that cycles are disallowed hereuse
statements now that allinterface
s are known. Cycles are again disallowed here and connections are made.interface individually, disalling name conflicts within an
interface. For now everything in an
interface` will share a namespace, meaning types, functions, and interfaces all live in the same namespace and can have no duplicates.The final resulting
*.wit
data structure still semantically hasuse
statements inside of it. This is useful for generators such as:*.wasm
generation ause
means "go alias something from somewhere else"use
means "skip this, import the name from somewhere else"use
means "print the name as used into this module"use
is "unwrapped" to look at the structure of the type to determine how to lift and lowerThis should provide a straightforward way for, even in code generators, to share types between interfaces since all that's necessary is to
use
between them.The text was updated successfully, but these errors were encountered: