From 015d6adba0af8049e13865cb401b82804ab08d6f Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Fri, 28 Aug 2026 07:26:55 +0000 Subject: [PATCH 1/2] [wasm-split] Don't use update_lit_checks.py for some tests `update_lit_checks.py` doesn't always work well with wasm-split. For example, for some tests, the test CHECK lines are mixed like this after running it: ```wast ;; PRIMARY: ... ;; SECONDARY: .... ;; PRIMARY: ... ;; SECONDARY: ... ``` A follow-up PR will change these two test files' CHECK lines to be mixed when using `update_lit_checks.py`, and making them not use in that PR will make it hard to see what actually change in that PR. To make the next PR's diff tidy, this makes a few tests not use the auto-updating script. This also adds `-all` to `transtiive-globals-multi.wast` to be consistent with other `transitive-globals*.wast` tests. --- test/lit/wasm-split/passive-deps.wast | 39 +++++------ .../wasm-split/transitive-globals-multi.wast | 64 ++++++++++--------- test/lit/wasm-split/transitive-globals.wast | 56 ++++++++-------- 3 files changed, 82 insertions(+), 77 deletions(-) diff --git a/test/lit/wasm-split/passive-deps.wast b/test/lit/wasm-split/passive-deps.wast index 9007cb6081a..9c14bb09e98 100644 --- a/test/lit/wasm-split/passive-deps.wast +++ b/test/lit/wasm-split/passive-deps.wast @@ -1,38 +1,39 @@ -;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. ;; RUN: wasm-split %s -all -g -o1 %t.1.wasm -o2 %t.2.wasm --split-funcs=split ;; RUN: wasm-dis -all %t.1.wasm | filecheck %s --check-prefix PRIMARY ;; RUN: wasm-dis -all %t.2.wasm | filecheck %s --check-prefix SECONDARY (module - ;; PRIMARY: (type $0 (func)) - - ;; PRIMARY: (global $g funcref (ref.null nofunc)) (global $g funcref (ref.null nofunc)) ;; We should scan this passive element segment's data and correctly mark $g as ;; used in the primary module. - ;; PRIMARY: (elem $passive-elem funcref (item (global.get $g))) (elem $passive-elem funcref (item (global.get $g))) - ;; PRIMARY: (export "global" (global $g)) - - ;; PRIMARY: (func $keep (type $0) - ;; PRIMARY-NEXT: (elem.drop $passive-elem) - ;; PRIMARY-NEXT: ) (func $keep (elem.drop $passive-elem) ) - ;; SECONDARY: (type $0 (func)) - - ;; SECONDARY: (import "primary" "global" (global $g funcref)) - - ;; SECONDARY: (func $split (type $0) - ;; SECONDARY-NEXT: (drop - ;; SECONDARY-NEXT: (global.get $g) - ;; SECONDARY-NEXT: ) - ;; SECONDARY-NEXT: ) (func $split (drop (global.get $g)) ) ) + +;; PRIMARY: (module +;; PRIMARY-NEXT: (type $0 (func)) +;; PRIMARY-NEXT: (global $g funcref (ref.null nofunc)) +;; PRIMARY-NEXT: (elem $passive-elem funcref (item (global.get $g))) +;; PRIMARY-NEXT: (export "global" (global $g)) +;; PRIMARY-NEXT: (func $keep (type $0) +;; PRIMARY-NEXT: (elem.drop $passive-elem) +;; PRIMARY-NEXT: ) +;; PRIMARY-NEXT: ) + +;; SECONDARY: (module +;; SECONDARY-NEXT: (type $0 (func)) +;; SECONDARY-NEXT: (import "primary" "global" (global $g funcref)) +;; SECONDARY-NEXT: (func $split (type $0) +;; SECONDARY-NEXT: (drop +;; SECONDARY-NEXT: (global.get $g) +;; SECONDARY-NEXT: ) +;; SECONDARY-NEXT: ) +;; SECONDARY-NEXT: ) diff --git a/test/lit/wasm-split/transitive-globals-multi.wast b/test/lit/wasm-split/transitive-globals-multi.wast index f9eda9a7d59..d1d6b73e61e 100644 --- a/test/lit/wasm-split/transitive-globals-multi.wast +++ b/test/lit/wasm-split/transitive-globals-multi.wast @@ -1,52 +1,54 @@ -;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. ;; RUN: wasm-split -all -g --multi-split %s --manifest %s.manifest --out-prefix=%t -o %t.wasm -;; RUN: wasm-dis %t.wasm | filecheck %s --check-prefix PRIMARY -;; RUN: wasm-dis %t1.wasm | filecheck %s --check-prefix SECONDARY1 -;; RUN: wasm-dis %t2.wasm | filecheck %s --check-prefix SECONDARY2 +;; RUN: wasm-dis -all %t.wasm | filecheck %s --check-prefix PRIMARY +;; RUN: wasm-dis -all %t1.wasm | filecheck %s --check-prefix SECONDARY1 +;; RUN: wasm-dis -all %t2.wasm | filecheck %s --check-prefix SECONDARY2 ;; Because global $e is used in both module1 ($split1) and module2 ($split2), $e ;; will be exported / imported, but we don't need to export $f. (module - ;; PRIMARY: (type $0 (func)) - - ;; PRIMARY: (global $f i32 (i32.const 42)) (global $f i32 (i32.const 42)) - ;; PRIMARY: (global $e i32 (global.get $f)) (global $e i32 (global.get $f)) - ;; PRIMARY: (export "global" (global $e)) - - ;; PRIMARY: (func $keep - ;; PRIMARY-NEXT: (nop) - ;; PRIMARY-NEXT: ) (func $keep (nop) ) - ;; SECONDARY1: (type $0 (func)) - - ;; SECONDARY1: (import "primary" "global" (global $e i32)) - - ;; SECONDARY1: (func $split1 - ;; SECONDARY1-NEXT: (drop - ;; SECONDARY1-NEXT: (global.get $e) - ;; SECONDARY1-NEXT: ) - ;; SECONDARY1-NEXT: ) (func $split1 (drop (global.get $e)) ) - ;; SECONDARY2: (type $0 (func)) - - ;; SECONDARY2: (import "primary" "global" (global $e i32)) - - ;; SECONDARY2: (func $split2 - ;; SECONDARY2-NEXT: (drop - ;; SECONDARY2-NEXT: (global.get $e) - ;; SECONDARY2-NEXT: ) - ;; SECONDARY2-NEXT: ) (func $split2 (drop (global.get $e)) ) ) + +;; PRIMARY: (module +;; PRIMARY-NEXT: (type $0 (func)) +;; PRIMARY-NEXT: (global $f i32 (i32.const 42)) +;; PRIMARY-NEXT: (global $e i32 (global.get $f)) +;; PRIMARY-NEXT: (export "global" (global $e)) +;; PRIMARY-NEXT: (func $keep (type $0) +;; PRIMARY-NEXT: (nop) +;; PRIMARY-NEXT: ) +;; PRIMARY-NEXT: ) + +;; SECONDARY1: (module +;; SECONDARY1-NEXT: (type $0 (func)) +;; SECONDARY1-NEXT: (import "primary" "global" (global $e i32)) +;; SECONDARY1-NEXT: (func $split1 (type $0) +;; SECONDARY1-NEXT: (drop +;; SECONDARY1-NEXT: (global.get $e) +;; SECONDARY1-NEXT: ) +;; SECONDARY1-NEXT: ) +;; SECONDARY1-NEXT: ) + +;; SECONDARY2: (module +;; SECONDARY2-NEXT: (type $0 (func)) +;; SECONDARY2-NEXT: (import "primary" "global" (global $e i32)) +;; SECONDARY2-NEXT: (func $split2 (type $0) +;; SECONDARY2-NEXT: (drop +;; SECONDARY2-NEXT: (global.get $e) +;; SECONDARY2-NEXT: ) +;; SECONDARY2-NEXT: ) +;; SECONDARY2-NEXT: ) diff --git a/test/lit/wasm-split/transitive-globals.wast b/test/lit/wasm-split/transitive-globals.wast index a277ec72605..ad702a4363b 100644 --- a/test/lit/wasm-split/transitive-globals.wast +++ b/test/lit/wasm-split/transitive-globals.wast @@ -19,29 +19,10 @@ (global $e i32 (global.get $f)) (global $d i32 (global.get $e)) - ;; PRIMARY: (global $f i32 (i32.const 42)) - ;; PRIMARY: (global $e i32 (global.get $f)) - - ;; PRIMARY: (export "global" (global $e)) - - ;; SECONDARY: (import "primary" "global" (global $e i32)) - - ;; SECONDARY: (global $c i32 (i32.const 42)) - ;; SECONDARY: (global $b i32 (global.get $c)) - ;; SECONDARY: (global $a i32 (global.get $b)) - - ;; SECONDARY: (global $d i32 (global.get $e)) - ;; This dead global is referring to a global ($a) that's moved to the ;; secondary module. This should be deleted. - ;; PRIMARY-NOT: (global (global $dead i32 (global.get $a)) (global $dead i32 (global.get $a)) - ;; PRIMARY: (func $keep - ;; PRIMARY-NEXT: (drop - ;; PRIMARY-NEXT: (global.get $e) - ;; PRIMARY-NEXT: ) - ;; PRIMARY-NEXT: ) (func $keep (drop (global.get $e) @@ -49,14 +30,6 @@ ) ;; Exclusively uses $a and $d, causing them to move to the secondary module - ;; SECONDARY: (func $split - ;; SECONDARY-NEXT: (drop - ;; SECONDARY-NEXT: (global.get $a) - ;; SECONDARY-NEXT: ) - ;; SECONDARY-NEXT: (drop - ;; SECONDARY-NEXT: (global.get $d) - ;; SECONDARY-NEXT: ) - ;; SECONDARY-NEXT: ) (func $split (drop (global.get $a) @@ -66,3 +39,32 @@ ) ) ) + +;; PRIMARY: (module +;; PRIMARY-NEXT: (type $0 (func)) +;; PRIMARY-NEXT: (global $f i32 (i32.const 42)) +;; PRIMARY-NEXT: (global $e i32 (global.get $f)) +;; PRIMARY-NEXT: (export "global" (global $e)) +;; PRIMARY-NEXT: (func $keep +;; PRIMARY-NEXT: (drop +;; PRIMARY-NEXT: (global.get $e) +;; PRIMARY-NEXT: ) +;; PRIMARY-NEXT: ) +;; PRIMARY-NEXT: ) + +;; SECONDARY: (module +;; SECONDARY-NEXT: (type $0 (func)) +;; SECONDARY-NEXT: (import "primary" "global" (global $e i32)) +;; SECONDARY-NEXT: (global $c i32 (i32.const 42)) +;; SECONDARY-NEXT: (global $b i32 (global.get $c)) +;; SECONDARY-NEXT: (global $a i32 (global.get $b)) +;; SECONDARY-NEXT: (global $d i32 (global.get $e)) +;; SECONDARY-NEXT: (func $split +;; SECONDARY-NEXT: (drop +;; SECONDARY-NEXT: (global.get $a) +;; SECONDARY-NEXT: ) +;; SECONDARY-NEXT: (drop +;; SECONDARY-NEXT: (global.get $d) +;; SECONDARY-NEXT: ) +;; SECONDARY-NEXT: ) +;; SECONDARY-NEXT: ) From f86d724b84ef4f5ad3523c8aaec8f9237fdf3286 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Sat, 29 Aug 2026 08:05:59 +0000 Subject: [PATCH 2/2] [wasm-split] Make mutable/immutable versions of tests 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`. --- test/lit/wasm-split/split-module-items.wast | 56 +++++++++++++------ ...> transitive-immutable-globals-multi.wast} | 2 +- .../transitive-mutable-globals-multi.wast | 54 ++++++++++++++++++ 3 files changed, 93 insertions(+), 19 deletions(-) rename test/lit/wasm-split/{transitive-globals-multi.wast => transitive-immutable-globals-multi.wast} (92%) create mode 100644 test/lit/wasm-split/transitive-mutable-globals-multi.wast diff --git a/test/lit/wasm-split/split-module-items.wast b/test/lit/wasm-split/split-module-items.wast index 3816b50ce9b..b4a8b3db881 100644 --- a/test/lit/wasm-split/split-module-items.wast +++ b/test/lit/wasm-split/split-module-items.wast @@ -19,7 +19,8 @@ ;; This is only used in the secondary module, but segments $keep-data2 can trap ;; so it is pinned to the primary, so this will be too. (memory $keep-memory2 1 1) - (global $keep-global i32 (i32.const 20)) + (global $keep-immutable-global i32 (i32.const 20)) + (global $keep-mutable-global (mut i32) (i32.const 20)) (table $keep-table 1 1 funcref) ;; This is only used in the secondary module, but segments $keep-elem2 and ;; $keep-elem3 can trap so they are pinned to the primary, so this will be too. @@ -35,21 +36,25 @@ (data $keep-data2 (memory $keep-memory2) (i32.const 65536) "a") (memory $split-memory 1 1) - (global $split-global i32 (i32.const 20)) + (global $split-immutable-global i32 (i32.const 20)) + (global $split-mutable-global (mut i32) (i32.const 20)) (table $split-table 1 1 funcref) (tag $split-tag (param i32)) (elem $split-elem (table $split-table) (i32.const 0) funcref (item (ref.null nofunc))) (data $split-data (memory $split-memory) (i32.const 0) "a") (memory $shared-memory 1 1) - (global $shared-global i32 (i32.const 20)) + (global $shared-immutable-global i32 (i32.const 20)) + (global $shared-mutable-global (mut i32) (i32.const 20)) (table $shared-table 1 1 funcref) (tag $shared-tag (param i32)) (elem $shared-elem (table $shared-table) (i32.const 0) funcref (item (ref.null nofunc))) (data $shared-data (memory $shared-memory) (i32.const 0) "a") - ;; PRIMARY: (global $keep-global i32 (i32.const 20)) - ;; PRIMARY-NEXT: (global $shared-global i32 (i32.const 20)) + ;; PRIMARY: (global $keep-immutable-global i32 (i32.const 20)) + ;; PRIMARY-NEXT: (global $keep-mutable-global (mut i32) (i32.const 20)) + ;; PRIMARY-NEXT: (global $shared-immutable-global i32 (i32.const 20)) + ;; PRIMARY-NEXT: (global $shared-mutable-global (mut i32) (i32.const 20)) ;; PRIMARY-NEXT: (memory $keep-memory 1 1) ;; PRIMARY-NEXT: (memory $keep-memory2 1 1) ;; PRIMARY-NEXT: (memory $shared-memory 1 1) @@ -73,21 +78,24 @@ ;; PRIMARY-NEXT: (export "memory_1" (memory $shared-memory)) ;; PRIMARY-NEXT: (export "table" (table $keep-table2)) ;; PRIMARY-NEXT: (export "table_3" (table $shared-table)) - ;; PRIMARY-NEXT: (export "global" (global $shared-global)) + ;; PRIMARY-NEXT: (export "global" (global $shared-immutable-global)) + ;; PRIMARY-NEXT: (export "global_5" (global $shared-mutable-global)) ;; PRIMARY-NEXT: (export "tag" (tag $shared-tag)) ;; PRIMARY-NEXT: (export "keep" (func $keep)) - ;; PRIMARY-NEXT: (export "table_7" (table $3)) + ;; PRIMARY-NEXT: (export "table_8" (table $3)) ;; SECONDARY: (import "primary" "memory" (memory $keep-memory2 1 1)) ;; SECONDARY-NEXT: (import "primary" "memory_1" (memory $shared-memory 1 1)) ;; SECONDARY-NEXT: (import "primary" "table" (table $keep-table2 1 1 (ref null $2))) ;; SECONDARY-NEXT: (import "primary" "table_3" (table $shared-table 1 1 funcref)) - ;; SECONDARY-NEXT: (import "primary" "table_7" (table $timport$2 1 funcref)) - ;; SECONDARY-NEXT: (import "primary" "global" (global $shared-global i32)) + ;; SECONDARY-NEXT: (import "primary" "table_8" (table $timport$2 1 funcref)) + ;; SECONDARY-NEXT: (import "primary" "global" (global $shared-immutable-global i32)) + ;; SECONDARY-NEXT: (import "primary" "global_5" (global $shared-mutable-global (mut i32))) ;; SECONDARY-NEXT: (import "primary" "keep" (func $keep (exact (param i32) (result i32)))) ;; SECONDARY-NEXT: (import "primary" "tag" (tag $shared-tag (type $1) (param i32))) - ;; SECONDARY: (global $split-global i32 (i32.const 20)) + ;; SECONDARY: (global $split-immutable-global i32 (i32.const 20)) + ;; SECONDARY-NEXT: (global $split-mutable-global (mut i32) (i32.const 20)) ;; SECONDARY-NEXT: (memory $split-memory 1 1) ;; SECONDARY-NEXT: (data $split-data (memory $split-memory) (i32.const 0) "a") ;; SECONDARY-NEXT: (table $split-table 1 1 funcref) @@ -109,9 +117,12 @@ (i32.const 0) ) ) - ;; Uses $keep-global + ;; Uses $keep-immutable-global and $keep-mutable-global (drop - (global.get $keep-global) + (global.get $keep-immutable-global) + ) + (drop + (global.get $keep-mutable-global) ) ;; Uses $keep-tag (try_table (catch $keep-tag 0) @@ -130,9 +141,12 @@ (i32.const 0) ) ) - ;; Uses $shared-global + ;; Uses $shared-immutable-global and $shared-mutable-global + (drop + (global.get $shared-immutable-global) + ) (drop - (global.get $shared-global) + (global.get $shared-mutable-global) ) ;; Uses $shared-tag (try_table (catch $shared-tag 0) @@ -166,9 +180,12 @@ (drop (table.get $keep-table2 (i32.const 0)) ) - ;; Uses $split-global + ;; Uses $split-immutable-global and $shared-mutable-global (drop - (global.get $split-global) + (global.get $split-immutable-global) + ) + (drop + (global.get $split-mutable-global) ) ;; Uses $split-tag (try_table (catch $split-tag 0) @@ -187,9 +204,12 @@ (i32.const 0) ) ) - ;; Uses $shared-global + ;; Uses $shared-immutable-global and $shared-mutable-global + (drop + (global.get $shared-immutable-global) + ) (drop - (global.get $shared-global) + (global.get $shared-mutable-global) ) ;; Uses $shared-tag (try_table (catch $shared-tag 0) diff --git a/test/lit/wasm-split/transitive-globals-multi.wast b/test/lit/wasm-split/transitive-immutable-globals-multi.wast similarity index 92% rename from test/lit/wasm-split/transitive-globals-multi.wast rename to test/lit/wasm-split/transitive-immutable-globals-multi.wast index d1d6b73e61e..3f2cb97c392 100644 --- a/test/lit/wasm-split/transitive-globals-multi.wast +++ b/test/lit/wasm-split/transitive-immutable-globals-multi.wast @@ -1,4 +1,4 @@ -;; RUN: wasm-split -all -g --multi-split %s --manifest %s.manifest --out-prefix=%t -o %t.wasm +;; RUN: wasm-split -all -g --multi-split %s --manifest %S/transitive-globals-multi.wast.manifest --out-prefix=%t -o %t.wasm ;; RUN: wasm-dis -all %t.wasm | filecheck %s --check-prefix PRIMARY ;; RUN: wasm-dis -all %t1.wasm | filecheck %s --check-prefix SECONDARY1 ;; RUN: wasm-dis -all %t2.wasm | filecheck %s --check-prefix SECONDARY2 diff --git a/test/lit/wasm-split/transitive-mutable-globals-multi.wast b/test/lit/wasm-split/transitive-mutable-globals-multi.wast new file mode 100644 index 00000000000..1b297267fd0 --- /dev/null +++ b/test/lit/wasm-split/transitive-mutable-globals-multi.wast @@ -0,0 +1,54 @@ +;; RUN: wasm-split -all -g --multi-split %s --manifest %S/transitive-globals-multi.wast.manifest --out-prefix=%t -o %t.wasm +;; RUN: wasm-dis -all %t.wasm | filecheck %s --check-prefix PRIMARY +;; RUN: wasm-dis -all %t1.wasm | filecheck %s --check-prefix SECONDARY1 +;; RUN: wasm-dis -all %t2.wasm | filecheck %s --check-prefix SECONDARY2 + +;; Because global $e is used in both module1 ($split1) and module2 ($split2), $e +;; will be exported / imported, but we don't need to export $f. + +(module + (global $f i32 (i32.const 42)) + (global $e (mut i32) (global.get $f)) + + (func $keep + (nop) + ) + + (func $split1 + (drop (global.get $e)) + ) + + (func $split2 + (drop (global.get $e)) + ) +) + +;; PRIMARY: (module +;; PRIMARY-NEXT: (type $0 (func)) +;; PRIMARY-NEXT: (global $f i32 (i32.const 42)) +;; PRIMARY-NEXT: (global $e (mut i32) (global.get $f)) +;; PRIMARY-NEXT: (export "global" (global $e)) +;; PRIMARY-NEXT: (func $keep (type $0) +;; PRIMARY-NEXT: (nop) +;; PRIMARY-NEXT: ) +;; PRIMARY-NEXT: ) + +;; SECONDARY1: (module +;; SECONDARY1-NEXT: (type $0 (func)) +;; SECONDARY1-NEXT: (import "primary" "global" (global $e (mut i32))) +;; SECONDARY1-NEXT: (func $split1 (type $0) +;; SECONDARY1-NEXT: (drop +;; SECONDARY1-NEXT: (global.get $e) +;; SECONDARY1-NEXT: ) +;; SECONDARY1-NEXT: ) +;; SECONDARY1-NEXT: ) + +;; SECONDARY2: (module +;; SECONDARY2-NEXT: (type $0 (func)) +;; SECONDARY2-NEXT: (import "primary" "global" (global $e (mut i32))) +;; SECONDARY2-NEXT: (func $split2 (type $0) +;; SECONDARY2-NEXT: (drop +;; SECONDARY2-NEXT: (global.get $e) +;; SECONDARY2-NEXT: ) +;; SECONDARY2-NEXT: ) +;; SECONDARY2-NEXT: )