Closed fitzgen closed 9 months ago
To confirm, you mean an outer type alias from within a core module type declared within a component, right? I ask because core modules don't have outer aliases but core module types to, so I think core modules themselves won't have any issues.
Ah ok yes, so the question here is about this component:
(component $C
(core type $t (module))
(core type (module
(alias outer $C $t (type $my_t))
))
)
As of yesterday wasm-tools
accepts this component. Once https://github.com/bytecodealliance/wasm-tools/pull/1257 lands, however, that module will fail with:
error: not implemented: aliasing core module types into a core module's types index space (at offset 0xd)
The spec issue here is the question of whether wasm-tools
is "in the wrong" and should implement this, or whether it should become a hard validation error. The rationale for not supporting this is that wasmparser
's state for validating a core module type is the same as the state for validating a core module itself. In core wasm core module types themselves don't need to be handled, so there's no support for modeling this.
Another loose argument in favor is that there's nothing you can do with a core module type in a core module type itself, so it's somewhat more conservative to disallow it for now.
That's a great point: it's a bit silly to allow the definition of a core module type that is impossible to implement. The current allowance of this mostly just falls out of the grammar, but we could easily and conservatively make it a validation error. If core wasm ever gets module-linking, then we'd naturally relax this restriction. I'll write up a PR in a sec.
Ah, the explainer (Type Definitions section, first paragraph after core:moduletype
) and Binary.md (second bullet) already reject nested core module types with the explicit intention of disallowing core-modules-importing-or-exporting-core-modules; I just forgot to reject the outer-alias case.
Fixed in #266
AFAICT, this is currently permitted by the spec, but until/unless core module linking exists, this is problematic because it means that one can't reuse off-the-shelf core module validation within component module validation. It requires extending core module validation structures to also be able to store core module types.
In fact, thewasmparser
crate doesn't even support this today, and it was only noticed as I did a large ish refactoring of how it internally represents types.cc @lukewagner @alexcrichton