diff options
author | Alon Zakai <azakai@google.com> | 2023-09-21 12:28:23 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-21 12:28:23 -0700 |
commit | ec0f05cb98d6a4e30375a7a6a78966d25fdb5d9c (patch) | |
tree | d1c86dc6b1759f231f7d9f51c9a4493f74542859 /test | |
parent | a35af4b1e9461b12fd7993b4fd249bd39d73945d (diff) | |
download | binaryen-ec0f05cb98d6a4e30375a7a6a78966d25fdb5d9c.tar.gz binaryen-ec0f05cb98d6a4e30375a7a6a78966d25fdb5d9c.tar.bz2 binaryen-ec0f05cb98d6a4e30375a7a6a78966d25fdb5d9c.zip |
Support i8/i16 mutable arrays as public types for string interop (#5814)
Probably any array of non-reference data can be allowed to be public and sent
out of the module, as it is just data. For now, however, just special case the i8
and i16 array types which are useful already for string interop.
Diffstat (limited to 'test')
-rw-r--r-- | test/lit/passes/gto-mutability.wast | 63 | ||||
-rw-r--r-- | test/lit/passes/type-merging.wast | 6 | ||||
-rw-r--r-- | test/lit/validation/closed-world-interface.wast | 4 |
3 files changed, 68 insertions, 5 deletions
diff --git a/test/lit/passes/gto-mutability.wast b/test/lit/passes/gto-mutability.wast index 28fc1bc69..ed04edccc 100644 --- a/test/lit/passes/gto-mutability.wast +++ b/test/lit/passes/gto-mutability.wast @@ -589,3 +589,66 @@ (drop (struct.get $sub 0 (local.get $sub))) ) ) + +;; This pass does not refine array types yet. Verify that we do not. This is +;; particularly important for array of i8 and i6, which we special-case as they +;; are used for string interop even in closed world. For now, however, we do not +;; optimize even arrays of i32. +;; +;; Nothing should change in these array types. They have no writes, but they'll +;; stay mutable. Also, this test verifies that we can even validate this module +;; in closed world, even though it contains imports of i8 and i16 arrays. +;; +;; The test also verifies that while we refine the mutability of a struct type, +;; which causes us to rewrite types, that we keep the i8 and i16 arrays in +;; their own size-1 rec groups by themselves, unmodified. The i32 array will be +;; moved into a new big rec group, together with the struct type (that is also +;; refined to be immutable). +(module + ;; CHECK: (type $array8 (array (mut i8))) + (type $array8 (array (mut i8))) + ;; CHECK: (type $array16 (array (mut i16))) + (type $array16 (array (mut i16))) + ;; CHECK: (rec + ;; CHECK-NEXT: (type $struct (struct (field funcref))) + + ;; CHECK: (type $array32 (array (mut i32))) + (type $array32 (array (mut i32))) + + (type $struct (struct (field (mut funcref)))) + + ;; CHECK: (type $4 (func (param funcref))) + + ;; CHECK: (import "a" "b" (global $i8 (ref $array8))) + (import "a" "b" (global $i8 (ref $array8))) + + ;; CHECK: (import "a" "c" (global $i16 (ref $array16))) + (import "a" "c" (global $i16 (ref $array16))) + + ;; CHECK: (func $use (type $4) (param $funcref funcref) + ;; CHECK-NEXT: (local $array8 (ref $array8)) + ;; CHECK-NEXT: (local $array16 (ref $array16)) + ;; CHECK-NEXT: (local $array32 (ref $array32)) + ;; CHECK-NEXT: (local $struct (ref $struct)) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (struct.get $struct 0 + ;; CHECK-NEXT: (struct.new $struct + ;; CHECK-NEXT: (local.get $funcref) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $use (param $funcref funcref) + (local $array8 (ref $array8)) + (local $array16 (ref $array16)) + (local $array32 (ref $array32)) + (local $struct (ref $struct)) + (drop + (struct.get $struct 0 + (struct.new $struct + (local.get $funcref) + ) + ) + ) + ) +) diff --git a/test/lit/passes/type-merging.wast b/test/lit/passes/type-merging.wast index 643e28bd9..7c44fe8e2 100644 --- a/test/lit/passes/type-merging.wast +++ b/test/lit/passes/type-merging.wast @@ -388,17 +388,17 @@ ;; CHECK: (type $C (array i16)) - ;; CHECK: (type $B (array (mut i8))) + ;; CHECK: (type $B (array (mut i32))) ;; CHECK: (type $A (array i8)) (type $A (array i8)) (type $A' (array i8)) - (type $B (array (mut i8))) - (type $B' (array (mut i8))) (type $C (array i16)) (type $C' (array i16)) (type $D (array i32)) (type $D' (array i32)) + (type $B (array (mut i32))) + (type $B' (array (mut i32))) (type $E (array i64)) (type $E' (array i64)) (type $F (array anyref)) diff --git a/test/lit/validation/closed-world-interface.wast b/test/lit/validation/closed-world-interface.wast index f5dd7ad46..06cf1cef7 100644 --- a/test/lit/validation/closed-world-interface.wast +++ b/test/lit/validation/closed-world-interface.wast @@ -9,7 +9,7 @@ ;; This is pulled in by a global. ;; CHECK: publicly exposed type disallowed with a closed world: $array, on -;; CHECK-NEXT: (array (mut i8)) +;; CHECK-NEXT: (array (mut i32)) ;; This is pulled in only by a global, so it is disallowed even though it is a function type. ;; CHECK: publicly exposed type disallowed with a closed world: $private, on @@ -21,7 +21,7 @@ (module (type $struct (struct)) - (type $array (array (mut i8))) + (type $array (array (mut i32))) (type $void (func)) (type $abstract (func (param anyref))) |