wac icon indicating copy to clipboard operation
wac copied to clipboard

wac expects "instantiation" of type aliaes

Open leon-thomm opened this issue 1 year ago • 2 comments

Hi, I noticed wac compose will fail if the world of the component I'm instantiating includes a type alias like so

world my-component {
    type my-alias = u32;
    export foo: func(x: my-alias) -> my-alias;
}

If I instantiate this in wac

let my-component = new wacdebug:my-component {};

it will fail

  × missing instantiation argument `my-alias` for package `wacdebug:my-component`
   ╭─[default.wac:3:24]
 2 │ 
 3 │ let my-component = new wacdebug:my-component {};
   ·                        ──────────┬──────────
   ·                                  ╰── missing argument `my-alias`
   ╰────

Instantiating a type alias makes no sense to me, it is not an import. Did I miss anything?

leon-thomm avatar Feb 06 '25 19:02 leon-thomm

This is just a nuance of wit<->component translation/encoding where top-level types (e.g. my-alias) are implicitly considered imports.

For a component targeting your world, if you wasm-tools print wacdebug.wasm --skeleton you'll see:

(component
  (type (;0;) u32)
  (import "my-alias" (type (;1;) (eq 0)))
  ...

To fix this you can tell wac to import any arguments you are not directly providing, i.e.:

let my-component = new wacdebug:my-component {...};

fibonacci1729 avatar Feb 06 '25 19:02 fibonacci1729

Ah that works! Maybe wac could have a more telling error here.

top-level types (e.g. my-alias) are implicitly considered imports

why is that? How should I think about imports on the component (encoding) level?

leon-thomm avatar Feb 06 '25 21:02 leon-thomm