Skip to content

Commit a21b0df

Browse files
authored
[test] Segments are evaluated only once in array.{new,init}_elem (#2136)
1 parent 9fb3a59 commit a21b0df

3 files changed

Lines changed: 62 additions & 6 deletions

File tree

test/core/bulk-memory/table_init.wast

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
(import "a" "ef4" (func (result i32))) ;; index 4
2222
(table $t0 30 30 funcref)
2323
(table $t1 30 30 funcref)
24-
24+
2525
(elem (table $t0) (i32.const 2) func 3 1 4 1)
2626
(elem funcref
2727
(ref.func 2) (ref.func 7) (ref.func 1) (ref.func 8))
@@ -80,7 +80,7 @@
8080
(import "a" "ef4" (func (result i32))) ;; index 4
8181
(table $t0 30 30 funcref)
8282
(table $t1 30 30 funcref)
83-
83+
8484
(elem (table $t0) (i32.const 2) func 3 1 4 1)
8585
(elem funcref
8686
(ref.func 2) (ref.func 7) (ref.func 1) (ref.func 8))
@@ -139,7 +139,7 @@
139139
(import "a" "ef4" (func (result i32))) ;; index 4
140140
(table $t0 30 30 funcref)
141141
(table $t1 30 30 funcref)
142-
142+
143143
(elem (table $t0) (i32.const 2) func 3 1 4 1)
144144
(elem funcref
145145
(ref.func 2) (ref.func 7) (ref.func 1) (ref.func 8))
@@ -206,7 +206,7 @@
206206
(import "a" "ef4" (func (result i32))) ;; index 4
207207
(table $t0 30 30 funcref)
208208
(table $t1 30 30 funcref)
209-
209+
210210
(elem (table $t1) (i32.const 2) func 3 1 4 1)
211211
(elem funcref
212212
(ref.func 2) (ref.func 7) (ref.func 1) (ref.func 8))
@@ -265,7 +265,7 @@
265265
(import "a" "ef4" (func (result i32))) ;; index 4
266266
(table $t0 30 30 funcref)
267267
(table $t1 30 30 funcref)
268-
268+
269269
(elem (table $t1) (i32.const 2) func 3 1 4 1)
270270
(elem funcref
271271
(ref.func 2) (ref.func 7) (ref.func 1) (ref.func 8))
@@ -324,7 +324,7 @@
324324
(import "a" "ef4" (func (result i32))) ;; index 4
325325
(table $t0 30 30 funcref)
326326
(table $t1 30 30 funcref)
327-
327+
328328
(elem (table $t1) (i32.const 2) func 3 1 4 1)
329329
(elem funcref
330330
(ref.func 2) (ref.func 7) (ref.func 1) (ref.func 8))
@@ -2147,3 +2147,20 @@
21472147
(elem funcref) (elem funcref) (elem funcref) (elem funcref)
21482148
(elem funcref)
21492149
(func (table.init 64 (i32.const 0) (i32.const 0) (i32.const 0))))
2150+
2151+
;; Test that element segments are not re-evaluated on every `table.init`.
2152+
(module
2153+
(type $arr (array (mut arrayref)))
2154+
2155+
(table $table 2 arrayref)
2156+
(elem $elem arrayref (item (array.new_default $arr (i32.const 0))))
2157+
2158+
(func (export "run") (result i32)
2159+
(table.init $table $elem (i32.const 0) (i32.const 0) (i32.const 1))
2160+
(table.init $table $elem (i32.const 1) (i32.const 0) (i32.const 1))
2161+
(ref.eq (table.get $table (i32.const 0))
2162+
(table.get $table (i32.const 1)))
2163+
)
2164+
)
2165+
2166+
(assert_return (invoke "run") (i32.const 1))

test/core/gc/array_init_elem.wast

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,24 @@
155155
(assert_return (invoke "array_len_nth" (i32.const 0)) (i32.const 1))
156156
(assert_return (invoke "array_len_nth" (i32.const 1)) (i32.const 1))
157157
(assert_return (invoke "array_eq_elems" (i32.const 0) (i32.const 1)) (i32.const 1))
158+
159+
;; Test that element segments are not re-evaluated on every `array.init_elem`.
160+
(module
161+
(type $arr (array (mut arrayref)))
162+
(elem $elem arrayref (item (array.new_default $arr (i32.const 0))))
163+
(func (export "run") (result i32)
164+
(local $a (ref null $arr))
165+
(local $b (ref null $arr))
166+
167+
(local.set $a (array.new_default $arr (i32.const 1)))
168+
(array.init_elem $arr $elem (local.get $a) (i32.const 0) (i32.const 0) (i32.const 1))
169+
170+
(local.set $b (array.new_default $arr (i32.const 1)))
171+
(array.init_elem $arr $elem (local.get $b) (i32.const 0) (i32.const 0) (i32.const 1))
172+
173+
(ref.eq (array.get $arr (local.get $a) (i32.const 0))
174+
(array.get $arr (local.get $b) (i32.const 0)))
175+
)
176+
)
177+
178+
(assert_return (invoke "run") (i32.const 1))

test/core/gc/array_new_elem.wast

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,21 @@
101101

102102
;; Array is initialized with the correct contents.
103103
(assert_return (invoke "array-new-elem-contents") (i32.const 0xbb) (i32.const 0xcc))
104+
105+
;; Test that element segments are not re-evaluated on every `array.new_elem`.
106+
(module
107+
(type $arr (array (mut arrayref)))
108+
(elem $elem arrayref (item (array.new_default $arr (i32.const 0))))
109+
(func (export "run") (result i32)
110+
(local $a (ref null $arr))
111+
(local $b (ref null $arr))
112+
113+
(local.set $a (array.new_elem $arr $elem (i32.const 0) (i32.const 1)))
114+
(local.set $b (array.new_elem $arr $elem (i32.const 0) (i32.const 1)))
115+
116+
(ref.eq (array.get $arr (local.get $a) (i32.const 0))
117+
(array.get $arr (local.get $b) (i32.const 0)))
118+
)
119+
)
120+
121+
(assert_return (invoke "run") (i32.const 1))

0 commit comments

Comments
 (0)