-
Notifications
You must be signed in to change notification settings - Fork 695
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
Optional imports #1281
Comments
@sbc100 , does this mean that we can get rid of the JS import thunks like the following? |
Its not clear to me exactly what the purpose of that wrapper in particular is. But in general with dynamic linking in emscripten we are going to continue to need to have JS thunks for at least some functions to work around the problem of circular dependencies. i.e. if two modules mutually depend on each other there is no way to simultaneously initialize them without providing some kind of thunk functions for thier mutual dependencies that then act and thunks into the real WebAssembly functions which become available only after instantiation. In short, I think the problem of mutual imports is independent of that of weak imports. |
Thanks for your reply @sbc100 . Just to clarify, these wrappers are generated by Emscripten and not by me. They are used as import functions into the main module thru asmLibraryArg. Perhaps, I don't understand about the use of weak imports in this context. Are weak imports a mechanism that we use to instantiate a Wasm module while the required import function is not defined? |
Yes, a weak import is one that can be undefined, but not just at initialization time, also at runtime. A weak import remains undefifined for the duration of the execution of the program. Not to be confused with lazy loading or on-demand loading of symbols, which is a separate issue related to dynamic linking. |
This got me thinking if such a feature might be similarly useful on the JS side for a |
At the WASI meeting on 15 August 2019, we decided to rename "weak imports" to "optional imports". |
In WASI we are discussing adding optional imports (also known as weak imports in the ELF spec) on top of the existing import system: WebAssembly/WASI#36.
For a more integrated solution I was thinking about a possible spec proposal to add the concept of a weak import. @binji and I discussed how this might work, at least for Function and Global imports:
weak_global
andweak_function
(or some bit to indicate the weakness of an import). These would exist in the same index space that strongly imported functions and globals.call
to an undefined weak function would result in a trap.global.get
orglobal.set
on an undefined weak global would result in a trap.func.check
andglobal.check
(taking function and global immediates respectively) could be used to check for the presence of the weak import at runtime.One downside of this approach is that it is specific to functions and globals and doesn't necessarily to all possible types of imports.
The text was updated successfully, but these errors were encountered: