Skip to content

Commit 2d40237

Browse files
committed
Add test for merging func params/results
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
1 parent ac9f365 commit 2d40237

5 files changed

Lines changed: 239 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
(component
2+
(type (;0;)
3+
(instance
4+
(type (;0;) (record (field "foo" u8)))
5+
(export (;1;) "foo" (type (eq 0)))
6+
(type (;2;) (func (result 1)))
7+
(export (;0;) "my-func1" (func (type 2)))
8+
)
9+
)
10+
(import "example:example/my-interface" (instance (;0;) (type 0)))
11+
(core module (;0;)
12+
(type (;0;) (func (result i32)))
13+
(type (;1;) (func (param i32 i32 i32 i32) (result i32)))
14+
(import "example:example/my-interface" "my-func1" (func (;0;) (type 0)))
15+
(func (;1;) (type 1) (param i32 i32 i32 i32) (result i32)
16+
unreachable
17+
)
18+
(memory (;0;) 0)
19+
(export "memory" (memory 0))
20+
(export "cabi_realloc" (func 1))
21+
)
22+
(alias export 0 "my-func1" (func (;0;)))
23+
(core func (;0;) (canon lower (func 0)))
24+
(core instance (;0;)
25+
(export "my-func1" (func 0))
26+
)
27+
(core instance (;1;) (instantiate 0
28+
(with "example:example/my-interface" (instance 0))
29+
)
30+
)
31+
)
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+
(type (;0;) (record (field "foo" u8)))
5+
(export (;1;) "foo" (type (eq 0)))
6+
(type (;2;) (func (result 1)))
7+
(export (;0;) "my-func2" (func (type 2)))
8+
)
9+
)
10+
(import "example:example/my-interface" (instance (;0;) (type 0)))
11+
(core module (;0;)
12+
(type (;0;) (func (result i32)))
13+
(type (;1;) (func (param i32 i32 i32 i32) (result i32)))
14+
(import "example:example/my-interface" "my-func2" (func (;0;) (type 0)))
15+
(func (;1;) (type 0) (result i32)
16+
unreachable
17+
)
18+
(func (;2;) (type 1) (param i32 i32 i32 i32) (result i32)
19+
unreachable
20+
)
21+
(memory (;0;) 0)
22+
(export "example:example/my-interface#my-func2" (func 1))
23+
(export "memory" (memory 0))
24+
(export "cabi_realloc" (func 2))
25+
)
26+
(alias export 0 "my-func2" (func (;0;)))
27+
(core func (;0;) (canon lower (func 0)))
28+
(core instance (;0;)
29+
(export "my-func2" (func 0))
30+
)
31+
(core instance (;1;) (instantiate 0
32+
(with "example:example/my-interface" (instance 0))
33+
)
34+
)
35+
(alias core export 1 "memory" (core memory (;0;)))
36+
(alias core export 1 "cabi_realloc" (core func (;1;)))
37+
(type (;1;) (record (field "foo" u8)))
38+
(type (;2;) (func (result 1)))
39+
(alias core export 1 "example:example/my-interface#my-func2" (core func (;2;)))
40+
(func (;1;) (type 2) (canon lift (core func 2)))
41+
(component (;0;)
42+
(type (;0;) (record (field "foo" u8)))
43+
(import "import-type-foo" (type (;1;) (eq 0)))
44+
(type (;2;) (func (result 1)))
45+
(import "import-func-my-func2" (func (;0;) (type 2)))
46+
(type (;3;) (record (field "foo" u8)))
47+
(export (;4;) "foo" (type 3))
48+
(type (;5;) (func (result 4)))
49+
(export (;1;) "my-func2" (func 0) (func (type 5)))
50+
)
51+
(instance (;1;) (instantiate 0
52+
(with "import-func-my-func2" (func 1))
53+
(with "import-type-foo" (type 1))
54+
)
55+
)
56+
(export (;2;) "example:example/my-interface" (instance 1))
57+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
During aggregation when merging the "source" interface into the aggregated "target" interface,
2+
we check whether for any given export from the source interface, if there is an export in the
3+
target types collection with the same name that is a subtype of that export (see here). If no,
4+
we can simply skip merging that export because it's equivalent already exists in the target collection.
5+
This should even work when there is a source function export that does not exist in the target
6+
collection but makes use of a type (either in params or results) that is already present in the
7+
target collection (i.e., its param/results are types that have equivalents in the target collection).
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
(component
2+
(type (;0;)
3+
(instance
4+
(type (;0;) (record (field "foo" u8)))
5+
(export (;1;) "foo" (type (eq 0)))
6+
(type (;2;) (func (result 1)))
7+
(export (;0;) "my-func1" (func (type 2)))
8+
(type (;3;) (func (result 1)))
9+
(export (;1;) "my-func2" (func (type 3)))
10+
)
11+
)
12+
(import "example:example/my-interface" (instance (;0;) (type 0)))
13+
(component (;0;)
14+
(type (;0;)
15+
(instance
16+
(type (;0;) (record (field "foo" u8)))
17+
(export (;1;) "foo" (type (eq 0)))
18+
(type (;2;) (func (result 1)))
19+
(export (;0;) "my-func2" (func (type 2)))
20+
)
21+
)
22+
(import "example:example/my-interface" (instance (;0;) (type 0)))
23+
(core module (;0;)
24+
(type (;0;) (func (result i32)))
25+
(type (;1;) (func (param i32 i32 i32 i32) (result i32)))
26+
(import "example:example/my-interface" "my-func2" (func (;0;) (type 0)))
27+
(func (;1;) (type 0) (result i32)
28+
unreachable
29+
)
30+
(func (;2;) (type 1) (param i32 i32 i32 i32) (result i32)
31+
unreachable
32+
)
33+
(memory (;0;) 0)
34+
(export "example:example/my-interface#my-func2" (func 1))
35+
(export "memory" (memory 0))
36+
(export "cabi_realloc" (func 2))
37+
)
38+
(alias export 0 "my-func2" (func (;0;)))
39+
(core func (;0;) (canon lower (func 0)))
40+
(core instance (;0;)
41+
(export "my-func2" (func 0))
42+
)
43+
(core instance (;1;) (instantiate 0
44+
(with "example:example/my-interface" (instance 0))
45+
)
46+
)
47+
(alias core export 1 "memory" (core memory (;0;)))
48+
(alias core export 1 "cabi_realloc" (core func (;1;)))
49+
(type (;1;) (record (field "foo" u8)))
50+
(type (;2;) (func (result 1)))
51+
(alias core export 1 "example:example/my-interface#my-func2" (core func (;2;)))
52+
(func (;1;) (type 2) (canon lift (core func 2)))
53+
(component (;0;)
54+
(type (;0;) (record (field "foo" u8)))
55+
(import "import-type-foo" (type (;1;) (eq 0)))
56+
(type (;2;) (func (result 1)))
57+
(import "import-func-my-func2" (func (;0;) (type 2)))
58+
(type (;3;) (record (field "foo" u8)))
59+
(export (;4;) "foo" (type 3))
60+
(type (;5;) (func (result 4)))
61+
(export (;1;) "my-func2" (func 0) (func (type 5)))
62+
)
63+
(instance (;1;) (instantiate 0
64+
(with "import-func-my-func2" (func 1))
65+
(with "import-type-foo" (type 1))
66+
)
67+
)
68+
(export (;2;) "example:example/my-interface" (instance 1))
69+
)
70+
(instance (;1;) (instantiate 0
71+
(with "example:example/my-interface" (instance 0))
72+
)
73+
)
74+
(alias export 1 "example:example/my-interface" (instance (;2;)))
75+
(component (;1;)
76+
(type (;0;)
77+
(instance
78+
(type (;0;) (record (field "foo" u8)))
79+
(export (;1;) "foo" (type (eq 0)))
80+
(type (;2;) (func (result 1)))
81+
(export (;0;) "my-func1" (func (type 2)))
82+
)
83+
)
84+
(import "example:example/my-interface" (instance (;0;) (type 0)))
85+
(core module (;0;)
86+
(type (;0;) (func (result i32)))
87+
(type (;1;) (func (param i32 i32 i32 i32) (result i32)))
88+
(import "example:example/my-interface" "my-func1" (func (;0;) (type 0)))
89+
(func (;1;) (type 1) (param i32 i32 i32 i32) (result i32)
90+
unreachable
91+
)
92+
(memory (;0;) 0)
93+
(export "memory" (memory 0))
94+
(export "cabi_realloc" (func 1))
95+
)
96+
(alias export 0 "my-func1" (func (;0;)))
97+
(core func (;0;) (canon lower (func 0)))
98+
(core instance (;0;)
99+
(export "my-func1" (func 0))
100+
)
101+
(core instance (;1;) (instantiate 0
102+
(with "example:example/my-interface" (instance 0))
103+
)
104+
)
105+
)
106+
(instance (;3;) (instantiate 1
107+
(with "example:example/my-interface" (instance 0))
108+
)
109+
)
110+
(export (;4;) "example:example/my-interface" (instance 2))
111+
)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"packages": [
3+
{
4+
"name": "example:component1",
5+
"path": "component1.wat"
6+
},
7+
{
8+
"name": "example:component2",
9+
"path": "component2.wat"
10+
}
11+
],
12+
"nodes": [
13+
{
14+
"type": "instantiation",
15+
"package": 0
16+
},
17+
{
18+
"type": "instantiation",
19+
"package": 1
20+
},
21+
{
22+
"type": "alias",
23+
"source": 1,
24+
"export": "example:example/my-interface"
25+
}
26+
],
27+
"exports": [
28+
{
29+
"node": 2,
30+
"name": "example:example/my-interface"
31+
}
32+
]
33+
}

0 commit comments

Comments
 (0)