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

How instantiate, argument and namespace interactive?

Open dannypsnl opened this issue 7 months ago • 4 comments
trafficstars

Below text is the binary built from https://github.com/sunfishcode/hello-wasi-http/tree/29205a0749835bd65be65841640af913be9be794 and use wasm-tools dump *.wasm to get.

[instance 6] Instantiate { component_index: 0, args: [ComponentInstantiationArg { name: "import-func-handle", kind: Func, index: 11 }, Compon
entInstantiationArg { name: "import-type-incoming-request", kind: Type, index: 25 }, ComponentInstantiationArg { name: "import-type-response-outparam", kind: Type, ind
ex: 26 }, ComponentInstantiationArg { name: "import-type-incoming-request0", kind: Type, index: 20 }, ComponentInstantiationArg { name: "import-type-response-outparam0
", kind: Type, index: 22 }] }

I stuck in this case, this part is trying to instantiate the component 0 with some arguments. The particular argument import-type-incoming-request has index 25, I thought that is the index of a component instance, and found that's wrong guess.

Indeed, there is a type 25:

alias [type 25] InstanceExport { kind: Type, instance_index: 5, name: "incoming-request" }

This confuse me because I think

  1. instantiation argument's name is given to correspond to imports in the component 0
  2. the kind is Type means instantiate the component 0 with a type (in the component should have a type import)
  3. index 25 is the index of type

Since they seems all wrong, I'm not sure how these interactive now.

dannypsnl avatar Mar 27 '25 07:03 dannypsnl

Could you clarify what you feel is wrong here? This is indeed instantiating a component with a type, and it's because the component being instantiated should import a type and that needs to be satisfied. You say that everything seems all wrong, but can you be more specific?

alexcrichton avatar Mar 27 '25 14:03 alexcrichton

Because I thought the meaning of

[type 0] ComponentImport { name: ComponentImportName("import-type-incoming-request"), ty: Type(SubResource) }

was

  1. import something named import-type-incoming-request
  2. check its type is a subtype of resource
  3. assign it to DBI space, in this case is 0

dannypsnl avatar Mar 28 '25 02:03 dannypsnl

Sorry I'm a bit confused, the snippet you pasted in response isn't present above, so this looks like it's new questions about a new line. Your understanding of that line in isolation seems correct enough, but I still don't really know what you feel is wrong and/or what you're asking here (maybe I'll let others resond....)

alexcrichton avatar Mar 31 '25 18:03 alexcrichton

Because argument import-type-incoming-request is a type, but in component, the import import-type-incoming-request should be an instance (to have a type that is a subtype of resource).

dannypsnl avatar Apr 03 '25 09:04 dannypsnl