-
Notifications
You must be signed in to change notification settings - Fork 447
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
spectest module not implementable in wasm #650
Comments
Agreed this would be nice. Also, as currently defined here, |
Hm, the idea was that this allows testing that engines can actually handle that case, because it's legal from the Wasm perspective -- at least it needs to validate, even if it cannot be linked in all embeddings. Any suggestion how we can serve both purposes? Perhaps isolate the overloaded case in a separate test? |
Requiring that in core wasm would require an otherwise needless feature in a wasm engine that only intends to run wasm modules. It seems like this is something that should apply to specific embeddings, such as the Web embedding, and it can be tested for there as well. |
Well, validation is supposed to be the same everywhere. |
But I guess we could turn that into a validation-only test. |
This forces an embedder to call functions with an explicit signature. Is the objection that this is more than what's needed, or that it can cause a double-dispatch, or can't use native calling conventions? I implemented some of this and it doesn't seem overly burdensome. |
@rossberg I think that's right; a module with two imports with the same name and different signatures can still pass validation, but engines can issue a link error if they don't support it. A validation-only test for this sounds fine, and then we can remove the overloading in |
@jfbastien Could I ask you to clarify what you're responding to here, and what you implemented? |
I'm speaking of having imported functions be overloaded. At least in my experiments for a non-JS embedding it doesn't seem particularly difficult, so I'd like to understand if anything you've tried has significant downside. From your example, we import Did I misunderstand your concern? |
@jfbastien I'm thinking of two use cases:
[0] this probably isn't universally true either, but |
You'd never expose any imports by default, right? Like JS embeddings, any non-JS embedding should expose things through opt-in capabilities. So Agreed it would be neat to expose I don't really care, but I agree with @rossberg that having things set up this way forces embedder to expose APIs polymorphically. Put another way, if these tests don't do it then embedders can easily diverge on supporting this, and users would be worse off. Maybe that's what we want though (non-polymorphic imports). In that case I wouldn't just fix the tests, I'd also explicitly make it part of core wasm that multiple imports of the same WDYT? |
I think @rossberg already found the solution and I agreed. There's an unbounded amount of information that could theoretically be overloaded on; function argument types are just the tip of the iceberg. But in practice, the only kinds that a given engine needs to support are those used by its own embedding. For example, the Web embedding could test for this, but there's no portability to be gained by requiring all non-Web engines support the same kind of polymorphism, because any code using that polymorphism on the Web is necessarily also using JS, because only JS can implement the other side of it. |
I'm not sure my description was clear enough to be understood, but I also don't think this is important enough to get right at this point in time. |
I posted a PR updating the testsuite here: #652. |
Can we update the spec to make this sort of silliness invalid? As I read it there's currently nothing preventing a module from claiming that a host function type matches whatever the importer asks for, even though doing so seems obviously bogus. edit: ...actually I suppose the spec might not need to be updated after all; the definition of a host function instance in a module is:
So you can't have a |
@icefoxen, It is natural to allow this in an untyped embedding like JavaScript. There are also some cute use cases, such as enabling generic host functionality. (Disallowing it would require additional side conditions in the validation rule for modules. The definition you cite does not imply what you think it does, quite the contrary: it implies that the same hostfunc can be paired with different function types to form different function instances.) |
But it seems very strange in an otherwise entirely-statically-typed setting like wasm.
Yes, but to use generic host functionality you have to make it look exactly like non-generic host functionality (by saying
It seems like it would make validation easier, since you have fewer edge cases to handle.
Oh, that makes perfect sense. It's just rather non-obvious that this is allowed since it's impossible to write a webassembly function that has more than one valid type signature, as far as I am aware. However, my personal grumpiness aside because this is annoying to implement... allowing host functions to have multiple type signatures when a webassembly function can only have one means you can write host functions that are impossible to polyfill in webassembly, as this issue demonstrates. Is that a power we want host functions to have? |
It may seem that way, but that's not the case, there are no edge cases. The Wasm semantics simply does not care about import names at all, they are merely labels for the convenience of hosts (and even hosts may ignore them and instead supply imports positionally).
I don't know what you mean by the latter, but let me assure you that it is useful. At Dfinity we are making essential use of it in a (yet undisclosed) API right now -- without it, we would be forced to define an infinite number of host functions identified through name mangling. |
#652 is now merged, so this is fixed. |
The testsuite uses functions named
print
which are overloaded by their argument type. For example:spec/test/core/imports.wast
Line 36 in a7e226a
This limits the ways in which the testsuite can be used. A non-Web wasm engine may not otherwise need a JS interpreter, function overloading (which would require name mangling in some implementations), or a
spectest
builtin module (which would be extra needless surface area in production). It would be useful to have the option to implementspectest
in wasm itself, however that's currently not possible with the current interface (as discussed in #622).Replacing
spectest
'sprint
withprint_i32
,print_i64
, and so on would eliminate these issues.The text was updated successfully, but these errors were encountered: