Skip to content

Commit 6531a98

Browse files
authored
[wasm-split] Make mutable/immutable versions of tests (#9062)
A follow-up PR will move immutable globals to secondary modules when possible, and it will make the test expectations of `transitive-globals-multi.wast` different for mutable and immutable globals. Creating a new test in that PR will make it different to see what changes in that PR. So this PR duplicates the test to make mutable and immutable versions. Note that `$f` can't be converted to mutable because it is used in a `global.get`. This also adds mutable/immutable versions of globals to `split-module-items.wast`.
1 parent f870c9e commit 6531a98

3 files changed

Lines changed: 93 additions & 19 deletions

File tree

test/lit/wasm-split/split-module-items.wast

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
;; This is only used in the secondary module, but segments $keep-data2 can trap
2020
;; so it is pinned to the primary, so this will be too.
2121
(memory $keep-memory2 1 1)
22-
(global $keep-global i32 (i32.const 20))
22+
(global $keep-immutable-global i32 (i32.const 20))
23+
(global $keep-mutable-global (mut i32) (i32.const 20))
2324
(table $keep-table 1 1 funcref)
2425
;; This is only used in the secondary module, but segments $keep-elem2 and
2526
;; $keep-elem3 can trap so they are pinned to the primary, so this will be too.
@@ -35,21 +36,25 @@
3536
(data $keep-data2 (memory $keep-memory2) (i32.const 65536) "a")
3637

3738
(memory $split-memory 1 1)
38-
(global $split-global i32 (i32.const 20))
39+
(global $split-immutable-global i32 (i32.const 20))
40+
(global $split-mutable-global (mut i32) (i32.const 20))
3941
(table $split-table 1 1 funcref)
4042
(tag $split-tag (param i32))
4143
(elem $split-elem (table $split-table) (i32.const 0) funcref (item (ref.null nofunc)))
4244
(data $split-data (memory $split-memory) (i32.const 0) "a")
4345

4446
(memory $shared-memory 1 1)
45-
(global $shared-global i32 (i32.const 20))
47+
(global $shared-immutable-global i32 (i32.const 20))
48+
(global $shared-mutable-global (mut i32) (i32.const 20))
4649
(table $shared-table 1 1 funcref)
4750
(tag $shared-tag (param i32))
4851
(elem $shared-elem (table $shared-table) (i32.const 0) funcref (item (ref.null nofunc)))
4952
(data $shared-data (memory $shared-memory) (i32.const 0) "a")
5053

51-
;; PRIMARY: (global $keep-global i32 (i32.const 20))
52-
;; PRIMARY-NEXT: (global $shared-global i32 (i32.const 20))
54+
;; PRIMARY: (global $keep-immutable-global i32 (i32.const 20))
55+
;; PRIMARY-NEXT: (global $keep-mutable-global (mut i32) (i32.const 20))
56+
;; PRIMARY-NEXT: (global $shared-immutable-global i32 (i32.const 20))
57+
;; PRIMARY-NEXT: (global $shared-mutable-global (mut i32) (i32.const 20))
5358
;; PRIMARY-NEXT: (memory $keep-memory 1 1)
5459
;; PRIMARY-NEXT: (memory $keep-memory2 1 1)
5560
;; PRIMARY-NEXT: (memory $shared-memory 1 1)
@@ -73,21 +78,24 @@
7378
;; PRIMARY-NEXT: (export "memory_1" (memory $shared-memory))
7479
;; PRIMARY-NEXT: (export "table" (table $keep-table2))
7580
;; PRIMARY-NEXT: (export "table_3" (table $shared-table))
76-
;; PRIMARY-NEXT: (export "global" (global $shared-global))
81+
;; PRIMARY-NEXT: (export "global" (global $shared-immutable-global))
82+
;; PRIMARY-NEXT: (export "global_5" (global $shared-mutable-global))
7783
;; PRIMARY-NEXT: (export "tag" (tag $shared-tag))
7884
;; PRIMARY-NEXT: (export "keep" (func $keep))
79-
;; PRIMARY-NEXT: (export "table_7" (table $3))
85+
;; PRIMARY-NEXT: (export "table_8" (table $3))
8086

8187
;; SECONDARY: (import "primary" "memory" (memory $keep-memory2 1 1))
8288
;; SECONDARY-NEXT: (import "primary" "memory_1" (memory $shared-memory 1 1))
8389
;; SECONDARY-NEXT: (import "primary" "table" (table $keep-table2 1 1 (ref null $2)))
8490
;; SECONDARY-NEXT: (import "primary" "table_3" (table $shared-table 1 1 funcref))
85-
;; SECONDARY-NEXT: (import "primary" "table_7" (table $timport$2 1 funcref))
86-
;; SECONDARY-NEXT: (import "primary" "global" (global $shared-global i32))
91+
;; SECONDARY-NEXT: (import "primary" "table_8" (table $timport$2 1 funcref))
92+
;; SECONDARY-NEXT: (import "primary" "global" (global $shared-immutable-global i32))
93+
;; SECONDARY-NEXT: (import "primary" "global_5" (global $shared-mutable-global (mut i32)))
8794
;; SECONDARY-NEXT: (import "primary" "keep" (func $keep (exact (param i32) (result i32))))
8895
;; SECONDARY-NEXT: (import "primary" "tag" (tag $shared-tag (type $1) (param i32)))
8996

90-
;; SECONDARY: (global $split-global i32 (i32.const 20))
97+
;; SECONDARY: (global $split-immutable-global i32 (i32.const 20))
98+
;; SECONDARY-NEXT: (global $split-mutable-global (mut i32) (i32.const 20))
9199
;; SECONDARY-NEXT: (memory $split-memory 1 1)
92100
;; SECONDARY-NEXT: (data $split-data (memory $split-memory) (i32.const 0) "a")
93101
;; SECONDARY-NEXT: (table $split-table 1 1 funcref)
@@ -109,9 +117,12 @@
109117
(i32.const 0)
110118
)
111119
)
112-
;; Uses $keep-global
120+
;; Uses $keep-immutable-global and $keep-mutable-global
113121
(drop
114-
(global.get $keep-global)
122+
(global.get $keep-immutable-global)
123+
)
124+
(drop
125+
(global.get $keep-mutable-global)
115126
)
116127
;; Uses $keep-tag
117128
(try_table (catch $keep-tag 0)
@@ -130,9 +141,12 @@
130141
(i32.const 0)
131142
)
132143
)
133-
;; Uses $shared-global
144+
;; Uses $shared-immutable-global and $shared-mutable-global
145+
(drop
146+
(global.get $shared-immutable-global)
147+
)
134148
(drop
135-
(global.get $shared-global)
149+
(global.get $shared-mutable-global)
136150
)
137151
;; Uses $shared-tag
138152
(try_table (catch $shared-tag 0)
@@ -166,9 +180,12 @@
166180
(drop
167181
(table.get $keep-table2 (i32.const 0))
168182
)
169-
;; Uses $split-global
183+
;; Uses $split-immutable-global and $shared-mutable-global
170184
(drop
171-
(global.get $split-global)
185+
(global.get $split-immutable-global)
186+
)
187+
(drop
188+
(global.get $split-mutable-global)
172189
)
173190
;; Uses $split-tag
174191
(try_table (catch $split-tag 0)
@@ -187,9 +204,12 @@
187204
(i32.const 0)
188205
)
189206
)
190-
;; Uses $shared-global
207+
;; Uses $shared-immutable-global and $shared-mutable-global
208+
(drop
209+
(global.get $shared-immutable-global)
210+
)
191211
(drop
192-
(global.get $shared-global)
212+
(global.get $shared-mutable-global)
193213
)
194214
;; Uses $shared-tag
195215
(try_table (catch $shared-tag 0)

test/lit/wasm-split/transitive-globals-multi.wast renamed to test/lit/wasm-split/transitive-immutable-globals-multi.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;; RUN: wasm-split -all -g --multi-split %s --manifest %s.manifest --out-prefix=%t -o %t.wasm
1+
;; RUN: wasm-split -all -g --multi-split %s --manifest %S/transitive-globals-multi.wast.manifest --out-prefix=%t -o %t.wasm
22
;; RUN: wasm-dis -all %t.wasm | filecheck %s --check-prefix PRIMARY
33
;; RUN: wasm-dis -all %t1.wasm | filecheck %s --check-prefix SECONDARY1
44
;; RUN: wasm-dis -all %t2.wasm | filecheck %s --check-prefix SECONDARY2
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
;; RUN: wasm-split -all -g --multi-split %s --manifest %S/transitive-globals-multi.wast.manifest --out-prefix=%t -o %t.wasm
2+
;; RUN: wasm-dis -all %t.wasm | filecheck %s --check-prefix PRIMARY
3+
;; RUN: wasm-dis -all %t1.wasm | filecheck %s --check-prefix SECONDARY1
4+
;; RUN: wasm-dis -all %t2.wasm | filecheck %s --check-prefix SECONDARY2
5+
6+
;; Because global $e is used in both module1 ($split1) and module2 ($split2), $e
7+
;; will be exported / imported, but we don't need to export $f.
8+
9+
(module
10+
(global $f i32 (i32.const 42))
11+
(global $e (mut i32) (global.get $f))
12+
13+
(func $keep
14+
(nop)
15+
)
16+
17+
(func $split1
18+
(drop (global.get $e))
19+
)
20+
21+
(func $split2
22+
(drop (global.get $e))
23+
)
24+
)
25+
26+
;; PRIMARY: (module
27+
;; PRIMARY-NEXT: (type $0 (func))
28+
;; PRIMARY-NEXT: (global $f i32 (i32.const 42))
29+
;; PRIMARY-NEXT: (global $e (mut i32) (global.get $f))
30+
;; PRIMARY-NEXT: (export "global" (global $e))
31+
;; PRIMARY-NEXT: (func $keep (type $0)
32+
;; PRIMARY-NEXT: (nop)
33+
;; PRIMARY-NEXT: )
34+
;; PRIMARY-NEXT: )
35+
36+
;; SECONDARY1: (module
37+
;; SECONDARY1-NEXT: (type $0 (func))
38+
;; SECONDARY1-NEXT: (import "primary" "global" (global $e (mut i32)))
39+
;; SECONDARY1-NEXT: (func $split1 (type $0)
40+
;; SECONDARY1-NEXT: (drop
41+
;; SECONDARY1-NEXT: (global.get $e)
42+
;; SECONDARY1-NEXT: )
43+
;; SECONDARY1-NEXT: )
44+
;; SECONDARY1-NEXT: )
45+
46+
;; SECONDARY2: (module
47+
;; SECONDARY2-NEXT: (type $0 (func))
48+
;; SECONDARY2-NEXT: (import "primary" "global" (global $e (mut i32)))
49+
;; SECONDARY2-NEXT: (func $split2 (type $0)
50+
;; SECONDARY2-NEXT: (drop
51+
;; SECONDARY2-NEXT: (global.get $e)
52+
;; SECONDARY2-NEXT: )
53+
;; SECONDARY2-NEXT: )
54+
;; SECONDARY2-NEXT: )

0 commit comments

Comments
 (0)