Skip to content

Commit 0970c6d

Browse files
committed
Add names section to encoded WAC documents.
Implements #37.
1 parent ff6cf2b commit 0970c6d

6 files changed

Lines changed: 81 additions & 73 deletions

File tree

crates/wac-parser/src/resolution.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,14 @@ impl State {
785785
});
786786
}
787787

788+
if let Item::Node(node) = item {
789+
// Use only the first name encountered for the node, ignoring
790+
// aliasing in the form of `let x = y;`
791+
if self.graph[node].name.is_none() {
792+
self.graph.set_node_name(node, id.string.to_owned());
793+
}
794+
}
795+
788796
Ok(())
789797
}
790798

crates/wac-parser/tests/encoding/instantiation.wac.result

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
(export (;0;) "foo" (func (type 0)))
1515
)
1616
)
17-
(import "i" (instance (;1;) (type 2)))
17+
(import "i" (instance $i (;1;) (type 2)))
1818
(type (;3;)
1919
(instance
2020
(type (;0;) (func))
2121
(export (;0;) "baz" (func (type 0)))
2222
)
2323
)
24-
(import "i2" (instance (;2;) (type 3)))
24+
(import "i2" (instance $i2 (;2;) (type 3)))
2525
(type (;4;) (func))
26-
(import "f" (func (;1;) (type 4)))
26+
(import "f" (func $f (;1;) (type 4)))
2727
(type (;5;)
2828
(component
2929
(type (;0;) (func))
@@ -32,20 +32,20 @@
3232
)
3333
)
3434
(import "unlocked-dep=<foo:bar>" (component (;0;) (type 5)))
35-
(instance (;3;) (instantiate 0
35+
(instance $x1 (;3;) (instantiate 0
3636
(with "baz" (func 0))
3737
)
3838
)
39-
(instance (;4;) (instantiate 0
40-
(with "baz" (func 1))
39+
(instance $x2 (;4;) (instantiate 0
40+
(with "baz" (func $f))
4141
)
4242
)
43-
(instance (;5;) (instantiate 0
44-
(with "baz" (func 1))
43+
(instance $x3 (;5;) (instantiate 0
44+
(with "baz" (func $f))
4545
)
4646
)
47-
(alias export 2 "baz" (func (;2;)))
48-
(instance (;6;) (instantiate 0
47+
(alias export $i2 "baz" (func (;2;)))
48+
(instance $x4 (;6;) (instantiate 0
4949
(with "baz" (func 2))
5050
)
5151
)
@@ -61,27 +61,27 @@
6161
)
6262
)
6363
(import "unlocked-dep=<bar:baz>" (component (;1;) (type 6)))
64-
(instance (;7;) (instantiate 1
64+
(instance $y1 (;7;) (instantiate 1
6565
(with "foo" (instance 0))
6666
)
6767
)
68-
(instance (;8;) (instantiate 1
69-
(with "foo" (instance 1))
68+
(instance $y2 (;8;) (instantiate 1
69+
(with "foo" (instance $i))
7070
)
7171
)
72-
(instance (;9;) (instantiate 1
73-
(with "foo" (instance 3))
72+
(instance $y3 (;9;) (instantiate 1
73+
(with "foo" (instance $x1))
7474
)
7575
)
76-
(instance (;10;) (instantiate 1
77-
(with "foo" (instance 4))
76+
(instance $y4 (;10;) (instantiate 1
77+
(with "foo" (instance $x2))
7878
)
7979
)
80-
(instance (;11;) (instantiate 1
81-
(with "foo" (instance 5))
80+
(instance $y5 (;11;) (instantiate 1
81+
(with "foo" (instance $x3))
8282
)
8383
)
84-
(alias export 6 "foo" (func (;3;)))
84+
(alias export $x4 "foo" (func (;3;)))
8585
(export (;4;) "foo" (func 3))
8686
(@producers
8787
(processed-by "wac-parser" "0.1.0")

crates/wac-parser/tests/encoding/merged-functions.wac.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
)
2525
)
2626
(import "unlocked-dep=<foo:bar>" (component (;0;) (type 1)))
27-
(instance (;1;) (instantiate 0
27+
(instance $a (;1;) (instantiate 0
2828
(with "foo:bar/baz" (instance 0))
2929
)
3030
)
@@ -42,7 +42,7 @@
4242
)
4343
)
4444
(import "unlocked-dep=<foo:baz>" (component (;1;) (type 2)))
45-
(instance (;2;) (instantiate 1
45+
(instance $b (;2;) (instantiate 1
4646
(with "foo:bar/baz" (instance 0))
4747
)
4848
)

crates/wac-parser/tests/encoding/resources.wac.result

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
(export (;4;) "baz" (func (type 11)))
2121
)
2222
)
23-
(import "foo" (instance (;0;) (type 0)))
23+
(import "foo" (instance $foo (;0;) (type 0)))
2424
(type (;1;)
2525
(component
2626
(type (;0;)
@@ -43,11 +43,11 @@
4343
)
4444
)
4545
(import "unlocked-dep=<foo:bar>" (component (;0;) (type 1)))
46-
(instance (;1;) (instantiate 0
47-
(with "foo" (instance 0))
46+
(instance $x (;1;) (instantiate 0
47+
(with "foo" (instance $foo))
4848
)
4949
)
50-
(alias export 1 "foo" (instance (;2;)))
50+
(alias export $x "foo" (instance (;2;)))
5151
(export (;3;) "foo" (instance 2))
5252
(@producers
5353
(processed-by "wac-parser" "0.1.0")

crates/wac-parser/tests/encoding/types.wac.result

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
(component
22
(type (;0;) u8)
3-
(export (;1;) "a" (type 0))
3+
(export $a (;1;) "a" (type 0))
44
(type (;2;) s8)
5-
(export (;3;) "b" (type 2))
5+
(export $b (;3;) "b" (type 2))
66
(type (;4;) u16)
7-
(export (;5;) "c" (type 4))
7+
(export $c (;5;) "c" (type 4))
88
(type (;6;) s16)
9-
(export (;7;) "d" (type 6))
9+
(export $d (;7;) "d" (type 6))
1010
(type (;8;) u32)
11-
(export (;9;) "e" (type 8))
11+
(export $e (;9;) "e" (type 8))
1212
(type (;10;) s32)
13-
(export (;11;) "f" (type 10))
13+
(export $f (;11;) "f" (type 10))
1414
(type (;12;) u64)
15-
(export (;13;) "g" (type 12))
15+
(export $g (;13;) "g" (type 12))
1616
(type (;14;) s64)
17-
(export (;15;) "h" (type 14))
17+
(export $h (;15;) "h" (type 14))
1818
(type (;16;) f32)
19-
(export (;17;) "i" (type 16))
19+
(export $i (;17;) "i" (type 16))
2020
(type (;18;) f64)
21-
(export (;19;) "j" (type 18))
21+
(export $j (;19;) "j" (type 18))
2222
(type (;20;) bool)
23-
(export (;21;) "k" (type 20))
23+
(export $k (;21;) "k" (type 20))
2424
(type (;22;) char)
25-
(export (;23;) "l" (type 22))
25+
(export $l (;23;) "l" (type 22))
2626
(type (;24;) string)
27-
(export (;25;) "m" (type 24))
27+
(export $m (;25;) "m" (type 24))
2828
(type (;26;) (list u8))
2929
(type (;27;) (tuple s8 u16 s16))
3030
(type (;28;) (option u32))
3131
(type (;29;) (record (field "a" 26) (field "b" 27) (field "c" 28)))
32-
(export (;30;) "n" (type 29))
33-
(type (;31;) (tuple 30 30 30))
34-
(type (;32;) (variant (case "foo") (case "bar" 30) (case "baz" 31)))
35-
(export (;33;) "o" (type 32))
32+
(export $n (;30;) "n" (type 29))
33+
(type (;31;) (tuple $n $n $n))
34+
(type (;32;) (variant (case "foo") (case "bar" $n) (case "baz" 31)))
35+
(export $o (;33;) "o" (type 32))
3636
(type (;34;) (flags "foo" "bar" "baz"))
37-
(export (;35;) "p" (type 34))
37+
(export $p (;35;) "p" (type 34))
3838
(type (;36;) (enum "a" "b" "c"))
39-
(export (;37;) "q" (type 36))
39+
(export $q (;37;) "q" (type 36))
4040
(type (;38;)
4141
(component
4242
(type (;0;)
@@ -64,7 +64,7 @@
6464
(export (;0;) "test:pkg/r" (instance (type 0)))
6565
)
6666
)
67-
(export (;39;) "r" (type 38))
67+
(export $r (;39;) "r" (type 38))
6868
(type (;40;)
6969
(component
7070
(type (;0;)
@@ -108,7 +108,7 @@
108108
(export (;1;) "test:pkg/s" (instance (type 4)))
109109
)
110110
)
111-
(export (;41;) "s" (type 40))
111+
(export $s (;41;) "s" (type 40))
112112
(type (;42;)
113113
(component
114114
(type (;0;)
@@ -152,24 +152,24 @@
152152
(export (;0;) "test:pkg/t" (component (type 0)))
153153
)
154154
)
155-
(export (;43;) "t" (type 42))
156-
(export (;44;) "a2" (type 1))
157-
(export (;45;) "b2" (type 3))
158-
(export (;46;) "c2" (type 5))
159-
(export (;47;) "d2" (type 7))
160-
(export (;48;) "e2" (type 9))
161-
(export (;49;) "f2" (type 11))
162-
(export (;50;) "g2" (type 13))
163-
(export (;51;) "h2" (type 15))
164-
(export (;52;) "i2" (type 17))
165-
(export (;53;) "j2" (type 19))
166-
(export (;54;) "k2" (type 21))
167-
(export (;55;) "l2" (type 23))
168-
(export (;56;) "n2" (type 30))
169-
(export (;57;) "m2" (type 25))
170-
(export (;58;) "o2" (type 33))
171-
(export (;59;) "p2" (type 35))
172-
(export (;60;) "q2" (type 37))
155+
(export $t (;43;) "t" (type 42))
156+
(export $a2 (;44;) "a2" (type $a))
157+
(export $b2 (;45;) "b2" (type $b))
158+
(export $c2 (;46;) "c2" (type $c))
159+
(export $d2 (;47;) "d2" (type $d))
160+
(export $e2 (;48;) "e2" (type $e))
161+
(export $f2 (;49;) "f2" (type $f))
162+
(export $g2 (;50;) "g2" (type $g))
163+
(export $h2 (;51;) "h2" (type $h))
164+
(export $i2 (;52;) "i2" (type $i))
165+
(export $j2 (;53;) "j2" (type $j))
166+
(export $k2 (;54;) "k2" (type $k))
167+
(export $l2 (;55;) "l2" (type $l))
168+
(export $n2 (;56;) "n2" (type $n))
169+
(export $m2 (;57;) "m2" (type $m))
170+
(export $o2 (;58;) "o2" (type $o))
171+
(export $p2 (;59;) "p2" (type $p))
172+
(export $q2 (;60;) "q2" (type $q))
173173
(@producers
174174
(processed-by "wac-parser" "0.1.0")
175175
)

crates/wac-resolver/tests/registry.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ export i2.foo as "bar";
7979
(export (;0;) "bar" (func (type 0)))
8080
)
8181
)
82-
(import "test:wit/foo" (instance (;0;) (type 0)))
82+
(import "test:wit/foo" (instance $x (;0;) (type 0)))
8383
(type (;1;)
8484
(instance
8585
(type (;0;) (func))
8686
(export (;0;) "bar" (func (type 0)))
8787
)
8888
)
89-
(import "y" (instance (;1;) (type 1)))
89+
(import "y" (instance $y (;1;) (type 1)))
9090
(type (;2;)
9191
(component
9292
(type (;0;)
@@ -100,16 +100,16 @@ export i2.foo as "bar";
100100
)
101101
)
102102
(import "unlocked-dep=<test:comp>" (component (;0;) (type 2)))
103-
(instance (;2;) (instantiate 0
104-
(with "test:wit/foo" (instance 0))
103+
(instance $i1 (;2;) (instantiate 0
104+
(with "test:wit/foo" (instance $x))
105105
)
106106
)
107-
(instance (;3;) (instantiate 0
108-
(with "test:wit/foo" (instance 1))
107+
(instance $i2 (;3;) (instantiate 0
108+
(with "test:wit/foo" (instance $y))
109109
)
110110
)
111-
(alias export 2 "test:wit/foo" (instance (;4;)))
112-
(alias export 3 "test:wit/foo" (instance (;5;)))
111+
(alias export $i1 "test:wit/foo" (instance (;4;)))
112+
(alias export $i2 "test:wit/foo" (instance (;5;)))
113113
(export (;6;) "test:wit/foo" (instance 4))
114114
(export (;7;) "bar" (instance 5))
115115
(@producers

0 commit comments

Comments
 (0)