Skip to content

Commit 0b11138

Browse files
committed
Add custom proposals tests; modify snapshots
1 parent 641ad23 commit 0b11138

24 files changed

+634
-39
lines changed
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
;; RUN: wast --assert default --snapshot tests/snapshots % -f custom-descriptors
2+
3+
;; --enable-gc
4+
5+
(module
6+
(type $f (func (result i32)))
7+
(rec
8+
(type $t1 (sub (descriptor $t2 (struct (field i32)))))
9+
(type $t2 (sub (describes $t1 (struct (field (ref $f))))))
10+
(type $t1sub (sub $t1 (descriptor $t2sub (struct (field i32 f32)))))
11+
(type $t2sub (sub $t2 (describes $t1sub (struct (field (ref $f) (ref $f))))))
12+
)
13+
14+
(import "" "rtt1" (global $g1 (ref (exact $t2))))
15+
(import "" "rtt1sub" (global $g1sub (ref (exact $t2sub))))
16+
17+
(elem declare func $f_impl)
18+
(func $f_impl (type $f) (result i32)
19+
unreachable
20+
)
21+
22+
(func $test-struct-new
23+
i32.const 3
24+
global.get $g1
25+
struct.new $t1
26+
drop
27+
28+
global.get $g1
29+
struct.new_default $t1
30+
drop
31+
32+
global.get $g1sub
33+
struct.new_default $t1sub
34+
drop
35+
)
36+
37+
(func $test-exact-types
38+
(local $l_any anyref)
39+
(local $l_struct structref)
40+
(local $l_t2 (ref $t2))
41+
(local $l_t2_e (ref (exact $t2)))
42+
global.get $g1
43+
local.set $l_any
44+
global.get $g1
45+
local.set $l_struct
46+
global.get $g1
47+
local.set $l_t2
48+
global.get $g1
49+
local.set $l_t2_e
50+
51+
global.get $g1sub
52+
local.set $l_struct
53+
global.get $g1sub
54+
local.set $l_t2
55+
56+
local.get $l_any
57+
ref.cast (ref null $t2)
58+
ref.cast (ref (exact $t2))
59+
local.set $l_t2_e
60+
)
61+
62+
(func $test-struct-new-result
63+
(local (ref (exact $t2)))
64+
ref.func $f_impl
65+
struct.new $t2
66+
local.set 0
67+
)
68+
69+
(func $test-get-desc (param $rtt (ref (exact $t2)))
70+
local.get $rtt
71+
struct.new_default $t1
72+
ref.get_desc $t1
73+
local.set $rtt
74+
)
75+
76+
(func $test-get-desc-2 (result (ref (exact $t2)))
77+
unreachable
78+
ref.get_desc $t1
79+
)
80+
81+
(func $test-cast-desc (param $i (ref $t1)) (param $desc (ref null (exact $t2))) (result (ref null (exact $t1)))
82+
local.get $i
83+
local.get $desc
84+
ref.cast_desc (ref null (exact $t1))
85+
)
86+
87+
(func $test-br_on_cast_desc (param $i (ref null $t1sub)) (param $desc (ref null $t2)) (result (ref null $t1))
88+
local.get $i
89+
local.get $desc
90+
br_on_cast_desc 0 (ref null $t1sub) (ref null $t1)
91+
)
92+
93+
(func $test-br_on_cast_desc_fail (param $i (ref null $t1sub)) (param $desc (ref null $t2)) (result (ref null $t1))
94+
local.get $i
95+
local.get $desc
96+
br_on_cast_desc_fail 0 (ref null $t1sub) (ref null $t1)
97+
)
98+
)
99+
100+
(assert_invalid
101+
(module
102+
(rec
103+
(type $t1 (sub (descriptor $t2 (struct (field i32)))))
104+
(type $t2 (sub (describes $t1 (struct (field (ref $f))))))
105+
(type $t1sub (sub $t1 (descriptor $t2sub (struct (field i32 f32)))))
106+
(type $t2sub (sub $t2 (describes $t1sub (struct (field (ref $f) (ref $f))))))
107+
(type $f (func (result i32)))
108+
)
109+
110+
(import "" "rtt1" (global $g1 (ref (exact $t2))))
111+
(import "" "rtt1sub" (global $g1sub (ref (exact $t2sub))))
112+
113+
(func $test-struct-new-non-exact-1
114+
global.get $g1sub
115+
i32.const 3
116+
struct.new $t1
117+
drop
118+
)
119+
)
120+
"type mismatch: expected (ref null (exact"
121+
)
122+
123+
(assert_invalid
124+
(module
125+
(rec
126+
(type $t1 (sub (descriptor $t2 (struct (field i32)))))
127+
(type $t2 (sub (describes $t1 (struct (field (ref $f))))))
128+
(type $t1sub (sub $t1 (descriptor $t2sub (struct (field i32 f32)))))
129+
(type $t2sub (sub $t2 (describes $t1sub (struct (field (ref $f) (ref $f))))))
130+
(type $f (func (result i32)))
131+
)
132+
133+
(import "" "rtt1" (global $g1 (ref (exact $t2))))
134+
(import "" "rtt1sub" (global $g1sub (ref (exact $t2sub))))
135+
136+
(func $test-struct-new-non-exact-2 (param (ref $t2))
137+
local.get 0
138+
struct.new_default $t1
139+
drop
140+
)
141+
)
142+
"type mismatch: expected (ref null (exact"
143+
)
144+
145+
(assert_invalid
146+
(module
147+
(rec
148+
(type $t1 (sub (descriptor $t2 (struct (field i32)))))
149+
(type $t2 (sub (describes $t1 (struct (field (ref $f))))))
150+
(type $t1sub (sub $t1 (descriptor $t2sub (struct (field i32 f32)))))
151+
(type $t2sub (sub $t2 (describes $t1sub (struct (field (ref $f) (ref $f))))))
152+
(type $f (func (result i32)))
153+
)
154+
155+
(import "" "rtt1" (global $g1 (ref (exact $t2))))
156+
(import "" "rtt1sub" (global $g1sub (ref (exact $t2sub))))
157+
158+
(func $test-struct-new-non-exact-3
159+
global.get $g1
160+
i32.const 2
161+
f32.const 1
162+
struct.new $t1sub
163+
drop
164+
)
165+
)
166+
"type mismatch: expected (ref null (exact"
167+
)
168+
169+
170+
(assert_invalid
171+
(module
172+
(rec
173+
(type $t1 (sub (descriptor $t2 (struct (field i32)))))
174+
(type $t2 (sub (describes $t1 (struct (field (ref $f))))))
175+
(type $t1sub (sub $t1 (descriptor $t2sub (struct (field i32 f32)))))
176+
(type $t2sub (sub $t2 (describes $t1sub (struct (field (ref $f) (ref $f))))))
177+
(type $f (func (result i32)))
178+
)
179+
180+
(import "" "rtt1" (global $g1 (ref (exact $t2))))
181+
(import "" "rtt1sub" (global $g1sub (ref (exact $t2sub))))
182+
183+
(func $test-br_on_cast_desc-bad-types (param $i (ref null $f)) (param $desc (ref null $t2)) (result (ref null $t1))
184+
local.get $i
185+
local.get $desc
186+
br_on_cast_desc 0 (ref null $f) (ref null $t1)
187+
)
188+
189+
)
190+
"type mismatch:"
191+
)

