Skip to content

Commit dbffafd

Browse files
authored
Merge pull request #83 from rylev/allow-unowned-resource-alias
Loosen restriction on top-level resource alias imports.
2 parents d3f6be2 + ebc752b commit dbffafd

5 files changed

Lines changed: 48 additions & 6 deletions

File tree

crates/wac-graph/src/encoding.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,6 @@ impl<'a> TypeEncoder<'a> {
577577
}
578578

579579
fn own(&self, state: &mut State, res: ResourceId) -> u32 {
580-
assert!(!state.scopes.is_empty());
581580
let res = state.current.resources[self.0[res].name.as_str()];
582581
let index = state.current.encodable.type_count();
583582
state.current.encodable.ty().defined_type().own(res);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
(component
2+
(import "x" (type (;0;) (sub resource)))
3+
(import "y" (type (;1;) (eq 0)))
4+
(type (;2;) (own 0))
5+
(type (;3;) (own 1))
6+
(type (;4;) (func (param "x" 2) (result 3)))
7+
(import "f" (func (;0;) (type 4)))
8+
(type (;5;)
9+
(component
10+
(import "x" (type (;0;) (sub resource)))
11+
(import "y" (type (;1;) (eq 0)))
12+
(type (;2;) (own 0))
13+
(type (;3;) (own 1))
14+
(type (;4;) (func (param "x" 2) (result 3)))
15+
(import "f" (func (;0;) (type 4)))
16+
)
17+
)
18+
(import "unlocked-dep=<test:foo>" (component (;0;) (type 5)))
19+
(instance (;0;) (instantiate 0
20+
(with "x" (type 0))
21+
(with "y" (type 1))
22+
(with "f" (func 0))
23+
)
24+
)
25+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"packages": [
3+
{
4+
"name": "test:foo",
5+
"path": "world.wit"
6+
}
7+
],
8+
"nodes": [
9+
{
10+
"type": "instantiation",
11+
"package": 0
12+
}
13+
]
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package example:foo;
2+
3+
world w {
4+
resource x;
5+
type y = x;
6+
import f: func(x: x) -> y;
7+
}

crates/wac-types/src/package.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -765,11 +765,8 @@ impl<'a> TypeConverter<'a> {
765765
let alias_id = self.types.add_resource(Resource {
766766
name: name.to_owned(),
767767
alias: Some(ResourceAlias {
768-
owner: match self
769-
.find_owner(ComponentAnyTypeId::Resource(id))
770-
.expect("should have owner")
771-
{
772-
(Owner::Interface(id), _) => Some(*id),
768+
owner: match self.find_owner(ComponentAnyTypeId::Resource(id)) {
769+
Some((Owner::Interface(id), _)) => Some(*id),
773770
_ => None,
774771
},
775772
source: *resource_id,

0 commit comments

Comments
 (0)