summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-12-14 13:58:12 -0800
committerGitHub <noreply@github.com>2021-12-14 13:58:12 -0800
commit01e6429a13abd2d8f5b3d4019a273e992fdd3a66 (patch)
tree4437eb47d7c6e3cb5c9b63a857e7cbff60212656 /test
parente5594bbde36ac96b6f2a41259d8a8d66e5d0a7cc (diff)
downloadbinaryen-01e6429a13abd2d8f5b3d4019a273e992fdd3a66.tar.gz
binaryen-01e6429a13abd2d8f5b3d4019a273e992fdd3a66.tar.bz2
binaryen-01e6429a13abd2d8f5b3d4019a273e992fdd3a66.zip
[Wasm GC] Refine results in SignatureRefining (#4380)
Similar to what DeadArgumentElimination does for individual functions, this can refine the results of a set of functions all using the same heap type, when they all return something more specific. After this PR SignatureRefining can refine both params and results and is basically complete.
Diffstat (limited to 'test')
-rw-r--r--test/lit/passes/signature-refining.wast134
1 files changed, 134 insertions, 0 deletions
diff --git a/test/lit/passes/signature-refining.wast b/test/lit/passes/signature-refining.wast
index 71eec54b2..fcffcc550 100644
--- a/test/lit/passes/signature-refining.wast
+++ b/test/lit/passes/signature-refining.wast
@@ -490,3 +490,137 @@
)
)
)
+
+(module
+ ;; CHECK: (type $struct (struct_subtype data))
+ (type $struct (struct_subtype data))
+
+ ;; This signature has a single function using it, which returns a more
+ ;; refined type, and we can refine to that.
+ ;; CHECK: (type $sig-can-refine (func_subtype (result (ref $struct)) func))
+ (type $sig-can-refine (func_subtype (result anyref) func))
+
+ ;; Also a single function, but no refinement is possible.
+ ;; CHECK: (type $sig-cannot-refine (func_subtype (result anyref) func))
+ (type $sig-cannot-refine (func_subtype (result anyref) func))
+
+ ;; The single function never returns, so no refinement is possible.
+ ;; CHECK: (type $sig-unreachable (func_subtype (result anyref) func))
+ (type $sig-unreachable (func_subtype (result anyref) func))
+
+ ;; CHECK: (type $none_=>_none (func_subtype func))
+
+ ;; CHECK: (elem declare func $func-can-refine)
+
+ ;; CHECK: (func $func-can-refine (type $sig-can-refine) (result (ref $struct))
+ ;; CHECK-NEXT: (struct.new_default $struct)
+ ;; CHECK-NEXT: )
+ (func $func-can-refine (type $sig-can-refine) (result anyref)
+ (struct.new $struct)
+ )
+
+ ;; CHECK: (func $func-cannot-refine (type $sig-cannot-refine) (result anyref)
+ ;; CHECK-NEXT: (ref.null any)
+ ;; CHECK-NEXT: )
+ (func $func-cannot-refine (type $sig-cannot-refine) (result anyref)
+ (ref.null any)
+ )
+
+ ;; CHECK: (func $func-unreachable (type $sig-unreachable) (result anyref)
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ (func $func-unreachable (type $sig-unreachable) (result anyref)
+ (unreachable)
+ )
+
+ ;; CHECK: (func $caller (type $none_=>_none)
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (if (result (ref $struct))
+ ;; CHECK-NEXT: (i32.const 1)
+ ;; CHECK-NEXT: (call $func-can-refine)
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (if (result (ref $struct))
+ ;; CHECK-NEXT: (i32.const 1)
+ ;; CHECK-NEXT: (call_ref
+ ;; CHECK-NEXT: (ref.func $func-can-refine)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $caller
+ ;; Add a call to see that we update call types properly.
+ ;; Put the call in an if so the refinalize will update the if type and get
+ ;; printed out conveniently.
+ (drop
+ (if (result anyref)
+ (i32.const 1)
+ (call $func-can-refine)
+ (unreachable)
+ )
+ )
+ ;; The same with a call_ref.
+ (drop
+ (if (result anyref)
+ (i32.const 1)
+ (call_ref
+ (ref.func $func-can-refine)
+ )
+ (unreachable)
+ )
+ )
+ )
+)
+
+(module
+ ;; CHECK: (type $struct (struct_subtype data))
+ (type $struct (struct_subtype data))
+
+ ;; This signature has multiple functions using it, and some of them have nulls
+ ;; which should be updated when we refine.
+ ;; CHECK: (type $sig (func_subtype (result (ref null $struct)) func))
+ (type $sig (func_subtype (result anyref) func))
+
+ ;; CHECK: (func $func-1 (type $sig) (result (ref null $struct))
+ ;; CHECK-NEXT: (struct.new_default $struct)
+ ;; CHECK-NEXT: )
+ (func $func-1 (type $sig) (result anyref)
+ (struct.new $struct)
+ )
+
+ ;; CHECK: (func $func-2 (type $sig) (result (ref null $struct))
+ ;; CHECK-NEXT: (ref.null $struct)
+ ;; CHECK-NEXT: )
+ (func $func-2 (type $sig) (result anyref)
+ (ref.null any)
+ )
+
+ ;; CHECK: (func $func-3 (type $sig) (result (ref null $struct))
+ ;; CHECK-NEXT: (ref.null $struct)
+ ;; CHECK-NEXT: )
+ (func $func-3 (type $sig) (result anyref)
+ (ref.null eq)
+ )
+
+ ;; CHECK: (func $func-4 (type $sig) (result (ref null $struct))
+ ;; CHECK-NEXT: (if
+ ;; CHECK-NEXT: (i32.const 1)
+ ;; CHECK-NEXT: (return
+ ;; CHECK-NEXT: (ref.null $struct)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ (func $func-4 (type $sig) (result anyref)
+ (if
+ (i32.const 1)
+ (return
+ (ref.null any)
+ )
+ )
+ (unreachable)
+ )
+)