-
Notifications
You must be signed in to change notification settings - Fork 694
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
Way of validating imports and exports are as expected #1289
Comments
Nice, this looks useful. I'd have some syntax nits, but structurally it makes sense to me. My main comment is that I'd recommend a rename, though. These are module interfaces/signatures, plain and simple. When you say "contract", many people will expect something way richer, especially in the S-expression community, where contracts are a very sophisticated thing. |
Great feedback. We will rename from "wasm contracts" to "wasm interfaces". You mentioned you had some syntax suggestions. We would love to get your input on this, as we keep iterating on it :) |
I'd suggest to stick as close to WAT syntax as possible, to minimise confusion. That suggests not to use asserts but a module "pattern" as description. For example:
|
@rossberg Should we have some separate top-level identifier than |
Thanks for the suggestions! We thought about using ExampleThe WASI interface would look like: (interface "wasi_unstable"
;; Here's a bunch of function imports!
(func (import "wasi_unstable" "args_get") (param i32 i32) (result i32))
(func (import "wasi_unstable" "args_sizes_get") (param i32 i32) (result i32))
(func (import "wasi_unstable" "clock_res_get") (param i32 i32) (result i32))
(func (import "wasi_unstable" "clock_time_get") (param i32 i32 i32) (result i32))
(func (import "wasi_unstable" "environ_get") (param i32 i32) (result i32))
(func (import "wasi_unstable" "environ_sizes_get") (param i32 i32) (result i32))
(func (import "wasi_unstable" "fd_advise") (param i32 i64 i64 i32) (result i32))
(func (import "wasi_unstable" "fd_allocate") (param i32 i64 i64) (result i32))
(func (import "wasi_unstable" "fd_close") (param i32) (result i32))
(func (import "wasi_unstable" "fd_datasync") (param i32) (result i32))
(func (import "wasi_unstable" "fd_fdstat_get") (param i32 i32) (result i32))
(func (import "wasi_unstable" "fd_fdstat_set_flags") (param i32 i32) (result i32))
(func (import "wasi_unstable" "fd_fdstat_set_rights") (param i32 i64 i64) (result i32))
(func (import "wasi_unstable" "fd_filestat_get") (param i32 i32) (result i32))
(func (import "wasi_unstable" "fd_filestat_set_size") (param i32 i64) (result i32))
(func (import "wasi_unstable" "fd_filestat_set_times") (param i32 i64 i64 i32) (result i32))
(func (import "wasi_unstable" "fd_pread") (param i32 i32 i32 i64 i32) (result i32))
(func (import "wasi_unstable" "fd_prestat_get") (param i32 i32) (result i32))
(func (import "wasi_unstable" "fd_prestat_dir_name") (param i32 i32 i32) (result i32))
(func (import "wasi_unstable" "fd_pwrite") (param i32 i32 i32 i64 i32) (result i32))
(func (import "wasi_unstable" "fd_read") (param i32 i32 i32 i32) (result i32))
(func (import "wasi_unstable" "fd_readdir") (param i32 i32 i32 i64 i32) (result i32))
(func (import "wasi_unstable" "fd_renumber") (param i32 i32) (result i32))
(func (import "wasi_unstable" "fd_seek") (param i32 i64 i32 i32) (result i32))
(func (import "wasi_unstable" "fd_sync") (param i32) (result i32))
(func (import "wasi_unstable" "fd_tell") (param i32 i32) (result i32))
(func (import "wasi_unstable" "fd_write") (param i32 i32 i32 i32) (result i32))
(func (import "wasi_unstable" "path_create_directory") (param i32 i32 i32) (result i32))
(func (import "wasi_unstable" "path_filestat_get") (param i32 i32 i32 i32 i32) (result i32))
(func (import "wasi_unstable" "path_filestat_set_times") (param i32 i32 i32 i32 i64 i64 i32) (result i32))
(func (import "wasi_unstable" "path_link") (param i32 i32 i32 i32 i32 i32 i32) (result i32))
(func (import "wasi_unstable" "path_open") (param i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i32))
(func (import "wasi_unstable" "path_readlink") (param i32 i32 i32 i32 i32 i32) (result i32))
(func (import "wasi_unstable" "path_remove_directory") (param i32 i32 i32) (result i32))
(func (import "wasi_unstable" "path_rename") (param i32 i32 i32 i32 i32 i32) (result i32))
(func (import "wasi_unstable" "path_symlink") (param i32 i32 i32 i32 i32) (result i32))
(func (import "wasi_unstable" "path_unlink_file") (param i32 i32 i32) (result i32))
(func (import "wasi_unstable" "poll_oneoff") (param i32 i32 i32 i32) (result i32))
(func (import "wasi_unstable" "proc_exit") (param i32))
(func (import "wasi_unstable" "proc_raise") (param i32) (result i32))
(func (import "wasi_unstable" "random_get") (param i32 i32) (result i32))
(func (import "wasi_unstable" "sched_yield") (result i32))
(func (import "wasi_unstable" "sock_recv") (param i32 i32 i32 i32 i32 i32) (result i32))
(func (import "wasi_unstable" "sock_send") (param i32 i32 i32 i32 i32) (result i32))
(func (import "wasi_unstable" "sock_shutdown") (param i32 i32) (result i32))
) From this, someone could eventually use it in wast tests, doing something like: (assert_module_has_interface "wasi_unstable") Let us know if you have more feedback. We would love to keep iterating on this! |
Here's the article that we created showcasing WebAssembly Interfaces, if you want to take a look! https://medium.com/wasmer/introducing-webassembly-interfaces-bb3c05bc671 |
Sorry for the late reply. @lukewagner, from my point of view, It's better to keep these straight, since it may well be that you'd eventually want both, What you seem to be getting at is that it might be useful to have |
@rossberg Actually, what I assumed we were talking about was just the |
@lukewagner, well, as a file, it supposedly is the counterpart to a wat file, so it would conceptually be the But even if you view it as just the
For Wasm, we also have gone with the former: e.g., types of funcs, globals, etc (as occurring in imports) use the same keyword as the respective definitions ("terms"). To be consistent, that would suggest to analogously use the Hope I'm making sense. :) |
Hah, interesting point; I hadn't appreciated that distinction. So then I suppose the context tells you whether you're parsing a type or an expression (specifically, either the statement in .wast or the file extension when used standalone in a file). Ok, so then if we wanted to spec this, could the diff to the spec more-or-less be:
? It seems like |
Yes, that would be the idea. If you wanted to add this notion to the spec itself you'd probably need to do slightly more:
For the time being I'd be a bit hesitant to overload this with binding-related extensions, though, since it might be preferable to keep some layering separation. You may want to be able to talk about both, the "raw" core Wasm interface and the more high-level bindings interface, because a given bindings interface can be implemented by different raw Wasm modules, by ways of overlaying different binding expressions. |
Yes, those bullet points make sense. For the final point: I agree that there should be a layering separation. I was imagining that the core wasm spec defines a |
Yes, makes sense. Bindings-level module types would essentially be a (syntactic & semantic) super-set language of core module types. |
We voted to move this to stage 0, but I don't see that reflected at https://github.com/webassembly/proposals. Has a repo been set up for this proposal yet? I have an issue to raise if only I could find out where. |
Oops, sorry! Created https://github.com/WebAssembly/module-types. It has a placeholder overview atm, but I'll try to get at least the motivation and an example written shortly. |
To help with linking, identifying and verifying the ABIs of modules for our package manager, and making using our runtime easier to use in plugin systems (which expect modules to conform to their own custom, possibly hybrid interface), we've made something called "wasm contracts" which are an s-expression text format that can be merged together and can be used to validate a module.
The README linked above explains the details of it.
In some ways this is a subset of ⛄️ bindings, but it serves a different enough purpose and is simple enough that we're able to use it immediately and benefit from it, that we thought that we'd share it here.
We're looking for feedback on this -- please let us know your thoughts!
The text was updated successfully, but these errors were encountered: