WebAssembly / WASI

WebAssembly System Interface
Other
4.81k stars 249 forks source link

Implement a new `use` syntax #415

Closed alexcrichton closed 3 years ago

alexcrichton commented 3 years ago

This commit implements a new use syntax which changes

(use "foo.witx")

to

(use $some $type $names from $foo)

This change ended up being much larger than originally intended. While at a surface level switching this style of use statements isn't too bad it has large ramifications on the mental model of how to interpret and work with *.witx files. This necessitated some internal refactorings which ended up as a bit of a yak shave. The other changes here are:

All *.witx files have been updated to the new syntax in this repository. Lots of changes look like they happened to the proposal documentation, but that's just because the documentation order of types has been shuffled around. I've checked to make sure no actual items were lost from the documentation.

Closes #378 Closes #379

devsnek commented 3 years ago

feel free to ignore, but it would be nice if something delineated the list of import names. maybe an extra pair of parens?

sunfishcode commented 3 years ago

Overall this looks good! My biggest concern here is the removal of the top-level (module ) syntax. For what it's worth I proposed a simlar syntax change back when the original wat syntax was being designed and it was clear that we wanted a file format fold holding exactly-one-module. But now, with witx being derived from wat syntax, and wat syntax retaining the outer (module ) around it, it feels like witx should retain it too.

sbc100 commented 3 years ago

Isn't the outer (module ..) syntax optional in the .wit format?

alexcrichton commented 3 years ago

I am not personally wed to any particular syntax here, so I'm happy to tweak as necessary for imports/etc.

@sunfishcode are you ok with the one-module-per-text-file restriction? (same as *.wat) It sounds like the module wrapper would be purely syntactical but wanted to confirm.

It's also true yeah that at least in *.wat the (module ...) is optional but AFAIK almost no one omits it, so seems reasonable to start requiring (module here and it can always be relaxed in the future.

sunfishcode commented 3 years ago

One-module-per-file is ok with me. Hmm, I actually forgot that (module ...) is optional; it's not optional in the spec, and all the official examples include it, and it does seem everyone use it includes it in practice.

I think my instinct is that we should support and require the (module ...) at this point, though I could be convinced otherwise.

alexcrichton commented 3 years ago

Ok updated!