-
Notifications
You must be signed in to change notification settings - Fork 15
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
WASM function imports #33
Comments
@lqd |
@eddyb's syntax looks right to me. It ultimately must work exactly like any other FFI import so that 'normal' Rust code can be compiled to wasm. |
@lqd But you already provided the solution for that: #[link(name="spectest")]
extern {
#[link_name = "print"]
fn print_i32(i: i32);
#[link_name = "print"]
fn print_i64(i: i64);
} |
@eddyb oh ok, so yes link + link_name is exactly what we need 😄 |
About overloading: yes, it's possible. The core issue is that when wasm imports a method, then on the web that is from JavaScript, which is not statically typed. So the function being called doesn't have types for params, etc. But wasm is typed, so (1) you must define those types for the imported function. And (2) you can import something multiple times (each to a different internal name), just because it seems arbitrary to limit that. As a result of (1)+(2) you can bind the same imported method to different internal import names that have different types, as in the examples here. But this is indeed kind of a corner case. In practice, I'd expect to not need to care about stuff like this. |
@kripken super clear, thank you. |
Related to #29 is the issue of importing wasm functions from other wasm modules (or the environment, say, a JS function). What form should it take in our rust code ?
Some more info https://github.com/WebAssembly/design/blob/master/Modules.md#imports
Example https://github.com/WebAssembly/testsuite/blob/master/imports.wast#L2
Making it work similarly to the current FFI machinery would make sense, and this would look good I think:
However, and this might be special treatment for the
spectest
module (probably @kripken can shed some light on this topic), it seems in this case — as seen in the linked example — theprint
function is overloaded. This might be a special case because exports are apparently required to have a unique name, IIUC meaning one might not be able to produce the same exports as thespectest
module provides.If this is to be supported — which is itself an interesting question, especially since printing is right now our "only" way to test — we might need to roll our own custom attribute à la:
There may be other attributes or language features more closely matching the semantics/requirements ? Maybe
#[link_args]
could be of use, etc.@brson and @eholk what do you think ?
The text was updated successfully, but these errors were encountered: