WebAssembly / WASI

WebAssembly System Interface
Other
4.75k stars 243 forks source link

API to instantiate a module from a bytes #477

Open kgtkr opened 2 years ago

kgtkr commented 2 years ago

JavaScript API has WebAssembly.compile and WebAssembly.instantiate. There seems to be no equivalent to this in wasi.

For example, if wasi have this, it should be able to realize a JIT compiler by generating a wasm module bytes and instantiating it by passing a function or memory. We can already do this with the JavaScript API.

Module-linking proposal

This looks like a problem that the module-linking proposal doesn't solve.

The general case of runtime dynamic linking in the style of dlopen, where an a priori unknown module is linked into the program at runtime, is not possible to do purely within wasm with this proposal. Additional host-provided APIs are required for:

  • compiling files or bytes into a module;

https://github.com/WebAssembly/module-linking/blob/main/design/proposals/module-linking/Example-SharedEverythingDynamicLinking.md#runtime-dynamic-linking

SamuraiCrow commented 2 years ago

Does the WITX to WIT transition address some of this? I remember seeing a new modularity feature being associated with the transition.

Secondly, I think dynamic code generation is incompatible with static compilation. It would only work during AOT or JIT compilation.

abrown commented 2 years ago

Seems like an interesting idea!

sunfishcode commented 2 years ago

I agree, I expect we will eventually want APIs for dynamic instantiation from module bytes. To do this, we'll likely want first-class type for holding references to dynamically created instances. These instance references could then be passed into other instances, potentially forming reference cycles, which means it'll probably need some form of GC.

Also, the ability to create code dynamically will need to be coordinated with the content-security-policy.

The WITX to WIT transition does not add dynamic instantiation from wasm module bytes.