component-model icon indicating copy to clipboard operation
component-model copied to clipboard

Add runtime instantiation to component model

Open pothos opened this issue 1 year ago • 2 comments

Is there anyone already working on a draft for adding runtime instantiation to the component model?

Runtime instantiation means that a component can dynamically instantiate another component given its binary representation, and then invoke them. This is needed to have something similar to exec, where the number of imported instances and even the module code itself is not statically predefined but evolves programmatically. Currently one could define a custom protocol between the runtime and a component to have a similar effect. Use cases are flexible reusing of modules, runtime generation or fetching of modules (network or from disk), and a small demo program you could think of is a wasm component shell or wac REPL that itself runs as wasm component.

A few links in Luke's answer here: https://github.com/WebAssembly/WASI/issues/763

pothos avatar Apr 27 '24 10:04 pothos

That's a good question, but perhaps the better place to ask it is https://github.com/webassembly/component-model.

lukewagner avatar Apr 29 '24 19:04 lukewagner

(Oh haha, I was confused by my above comment before seeing that Dan transferred it :P)

I'm not working on a draft yet, but once 0.3-async is closed out, this is one of the last significant feature I am quite keen to add to the CM for a 1.0 MVP, because I totally agree with those use cases you mention being important.

The rough shape of the feature here is a new canon built-in that allows "resourceifying" any component (nested or imported) to produce:

  1. a new resource type representing instances of that component
  2. a new function that runtime-instantiates that component, returning an owned handle of type (1)
  3. for each export of that component, a function that prepends to the original parameters a borrowed handle of type (1)

But lots more work to turn this idea into a real draft proposal; I'm sorry there's not more worked out yet.

lukewagner avatar Dec 03 '24 22:12 lukewagner