binaryen icon indicating copy to clipboard operation
binaryen copied to clipboard

Implement type imports and exports

Open vouillon opened this issue 10 months ago • 1 comments

Implementation of the Type Imports and Exports proposal, which allows Wasm module to export and import types:

        (type $File (export "File") (struct ...))
        (import "file" "File" (type $File (sub any)))

wasm-merge can combine several modules using this proposal, connecting type imports to corresponding type exports. To produce an output compatible with existing tools, an option --strip-type-exports can be used to omit any type export from the output.

From an implementation point of view, for imports, a new kind of heap type is used:

        (import "module" "base" (sub absheaptype))

Including the module and base names in the type definition works well with type canonicalization.

For exports, we separate type exports from other exports, since they don't have an internal name but a heap type:

        class TypeExport {
          Name name;
          HeapType heaptype; // exported type
        };

This is somewhat error-prone: to check for repeated exports, we need to check two tables. But the alternatives do not seem much better. If we put all exports together, then we have to make sure that we are never trying to access the internal name of a type import.

vouillon avatar Feb 26 '25 17:02 vouillon

Please re-request review from me when you're ready :)

tlively avatar Feb 28 '25 01:02 tlively