Skip to content

Commit 64c0b26

Browse files
authored
Allow aliases to core wasm types outside of depth 1 (#1539)
This accompanies WebAssembly/component-model#350 and relaxes the previous constraint implemented in #640 to reflect the spec-at-the-time, which has since been relaxed.
1 parent 6797729 commit 64c0b26

File tree

6 files changed

+57
-39
lines changed

6 files changed

+57
-39
lines changed

crates/wasmparser/src/validator/component.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,13 +1503,6 @@ impl ComponentState {
15031503
state.add_export(name, ty, features, offset, true, types)?;
15041504
}
15051505
crate::ModuleTypeDeclaration::OuterAlias { kind, count, index } => {
1506-
if count > 1 {
1507-
return Err(BinaryReaderError::new(
1508-
"outer type aliases in module type declarations are limited to a \
1509-
maximum count of 1",
1510-
offset,
1511-
));
1512-
}
15131506
match kind {
15141507
crate::OuterAliasKind::Type => {
15151508
let ty = if count == 0 {

crates/wast/src/component/resolve.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl<'a> Resolver<'a> {
157157
ComponentField::CoreType(t) => self.core_ty(t),
158158
ComponentField::Component(c) => self.component(c),
159159
ComponentField::Instance(i) => self.instance(i),
160-
ComponentField::Alias(a) => self.alias(a, false),
160+
ComponentField::Alias(a) => self.alias(a),
161161
ComponentField::Type(t) => self.ty(t),
162162
ComponentField::CanonicalFunc(f) => self.canonical_func(f),
163163
ComponentField::CoreFunc(_) => unreachable!("should be expanded already"),
@@ -288,7 +288,6 @@ impl<'a> Resolver<'a> {
288288
index: &mut Index<'a>,
289289
kind: T,
290290
span: Span,
291-
enclosing_only: bool,
292291
) -> Result<(), Error> {
293292
// Short-circuit when both indices are already resolved as this
294293
// helps to write tests for invalid modules where wasmparser should
@@ -328,13 +327,6 @@ impl<'a> Resolver<'a> {
328327
));
329328
}
330329

331-
if enclosing_only && depth > 1 {
332-
return Err(Error::new(
333-
span,
334-
"only the local or enclosing scope can be aliased".to_string(),
335-
));
336-
}
337-
338330
*outer = Index::Num(depth, span);
339331

340332
// Resolve `index` within the computed scope depth.
@@ -344,7 +336,7 @@ impl<'a> Resolver<'a> {
344336
Ok(())
345337
}
346338

347-
fn alias(&mut self, alias: &mut Alias<'a>, enclosing_only: bool) -> Result<(), Error> {
339+
fn alias(&mut self, alias: &mut Alias<'a>) -> Result<(), Error> {
348340
match &mut alias.target {
349341
AliasTarget::Export {
350342
instance,
@@ -357,7 +349,7 @@ impl<'a> Resolver<'a> {
357349
kind: _,
358350
} => self.resolve_ns(instance, Ns::CoreInstance),
359351
AliasTarget::Outer { outer, index, kind } => {
360-
self.outer_alias(outer, index, *kind, alias.span, enclosing_only)
352+
self.outer_alias(outer, index, *kind, alias.span)
361353
}
362354
}
363355
}
@@ -550,7 +542,7 @@ impl<'a> Resolver<'a> {
550542
self.resolve_prepending_aliases(
551543
&mut c.decls,
552544
|resolver, decl| match decl {
553-
ComponentTypeDecl::Alias(alias) => resolver.alias(alias, false),
545+
ComponentTypeDecl::Alias(alias) => resolver.alias(alias),
554546
ComponentTypeDecl::CoreType(ty) => resolver.core_ty(ty),
555547
ComponentTypeDecl::Type(ty) => resolver.ty(ty),
556548
ComponentTypeDecl::Import(import) => resolver.item_sig(&mut import.item),
@@ -583,7 +575,7 @@ impl<'a> Resolver<'a> {
583575
self.resolve_prepending_aliases(
584576
&mut c.decls,
585577
|resolver, decl| match decl {
586-
InstanceTypeDecl::Alias(alias) => resolver.alias(alias, false),
578+
InstanceTypeDecl::Alias(alias) => resolver.alias(alias),
587579
InstanceTypeDecl::CoreType(ty) => resolver.core_ty(ty),
588580
InstanceTypeDecl::Type(ty) => resolver.ty(ty),
589581
InstanceTypeDecl::Export(export) => resolver.item_sig(&mut export.item),
@@ -740,7 +732,7 @@ impl<'a> Resolver<'a> {
740732
return self.resolve_prepending_aliases(
741733
&mut ty.decls,
742734
|resolver, decl| match decl {
743-
ModuleTypeDecl::Alias(alias) => resolver.alias(alias, true),
735+
ModuleTypeDecl::Alias(alias) => resolver.alias(alias),
744736
ModuleTypeDecl::Type(_) => Ok(()),
745737
ModuleTypeDecl::Import(import) => resolve_item_sig(resolver, &mut import.item),
746738
ModuleTypeDecl::Export(_, item) => resolve_item_sig(resolver, item),

tests/local/component-model/types.wast

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,12 @@
134134
)
135135
"type index out of bounds")
136136

137-
(assert_invalid
138-
(component $c
139-
(type $f (func))
140-
(core type $t (module
141-
(alias outer 100 0 (type))
142-
))
143-
)
144-
"outer type aliases in module type declarations are limited to a maximum count of 1")
137+
(component $c
138+
(core type $f (func))
139+
(core type $t (module
140+
(alias outer $c $f (type))
141+
))
142+
)
145143

146144
(assert_invalid
147145
(component $c
@@ -262,17 +260,14 @@
262260
)
263261
)
264262

265-
(assert_invalid
266-
(component $C
267-
(core type $t (func))
268-
(component $C2
269-
(core type (module
270-
(alias outer $C $t (type $a))
271-
(import "" "" (func (type $a)))
272-
))
273-
)
263+
(component $C
264+
(core type $t (func))
265+
(component $C2
266+
(core type (module
267+
(alias outer $C $t (type $a))
268+
(import "" "" (func (type $a)))
269+
))
274270
)
275-
"only the local or enclosing scope can be aliased"
276271
)
277272

278273
(component
@@ -319,3 +314,12 @@
319314
(type (tuple))
320315
)
321316
"tuple type must have at least one type")
317+
318+
(component $c
319+
(core type $f (func))
320+
(component $c2
321+
(core type $t (module
322+
(alias outer $c $f (type))
323+
))
324+
)
325+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(component $c
2+
(core type $f (;0;) (func))
3+
(core type $t (;1;)
4+
(module
5+
(alias outer $c $f (type (;0;)))
6+
)
7+
)
8+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(component $C
2+
(core type $t (;0;) (func))
3+
(component $C2 (;0;)
4+
(core type (;0;)
5+
(module
6+
(alias outer $C $t (type (;0;)))
7+
(import "" "" (func (type 0)))
8+
)
9+
)
10+
)
11+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(component $c
2+
(core type $f (;0;) (func))
3+
(component $c2 (;0;)
4+
(core type $t (;0;)
5+
(module
6+
(alias outer $c $f (type (;0;)))
7+
)
8+
)
9+
)
10+
)

0 commit comments

Comments
 (0)