summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/lit/help/wasm-metadce.test3
-rw-r--r--test/lit/help/wasm-opt.test3
-rw-r--r--test/lit/help/wasm2js.test3
-rw-r--r--test/lit/passes/enclose-world.wast237
-rw-r--r--test/passes/fuzz_metrics_passes_noprint.bin.txt58
-rw-r--r--test/passes/translate-to-fuzz_all-features_metrics_noprint.txt72
6 files changed, 314 insertions, 62 deletions
diff --git a/test/lit/help/wasm-metadce.test b/test/lit/help/wasm-metadce.test
index 4dc03883a..e44e51a16 100644
--- a/test/lit/help/wasm-metadce.test
+++ b/test/lit/help/wasm-metadce.test
@@ -143,6 +143,9 @@
;; CHECK-NEXT: --emit-target-features emit the target features section
;; CHECK-NEXT: in the output
;; CHECK-NEXT:
+;; CHECK-NEXT: --enclose-world modify the wasm (destructively)
+;; CHECK-NEXT: for closed-world
+;; CHECK-NEXT:
;; CHECK-NEXT: --extract-function leaves just one function (useful
;; CHECK-NEXT: for debugging)
;; CHECK-NEXT:
diff --git a/test/lit/help/wasm-opt.test b/test/lit/help/wasm-opt.test
index 62a30a770..5c978ee81 100644
--- a/test/lit/help/wasm-opt.test
+++ b/test/lit/help/wasm-opt.test
@@ -152,6 +152,9 @@
;; CHECK-NEXT: --emit-target-features emit the target features section
;; CHECK-NEXT: in the output
;; CHECK-NEXT:
+;; CHECK-NEXT: --enclose-world modify the wasm (destructively)
+;; CHECK-NEXT: for closed-world
+;; CHECK-NEXT:
;; CHECK-NEXT: --extract-function leaves just one function (useful
;; CHECK-NEXT: for debugging)
;; CHECK-NEXT:
diff --git a/test/lit/help/wasm2js.test b/test/lit/help/wasm2js.test
index e2a450bc8..c1dd0401d 100644
--- a/test/lit/help/wasm2js.test
+++ b/test/lit/help/wasm2js.test
@@ -106,6 +106,9 @@
;; CHECK-NEXT: --emit-target-features emit the target features section
;; CHECK-NEXT: in the output
;; CHECK-NEXT:
+;; CHECK-NEXT: --enclose-world modify the wasm (destructively)
+;; CHECK-NEXT: for closed-world
+;; CHECK-NEXT:
;; CHECK-NEXT: --extract-function leaves just one function (useful
;; CHECK-NEXT: for debugging)
;; CHECK-NEXT:
diff --git a/test/lit/passes/enclose-world.wast b/test/lit/passes/enclose-world.wast
new file mode 100644
index 000000000..0077c27be
--- /dev/null
+++ b/test/lit/passes/enclose-world.wast
@@ -0,0 +1,237 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
+
+;; RUN: foreach %s %t wasm-opt --enclose-world -all -S -o - | filecheck %s
+
+(module
+ ;; CHECK: (type $A (struct))
+ (type $A (struct))
+ ;; CHECK: (type $B (struct (field i32)))
+ (type $B (struct (field i32)))
+ ;; CHECK: (type $2 (func (param externref)))
+
+ ;; CHECK: (type $3 (func (result externref)))
+
+ ;; CHECK: (type $4 (func (param anyref) (result anyref)))
+
+ ;; CHECK: (type $5 (func (param externref) (result externref)))
+
+ ;; CHECK: (type $C (struct (field i32) (field f64)))
+ (type $C (struct (field i32 f64)))
+
+ ;; CHECK: (type $7 (func (param i32) (result f64)))
+
+ ;; CHECK: (type $8 (func (param anyref)))
+
+ ;; CHECK: (type $9 (func (result anyref)))
+
+ ;; CHECK: (type $10 (func (param (ref $A) (ref null $B)) (result (ref $C))))
+
+ ;; CHECK: (type $11 (func (param i32 (ref $A) funcref)))
+
+ ;; CHECK: (type $12 (func (param externref externref) (result externref)))
+
+ ;; CHECK: (type $13 (func (param i32 externref funcref)))
+
+ ;; CHECK: (export "normal" (func $normal))
+
+ ;; CHECK: (export "externref-param" (func $externref-param))
+
+ ;; CHECK: (export "externref-result" (func $externref-result))
+
+ ;; CHECK: (export "anyref-param" (func $stub$anyref-param))
+
+ ;; CHECK: (export "anyref-result" (func $stub$anyref-result))
+
+ ;; CHECK: (export "anyref-both" (func $stub$anyref-both))
+
+ ;; CHECK: (export "anyref-both-dupe" (func $stub$anyref-both-dupe))
+
+ ;; CHECK: (export "many" (func $stub$many))
+
+ ;; CHECK: (export "mixed" (func $stub$mixed))
+
+ ;; CHECK: (func $normal (type $7) (param $x i32) (result f64)
+ ;; CHECK-NEXT: (f64.const 3.14159)
+ ;; CHECK-NEXT: )
+ (func $normal (export "normal") (param $x i32) (result f64)
+ ;; A normal function which we do not need to do anything with.
+ (f64.const 3.14159)
+ )
+
+ ;; CHECK: (func $externref-param (type $2) (param $x externref)
+ ;; CHECK-NEXT: )
+ (func $externref-param (export "externref-param") (param $x externref)
+ ;; An externref param is fine, we don't need to do anything.
+ )
+
+ ;; CHECK: (func $externref-result (type $3) (result externref)
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ (func $externref-result (export "externref-result") (result externref)
+ ;; An externref result is also fine.
+ (unreachable)
+ )
+
+ ;; CHECK: (func $anyref-param (type $8) (param $x anyref)
+ ;; CHECK-NEXT: )
+ (func $anyref-param (export "anyref-param") (param $x anyref)
+ ;; An anyref requires a fixup. We will call this from a stub that has an
+ ;; externref param, which calls this.
+ )
+
+ ;; CHECK: (func $anyref-result (type $9) (result anyref)
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ (func $anyref-result (export "anyref-result") (result anyref)
+ ;; An anyref result also requires a fixup.
+ (unreachable)
+ )
+
+ ;; CHECK: (func $anyref-both (type $4) (param $x anyref) (result anyref)
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ (func $anyref-both (export "anyref-both") (param $x anyref) (result anyref)
+ ;; Here we must fix up both the param and the result.
+ (unreachable)
+ )
+
+ ;; CHECK: (func $anyref-both-dupe (type $4) (param $x anyref) (result anyref)
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ (func $anyref-both-dupe (export "anyref-both-dupe") (param $x anyref) (result anyref)
+ ;; Identical to the above function, and should be fixed up in the same
+ ;; manner. In theory we could use the same stub for both, but we leave that
+ ;; for the optimizer.
+ (unreachable)
+ )
+
+ ;; CHECK: (func $many (type $10) (param $a (ref $A)) (param $b (ref null $B)) (result (ref $C))
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ (func $many (export "many") (param $a (ref $A)) (param $b (ref null $B)) (result (ref $C))
+ ;; Various declared types are used, and must be fixed up.
+ (unreachable)
+ )
+
+ ;; CHECK: (func $mixed (type $11) (param $a i32) (param $b (ref $A)) (param $c funcref)
+ ;; CHECK-NEXT: )
+ (func $mixed (export "mixed") (param $a i32) (param $b (ref $A)) (param $c funcref)
+ ;; One param needs to be fixed, two others do not: we can ignore i32 and
+ ;; funcref.
+ )
+)
+
+;; CHECK: (func $stub$anyref-param (type $2) (param $0 externref)
+;; CHECK-NEXT: (call $anyref-param
+;; CHECK-NEXT: (ref.cast anyref
+;; CHECK-NEXT: (any.convert_extern
+;; CHECK-NEXT: (local.get $0)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+
+;; CHECK: (func $stub$anyref-result (type $3) (result externref)
+;; CHECK-NEXT: (extern.convert_any
+;; CHECK-NEXT: (call $anyref-result)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+
+;; CHECK: (func $stub$anyref-both (type $5) (param $0 externref) (result externref)
+;; CHECK-NEXT: (extern.convert_any
+;; CHECK-NEXT: (call $anyref-both
+;; CHECK-NEXT: (ref.cast anyref
+;; CHECK-NEXT: (any.convert_extern
+;; CHECK-NEXT: (local.get $0)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+
+;; CHECK: (func $stub$anyref-both-dupe (type $5) (param $0 externref) (result externref)
+;; CHECK-NEXT: (extern.convert_any
+;; CHECK-NEXT: (call $anyref-both-dupe
+;; CHECK-NEXT: (ref.cast anyref
+;; CHECK-NEXT: (any.convert_extern
+;; CHECK-NEXT: (local.get $0)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+
+;; CHECK: (func $stub$many (type $12) (param $0 externref) (param $1 externref) (result externref)
+;; CHECK-NEXT: (extern.convert_any
+;; CHECK-NEXT: (call $many
+;; CHECK-NEXT: (ref.cast (ref $A)
+;; CHECK-NEXT: (any.convert_extern
+;; CHECK-NEXT: (local.get $0)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: (ref.cast (ref null $B)
+;; CHECK-NEXT: (any.convert_extern
+;; CHECK-NEXT: (local.get $1)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+
+;; CHECK: (func $stub$mixed (type $13) (param $0 i32) (param $1 externref) (param $2 funcref)
+;; CHECK-NEXT: (call $mixed
+;; CHECK-NEXT: (local.get $0)
+;; CHECK-NEXT: (ref.cast (ref $A)
+;; CHECK-NEXT: (any.convert_extern
+;; CHECK-NEXT: (local.get $1)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: (local.get $2)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+(module
+ ;; Two exports of a single function that needs fixups. We could reuse a
+ ;; single stub, but we leave that for the optimizer.
+
+ (export "a" (func $anyref-both))
+
+ (export "b" (func $anyref-both))
+
+ ;; CHECK: (type $0 (func (param externref) (result externref)))
+
+ ;; CHECK: (type $1 (func (param anyref) (result anyref)))
+
+ ;; CHECK: (export "a" (func $stub$anyref-both))
+
+ ;; CHECK: (export "b" (func $stub$anyref-both_2))
+
+ ;; CHECK: (func $anyref-both (type $1) (param $x anyref) (result anyref)
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ (func $anyref-both (param $x anyref) (result anyref)
+ (unreachable)
+ )
+)
+;; CHECK: (func $stub$anyref-both (type $0) (param $0 externref) (result externref)
+;; CHECK-NEXT: (extern.convert_any
+;; CHECK-NEXT: (call $anyref-both
+;; CHECK-NEXT: (ref.cast anyref
+;; CHECK-NEXT: (any.convert_extern
+;; CHECK-NEXT: (local.get $0)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+
+;; CHECK: (func $stub$anyref-both_2 (type $0) (param $0 externref) (result externref)
+;; CHECK-NEXT: (extern.convert_any
+;; CHECK-NEXT: (call $anyref-both
+;; CHECK-NEXT: (ref.cast anyref
+;; CHECK-NEXT: (any.convert_extern
+;; CHECK-NEXT: (local.get $0)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
diff --git a/test/passes/fuzz_metrics_passes_noprint.bin.txt b/test/passes/fuzz_metrics_passes_noprint.bin.txt
index b4d67bab0..5e0dbfe07 100644
--- a/test/passes/fuzz_metrics_passes_noprint.bin.txt
+++ b/test/passes/fuzz_metrics_passes_noprint.bin.txt
@@ -1,35 +1,35 @@
Metrics
total
- [exports] : 23
- [funcs] : 34
- [globals] : 30
+ [exports] : 50
+ [funcs] : 64
+ [globals] : 24
[imports] : 5
[memories] : 1
- [memory-data] : 17
- [table-data] : 6
+ [memory-data] : 15
+ [table-data] : 16
[tables] : 1
[tags] : 0
- [total] : 9415
- [vars] : 105
- Binary : 726
- Block : 1537
- Break : 331
- Call : 306
- CallIndirect : 10
- Const : 1479
- Drop : 83
- GlobalGet : 778
- GlobalSet : 584
- If : 531
- Load : 164
- LocalGet : 774
- LocalSet : 570
- Loop : 244
- Nop : 105
- RefFunc : 6
- Return : 94
- Select : 70
- Store : 86
- Switch : 2
- Unary : 654
- Unreachable : 281
+ [total] : 6973
+ [vars] : 223
+ Binary : 534
+ Block : 1168
+ Break : 228
+ Call : 282
+ CallIndirect : 38
+ Const : 1083
+ Drop : 115
+ GlobalGet : 580
+ GlobalSet : 444
+ If : 354
+ Load : 113
+ LocalGet : 501
+ LocalSet : 367
+ Loop : 148
+ Nop : 99
+ RefFunc : 16
+ Return : 91
+ Select : 53
+ Store : 70
+ Switch : 1
+ Unary : 466
+ Unreachable : 222
diff --git a/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt b/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
index a77708b2e..8df9d033c 100644
--- a/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
+++ b/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
@@ -1,48 +1,54 @@
Metrics
total
- [exports] : 6
- [funcs] : 12
+ [exports] : 9
+ [funcs] : 10
[globals] : 4
[imports] : 8
[memories] : 1
[memory-data] : 112
- [table-data] : 3
+ [table-data] : 2
[tables] : 1
- [tags] : 0
- [total] : 608
- [vars] : 48
- ArrayNew : 5
+ [tags] : 1
+ [total] : 682
+ [vars] : 37
+ ArrayLen : 1
+ ArrayNew : 7
ArrayNewFixed : 5
- Binary : 75
- Block : 80
- BrOn : 5
- Break : 4
- Call : 21
- CallRef : 1
- Const : 113
+ ArraySet : 1
+ AtomicNotify : 1
+ Binary : 79
+ Block : 72
+ BrOn : 4
+ Break : 7
+ Call : 19
+ Const : 149
Drop : 15
- GlobalGet : 39
- GlobalSet : 36
- If : 21
- Load : 17
- LocalGet : 45
- LocalSet : 20
+ GlobalGet : 35
+ GlobalSet : 32
+ If : 20
+ Load : 20
+ LocalGet : 55
+ LocalSet : 26
Loop : 7
- Nop : 7
- RefAs : 2
+ MemoryFill : 1
+ Nop : 9
+ Pop : 1
+ RefAs : 1
+ RefCast : 1
RefEq : 1
- RefFunc : 9
- RefI31 : 1
- RefIsNull : 1
+ RefFunc : 17
+ RefI31 : 2
+ RefIsNull : 2
RefNull : 8
Return : 5
- Select : 2
+ SIMDExtract : 3
Store : 1
- StringConst : 4
- StringEq : 1
- StringMeasure : 2
- StructNew : 13
- TupleExtract : 1
+ StringConst : 3
+ StringMeasure : 1
+ StringWTF16Get : 1
+ StructNew : 23
+ Try : 1
+ TupleExtract : 3
TupleMake : 4
- Unary : 19
- Unreachable : 18
+ Unary : 23
+ Unreachable : 16