tests/cli/custom-descriptors.wast

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
;; RUN: wast --assert default --snapshot tests/snapshots % -f custom-descriptors
2+
3+
;; --enable-gc
4+
5+
(module
6+
(rec
7+
(type $t1 (descriptor $t2 (struct (field i32))))
8+
(type $t2 (describes $t1 (struct (field (ref $f)))))
9+
(type $f (func (result i32)))
10+
)
11+
)
12+
13+
(assert_invalid
14+
(module
15+
(rec
16+
(type $f (func (result i32)))
17+
(type $t2 (describes $t1 (struct (field (ref $f)))))
18+
(type $t1 (descriptor $t2 (struct (field i32))))
19+
)
20+
)
21+
"forward describes reference"
22+
)
23+
24+
(assert_invalid
25+
(module
26+
(rec
27+
(type $t1 (descriptor $t2 (array f32)))
28+
(type $t2 (describes $t1 (struct (field funcref))))
29+
)
30+
)
31+
"descriptor clause on non-struct type"
32+
)
33+
34+
(assert_invalid
35+
(module
36+
(rec
37+
(type $t1 (descriptor $t2 (struct (field i32))))
38+
(type $t2 (describes $t1 (func)))
39+
)
40+
)
41+
"describes clause on non-struct type"
42+
)
43+
44+
(module
45+
(rec
46+
(type $t1 (sub (descriptor $t2 (struct (field i32)))))
47+
(type $t2 (sub (describes $t1 (struct (field (ref $f))))))
48+
(type $t1sub (sub $t1 (descriptor $t2sub (struct (field i32 f32)))))
49+
(type $t2sub (sub $t2 (describes $t1sub (struct (field (ref $f) (ref $f))))))
50+
(type $f (func (result i32)))
51+
)
52+
)
53+
54+
(assert_invalid
55+
(module
56+
(rec
57+
(type $t1 (sub (descriptor $t2 (struct (field i32)))))
58+
(type $t2 (sub (describes $t1 (struct (field (ref $f))))))
59+
(type $t1sub (sub $t1 (descriptor $t2sub (struct (field i32 f32)))))
60+
(type $t2sub (sub (describes $t1sub (struct (field (ref $f) (ref $f))))))
61+
(type $f (func (result i32)))
62+
)
63+
)
64+
"supertype of described type must be described by supertype of descriptor"
65+
)
66+
67+
(assert_invalid
68+
(module
69+
(rec
70+
(type $t1 (sub (descriptor $t2 (struct (field i32)))))
71+
(type $t2 (sub (describes $t1 (struct (field (ref $f))))))
72+
(type $t1n (sub (descriptor $t2n (struct (field i64)))))
73+
(type $t2n (sub (describes $t1n (struct (field (ref $f))))))
74+
(type $t1sub (sub $t1 (descriptor $t2sub (struct (field i32 f32)))))
75+
(type $t2sub (sub $t2n (describes $t1sub (struct (field (ref $f) (ref $f))))))
76+
(type $f (func (result i32)))
77+
)
78+
)
79+
"supertype of described type must be described by supertype of descriptor"
80+
)
81+
82+
(assert_invalid
83+
(module
84+
(rec
85+
(type $t1 (sub (descriptor $t2 (struct (field i32)))))
86+
(type $t2 (sub (describes $t1 (struct (field (ref $f))))))
87+
(type $t1sub (sub $t1 (struct (field i32 f32))))
88+
(type $t2sub (sub $t2 (describes $t1sub (struct (field (ref $f) (ref $f))))))
89+
(type $f (func (result i32)))
90+
)
91+
)
92+
"supertype of type without descriptor cannot have descriptor"
93+
)
94+
95+
(assert_invalid
96+
(module
97+
(rec
98+
(type $t1 (sub (descriptor $t2 (struct (field i32)))))
99+
(type $t2 (sub (describes $t1 (struct (field (ref $f))))))
100+
(type $t1sub (sub $t1 (descriptor $t2sub (struct (field i32 f32)))))
101+
(type $t2sub (sub $t2 (describes $t1sub (struct (field (ref $f) (ref $f))))))
102+
(type $t2sub-n (sub $t2sub (struct (field (ref $f) (ref $f) (ref $f)))))
103+
(type $f (func (result i32)))
104+
)
105+
)
106+
"supertype of non-descriptor type cannot be a descriptor"
107+
)
108+
109+
(assert_invalid
110+
(module
111+
(rec
112+
(type $t0 (sub (struct (field (ref $f)))))
113+
(type $t1 (sub (descriptor $t2 (struct (field i32)))))
114+
(type $t2 (sub $t0 (describes $t1 (struct (field (ref $f))))))
115+
(type $f (func (result i32)))
116+
)
117+
)
118+
"supertype of descriptor must be a descriptor"
119+
)
120+
121+
(assert_invalid
122+
(module
123+
(rec
124+
(type $f (func (result i32)))
125+
(type $t1 (descriptor $t2 (struct (field i32))))
126+
(type $t2 (struct (field (ref $f))))
127+
)
128+
)
129+
"descriptor with no matching describes"
130+
)
131+
132+
(assert_invalid
133+
(module
134+
(rec
135+
(type $f (func (result i32)))
136+
(type $t1 (descriptor $t2 (struct (field i32))))
137+
(type $t1b (descriptor $t2 (struct (field i32))))
138+
(type $t2 (describes $t1b (struct (field (ref $f)))))
139+
)
140+
)
141+
"descriptor with no matching describes"
142+
)
143+
144+
145+
(assert_invalid
146+
(module
147+
(rec
148+
(type $f (func (result i32)))
149+
(type $t1 (struct (field i32)))
150+
(type $t2 (describes $t1 (struct (field (ref $f)))))
151+
)
152+
)
153+
"describes with no matching descriptor"
154+
)
155+
156+
(assert_invalid
157+
(module
158+
(rec
159+
(type $f (func (result i32)))
160+
(type $t1 (descriptor $t2 (struct (field i32))))
161+
(type $t2 (describes $t1 (struct (field (ref $f)))))
162+
(type $t2b (describes $t1 (struct (field (ref $f)))))
163+
)
164+
)
165+
"describes with no matching descriptor"
166+
)

