Repository navigation
Conversation
|
This is effectively saying that we should spec an FFI interface, right? |
|
I don't think this adds that - we can already import methods from outside, as an ES6 module that has some methods. And we can call them (like asm.js ffi calls). So the call has to contain all the type info for the call (what type is returned, etc.). The proposal here just says that we can add such external methods to function tables dynamically, at runtime. |
|
My thinking was that wasm code could say "there's this external thing that I'll get later. Let me use it." In the browser it could be JS that provides the impl, and in a shell it could be C++ code or something. I think both should work. That's pretty much dynamic linking / modules? |
|
Actually, there's a pretty interesting underlying asymmetry that I think Alon's point hits on:
But our ES6-Module-y version of dlopen will just take a URL (or byte stream for dynamic compilation), so that means we could pass a JS module which would logically return function pointers (what else?) that, in the case of a JS module, thunked into JS. So for the JS-extending-C++-class use case, you'd put the JS class in an ES6 module and dlopen() it. Would that work? |
|
Yes, if the goal with dlopen was to support non-wasm modules as well - I can clarify that in the spec, if so? - then that would cover most of what the added line in this pull request suggests. There is still another aspect, that a direct API to add a function pointer to a new external method provides, which is that you don't need to create and dlopen an entire ES6 module to get a function pointer to a new method. Might be an overhead issue there. But if that is the only issue, I think it is enough to change this pull to mention that dlopen can load non-wasm modules too. Sound ok? |
|
|
|
sgtm too |
|
Updated. |
|
I'd make it less JS-centric, since we want this to work outside. They key is that |
|
How, though? I have to mention ES6 modules here, since that's the underlying model I think we have in mind? I'm not sure how to avoid mentioning JS. What kind of change do you suggest? |
|
|
Updated. |
Add external function pointers
It is useful to add function pointers at runtime, that arrive from outside WebAssembly. This is related to dynamic linking, but distinct. For example, qsort might be compiled into WebAssembly, and outside JavaScript might pass in a function at runtime to sort by.
This is very useful for the C++ <-> JS interop story, specifically, when extending a C++ class using JavaScript (the same could be true of C++ <-> other language interop, if not on the web). Specifically, for extension done at runtime, i.e., we don't whether or how many times the class will be extended by JavaScript. Emscripten currently supports this in 3 ways: By "reserving" function pointer space for JS functions to be added; by adding an extra dynamic lookup table; and by "emulating" function tables (i.e., having them outside of the asm module, so that new JS methods can be added directly). Supporting a direct way to add function pointers to outside JS methods would be far superior to all of those.
This is also related to other future features like accessing GC things. Note that a JS function would be just a GC thing, in a sense; the proposal here is to be able to add such GC things as function pointers.
Thoughts?