Skip to content

Commit f31c6bc

Browse files
authored
Merge pull request #101 from rylev/panic-repro
Fix panic when resource's owning interface is not otherwise implicitly imported
2 parents ac04147 + 321c40b commit f31c6bc

11 files changed

Lines changed: 191 additions & 12 deletions

File tree

crates/wac-graph/src/graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,7 @@ impl<'a> CompositionGraphEncoder<'a> {
15331533
}
15341534

15351535
// Next encode the imports
1536-
for (name, kind) in aggregator.iter() {
1536+
for (name, kind) in aggregator.imports() {
15371537
log::debug!("import `{name}` is being implicitly imported");
15381538
let index = self.import(state, name, aggregator.types(), kind);
15391539
encoded.insert(name, (kind.into(), index));

crates/wac-graph/tests/encoding.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ impl GraphFile {
171171
path = path.display()
172172
)
173173
})?,
174+
None if path.is_dir() => Self::load_wit_package(test_case, &path)?,
174175
_ => bail!(
175176
"unexpected file extension for package file `{path}`",
176177
path = package.path.display()
@@ -331,6 +332,7 @@ fn encoding() -> Result<()> {
331332
})?
332333
.into_composition_graph(&path, test_case)
333334
.and_then(|graph| {
335+
println!("{:?}", graph);
334336
graph
335337
.encode(EncodeOptions {
336338
// We import the component definitions instead
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package foo:dependency;
2+
3+
interface types {
4+
resource x;
5+
}
6+
7+
world w {
8+
export types;
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package foo:bar;
2+
3+
world w {
4+
export foo:dependency/types;
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package foo:dependency;
2+
3+
interface types {
4+
resource x;
5+
}
6+
7+
world w {
8+
export types;
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package foo:baz;
2+
3+
world w {
4+
use foo:dependency/types.{x};
5+
import my-func: func() -> x;
6+
// The test will fail whether this is here or not
7+
import foo:dependency/types;
8+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
(component
2+
(type (;0;)
3+
(instance
4+
(export (;0;) "x" (type (sub resource)))
5+
)
6+
)
7+
(import "foo:dependency/types" (instance (;0;) (type 0)))
8+
(alias export 0 "x" (type (;1;)))
9+
(import "x" (type (;2;) (eq 1)))
10+
(alias export 0 "x" (type (;3;)))
11+
(type (;4;)
12+
(instance
13+
(alias outer 1 3 (type (;0;)))
14+
(export (;1;) "x" (type (eq 0)))
15+
(type (;2;) (own 1))
16+
(type (;3;) (func (result 2)))
17+
(export (;0;) "my-func" (func (type 3)))
18+
)
19+
)
20+
(import "foo:test-import/my-interface" (instance (;1;) (type 4)))
21+
(type (;5;)
22+
(component
23+
(type (;0;)
24+
(instance
25+
(export (;0;) "x" (type (sub resource)))
26+
)
27+
)
28+
(export (;0;) "foo:dependency/types" (instance (type 0)))
29+
)
30+
)
31+
(import "unlocked-dep=<test:bar>" (component (;0;) (type 5)))
32+
(instance (;2;) (instantiate 0))
33+
(alias export 1 "my-func" (func (;0;)))
34+
(alias export 2 "foo:dependency/types" (instance (;3;)))
35+
(type (;6;)
36+
(component
37+
(type (;0;)
38+
(instance
39+
(export (;0;) "x" (type (sub resource)))
40+
)
41+
)
42+
(import "foo:dependency/types" (instance (;0;) (type 0)))
43+
(alias outer 1 3 (type (;1;)))
44+
(import "x" (type (;2;) (eq 1)))
45+
(type (;3;) (own 2))
46+
(type (;4;) (func (result 3)))
47+
(import "my-func" (func (;0;) (type 4)))
48+
)
49+
)
50+
(import "unlocked-dep=<test:baz>" (component (;1;) (type 6)))
51+
(instance (;4;) (instantiate 1
52+
(with "foo:dependency/types" (instance 3))
53+
(with "my-func" (func 0))
54+
(with "x" (type 2))
55+
)
56+
)
57+
)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"packages": [
3+
{
4+
"name": "foo:import",
5+
"path": "import"
6+
},
7+
{
8+
"name": "test:bar",
9+
"path": "bar"
10+
},
11+
{
12+
"name": "test:baz",
13+
"path": "baz"
14+
}
15+
],
16+
"nodes": [
17+
{
18+
"type": "import",
19+
"name": "foo:test-import/my-interface",
20+
"package": 0,
21+
"export": "foo:test-import/my-interface"
22+
},
23+
{
24+
"type": "instantiation",
25+
"package": 1
26+
},
27+
{
28+
"type": "alias",
29+
"source": 0,
30+
"export": "my-func"
31+
},
32+
{
33+
"type": "alias",
34+
"source": 1,
35+
"export": "foo:dependency/types"
36+
},
37+
{
38+
"type": "instantiation",
39+
"package": 2
40+
}
41+
],
42+
"arguments": [
43+
{
44+
"source": 2,
45+
"target": 4,
46+
"name": "my-func"
47+
},
48+
{
49+
"source": 3,
50+
"target": 4,
51+
"name": "foo:dependency/types"
52+
}
53+
]
54+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package foo:dependency;
2+
3+
interface types {
4+
resource x;
5+
}
6+
7+
world w {
8+
export types;
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package foo:test-import;
2+
3+
world w {
4+
export my-interface;
5+
}
6+
7+
interface my-interface{
8+
use foo:dependency/types.{x};
9+
my-func: func() -> x;
10+
}

0 commit comments

Comments
 (0)