tests/cli/dump-branch-hints.wat.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
0x8 | 01 04 | type section
44
0xa | 01 | 1 count
55
--- rec group 0 (implicit) ---
6-
0xb | 60 00 00 | [type 0] SubType { is_final: true, supertype_idx: None, composite_type: CompositeType { inner: Func(FuncType { params: [], results: [] }), shared: false } }
6+
0xb | 60 00 00 | [type 0] SubType { is_final: true, supertype_idx: None, composite_type: CompositeType { inner: Func(FuncType { params: [], results: [] }), shared: false, descriptor_idx: None, describes_idx: None } }
77
0xe | 03 02 | func section
88
0x10 | 01 | 1 count
99
0x11 | 00 | [func 0] type 0

tests/cli/dump-elem-segments.wat.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
0x8 | 01 04 | type section
44
0xa | 01 | 1 count
55
--- rec group 0 (implicit) ---
6-
0xb | 60 00 00 | [type 0] SubType { is_final: true, supertype_idx: None, composite_type: CompositeType { inner: Func(FuncType { params: [], results: [] }), shared: false } }
6+
0xb | 60 00 00 | [type 0] SubType { is_final: true, supertype_idx: None, composite_type: CompositeType { inner: Func(FuncType { params: [], results: [] }), shared: false, descriptor_idx: None, describes_idx: None } }
77
0xe | 03 02 | func section
88
0x10 | 01 | 1 count
99
0x11 | 00 | [func 0] type 0

0 commit comments

Comments
 (0)