Skip to content

Commit

Permalink
Merge with upstream (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhil authored May 21, 2024
2 parents 134828e + 21846fd commit 226d1c9
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 61 deletions.
7 changes: 0 additions & 7 deletions crates/wasmparser/src/validator/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1503,13 +1503,6 @@ impl ComponentState {
state.add_export(name, ty, features, offset, true, types)?;
}
crate::ModuleTypeDeclaration::OuterAlias { kind, count, index } => {
if count > 1 {
return Err(BinaryReaderError::new(
"outer type aliases in module type declarations are limited to a \
maximum count of 1",
offset,
));
}
match kind {
crate::OuterAliasKind::Type => {
let ty = if count == 0 {
Expand Down
14 changes: 1 addition & 13 deletions crates/wasmparser/src/validator/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,7 @@ impl<'a> DependencyName<'a> {
}
}

/// A dependency on an implementation either as `url=...` or
/// `relative-url=...`
/// A dependency on an implementation either as `url=...`
#[derive(Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct UrlName<'a>(&'a str);

Expand Down Expand Up @@ -649,17 +648,6 @@ impl<'a> ComponentNameParser<'a> {
self.eat_optional_hash()?;
return Ok(ParsedComponentNameKind::Url);
}
// 'relative-url=<' <nonbrackets> '>' (',' <hashname>)?
if self.eat_str("relative-url=") {
self.expect_str("<")?;
let url = self.take_up_to('>')?;
if url.contains('<') {
bail!(self.offset, "relative-url cannot contain `<`");
}
self.expect_str(">")?;
self.eat_optional_hash()?;
return Ok(ParsedComponentNameKind::Url);
}

// 'integrity=<' <integrity-metadata> '>'
if self.eat_str("integrity=") {
Expand Down
20 changes: 6 additions & 14 deletions crates/wast/src/component/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl<'a> Resolver<'a> {
ComponentField::CoreType(t) => self.core_ty(t),
ComponentField::Component(c) => self.component(c),
ComponentField::Instance(i) => self.instance(i),
ComponentField::Alias(a) => self.alias(a, false),
ComponentField::Alias(a) => self.alias(a),
ComponentField::Type(t) => self.ty(t),
ComponentField::CanonicalFunc(f) => self.canonical_func(f),
ComponentField::CoreFunc(_) => unreachable!("should be expanded already"),
Expand Down Expand Up @@ -288,7 +288,6 @@ impl<'a> Resolver<'a> {
index: &mut Index<'a>,
kind: T,
span: Span,
enclosing_only: bool,
) -> Result<(), Error> {
// Short-circuit when both indices are already resolved as this
// helps to write tests for invalid modules where wasmparser should
Expand Down Expand Up @@ -328,13 +327,6 @@ impl<'a> Resolver<'a> {
));
}

if enclosing_only && depth > 1 {
return Err(Error::new(
span,
"only the local or enclosing scope can be aliased".to_string(),
));
}

*outer = Index::Num(depth, span);

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

fn alias(&mut self, alias: &mut Alias<'a>, enclosing_only: bool) -> Result<(), Error> {
fn alias(&mut self, alias: &mut Alias<'a>) -> Result<(), Error> {
match &mut alias.target {
AliasTarget::Export {
instance,
Expand All @@ -357,7 +349,7 @@ impl<'a> Resolver<'a> {
kind: _,
} => self.resolve_ns(instance, Ns::CoreInstance),
AliasTarget::Outer { outer, index, kind } => {
self.outer_alias(outer, index, *kind, alias.span, enclosing_only)
self.outer_alias(outer, index, *kind, alias.span)
}
}
}
Expand Down Expand Up @@ -552,7 +544,7 @@ impl<'a> Resolver<'a> {
self.resolve_prepending_aliases(
&mut c.decls,
|resolver, decl| match decl {
ComponentTypeDecl::Alias(alias) => resolver.alias(alias, false),
ComponentTypeDecl::Alias(alias) => resolver.alias(alias),
ComponentTypeDecl::CoreType(ty) => resolver.core_ty(ty),
ComponentTypeDecl::Type(ty) => resolver.ty(ty),
ComponentTypeDecl::Import(import) => resolver.item_sig(&mut import.item),
Expand Down Expand Up @@ -585,7 +577,7 @@ impl<'a> Resolver<'a> {
self.resolve_prepending_aliases(
&mut c.decls,
|resolver, decl| match decl {
InstanceTypeDecl::Alias(alias) => resolver.alias(alias, false),
InstanceTypeDecl::Alias(alias) => resolver.alias(alias),
InstanceTypeDecl::CoreType(ty) => resolver.core_ty(ty),
InstanceTypeDecl::Type(ty) => resolver.ty(ty),
InstanceTypeDecl::Export(export) => resolver.item_sig(&mut export.item),
Expand Down Expand Up @@ -742,7 +734,7 @@ impl<'a> Resolver<'a> {
return self.resolve_prepending_aliases(
&mut ty.decls,
|resolver, decl| match decl {
ModuleTypeDecl::Alias(alias) => resolver.alias(alias, true),
ModuleTypeDecl::Alias(alias) => resolver.alias(alias),
ModuleTypeDecl::Type(_) => Ok(()),
ModuleTypeDecl::Import(import) => resolve_item_sig(resolver, &mut import.item),
ModuleTypeDecl::Export(_, item) => resolve_item_sig(resolver, item),
Expand Down
2 changes: 1 addition & 1 deletion tests/local/component-model/export.wast
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"not a valid export name")
(assert_invalid
(component (type (component (export "relative-url=<x>" (func)))))
"not a valid export name")
"not a valid extern name")
(assert_invalid
(component (type (component (export "locked-dep=<a:b>" (func)))))
"not a valid export name")
Expand Down
18 changes: 10 additions & 8 deletions tests/local/component-model/import.wast
Original file line number Diff line number Diff line change
Expand Up @@ -287,21 +287,23 @@
(component (import "url=<<>" (func)))
"url cannot contain `<`")

(component
(import "relative-url=<>" (func))
(import "relative-url=<a>" (func))
(import "relative-url=<a>,integrity=<sha256-a>" (func))
)
(assert_invalid
(component
(import "relative-url=<>" (func))
(import "relative-url=<a>" (func))
(import "relative-url=<a>,integrity=<sha256-a>" (func))
)
"not a valid extern name")

(assert_invalid
(component (import "relative-url=" (func)))
"expected `<` at ``")
"not a valid extern name")
(assert_invalid
(component (import "relative-url=<" (func)))
"failed to find `>`")
"not a valid extern name")
(assert_invalid
(component (import "relative-url=<<>" (func)))
"relative-url cannot contain `<`")
"not a valid extern name")

(component
(import "integrity=<sha256-a>" (func))
Expand Down
40 changes: 22 additions & 18 deletions tests/local/component-model/types.wast
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,12 @@
)
"type index out of bounds")

(assert_invalid
(component $c
(type $f (func))
(core type $t (module
(alias outer 100 0 (type))
))
)
"outer type aliases in module type declarations are limited to a maximum count of 1")
(component $c
(core type $f (func))
(core type $t (module
(alias outer $c $f (type))
))
)

(assert_invalid
(component $c
Expand Down Expand Up @@ -262,17 +260,14 @@
)
)

(assert_invalid
(component $C
(core type $t (func))
(component $C2
(core type (module
(alias outer $C $t (type $a))
(import "" "" (func (type $a)))
))
)
(component $C
(core type $t (func))
(component $C2
(core type (module
(alias outer $C $t (type $a))
(import "" "" (func (type $a)))
))
)
"only the local or enclosing scope can be aliased"
)

(component
Expand Down Expand Up @@ -319,3 +314,12 @@
(type (tuple))
)
"tuple type must have at least one type")

(component $c
(core type $f (func))
(component $c2
(core type $t (module
(alias outer $c $f (type))
))
)
)
8 changes: 8 additions & 0 deletions tests/snapshots/local/component-model/types.wast/17.print
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(component $c
(core type $f (;0;) (func))
(core type $t (;1;)
(module
(alias outer $c $f (type (;0;)))
)
)
)
11 changes: 11 additions & 0 deletions tests/snapshots/local/component-model/types.wast/32.print
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(component $C
(core type $t (;0;) (func))
(component $C2 (;0;)
(core type (;0;)
(module
(alias outer $C $t (type (;0;)))
(import "" "" (func (type 0)))
)
)
)
)
10 changes: 10 additions & 0 deletions tests/snapshots/local/component-model/types.wast/40.print
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(component $c
(core type $f (;0;) (func))
(component $c2 (;0;)
(core type $t (;0;)
(module
(alias outer $c $f (type (;0;)))
)
)
)
)

0 comments on commit 226d1c9

Please sign in to comment.