diff options
author | Alon Zakai <azakai@google.com> | 2021-03-09 11:57:23 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-09 11:57:23 -0800 |
commit | a1d3e63f89e9d13daabf626033a66fe5b8a8bce1 (patch) | |
tree | 9aabb7bdfa5645c31323ffea2051db7f3645653d | |
parent | afc5fbd51759c07492fec4cae86d7e9484547626 (diff) | |
download | binaryen-a1d3e63f89e9d13daabf626033a66fe5b8a8bce1.tar.gz binaryen-a1d3e63f89e9d13daabf626033a66fe5b8a8bce1.tar.bz2 binaryen-a1d3e63f89e9d13daabf626033a66fe5b8a8bce1.zip |
[Wasm GC] Allow set values to be subtypes (#3665)
-rw-r--r-- | src/wasm/wasm-validator.cpp | 16 | ||||
-rw-r--r-- | test/heap-types.wast | 16 | ||||
-rw-r--r-- | test/heap-types.wast.from-wast | 15 | ||||
-rw-r--r-- | test/heap-types.wast.fromBinary | 15 | ||||
-rw-r--r-- | test/heap-types.wast.fromBinary.noDebugInfo | 15 |
5 files changed, 62 insertions, 15 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 656c5e832..70a9ad90f 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -2423,10 +2423,10 @@ void FunctionValidator::visitStructSet(StructSet* curr) { const auto& fields = curr->ref->type.getHeapType().getStruct().fields; shouldBeTrue(curr->index < fields.size(), curr, "bad struct.get field"); auto& field = fields[curr->index]; - shouldBeEqual(curr->value->type, - field.type, - curr, - "struct.set must have the proper type"); + shouldBeSubType(curr->value->type, + field.type, + curr, + "struct.set must have the proper type"); shouldBeEqual( field.mutable_, Mutable, curr, "struct.set field must be mutable"); } @@ -2494,10 +2494,10 @@ void FunctionValidator::visitArraySet(ArraySet* curr) { return; } const auto& element = curr->ref->type.getHeapType().getArray().element; - shouldBeEqual(curr->value->type, - element.type, - curr, - "array.set must have the proper type"); + shouldBeSubType(curr->value->type, + element.type, + curr, + "array.set must have the proper type"); shouldBeTrue(element.mutable_, curr, "array.set type must be mutable"); } diff --git a/test/heap-types.wast b/test/heap-types.wast index 364d1b0a3..137e847af 100644 --- a/test/heap-types.wast +++ b/test/heap-types.wast @@ -37,6 +37,9 @@ (global $rttchild (rtt 1 $child) (rtt.sub $child (global.get $rttparent))) (global $rttgrandchild (rtt 2 $grandchild) (rtt.sub $grandchild (global.get $rttchild))) + (type $nested-child-struct (struct (field (mut (ref $child))))) + (type $nested-child-array (array (mut (ref $child)))) + (func $structs (param $x (ref $struct.A)) (result (ref $struct.B)) (local $tA (ref null $struct.A)) (local $tB (ref null $struct.B)) @@ -67,8 +70,8 @@ (drop (struct.get_s $struct.B 0 (local.get $tB)) ) + ;; immutable fields allow subtyping. (drop - ;; immutable fields allow subtyping. (struct.get $child 0 (ref.null $grandchild)) ) (drop @@ -102,6 +105,11 @@ (ref.null $struct.C) (f32.const 100) ) + ;; values may be subtypes + (struct.set $nested-child-struct 0 + (ref.null $nested-child-struct) + (ref.null $grandchild) + ) (drop (struct.new_default_with_rtt $struct.A (rtt.canon $struct.A) @@ -146,6 +154,12 @@ (i32.const 2) (f64.const 2.18281828) ) + ;; values may be subtypes + (array.set $nested-child-array + (ref.null $nested-child-array) + (i32.const 3) + (ref.null $grandchild) + ) (drop (array.len $vector (local.get $x) diff --git a/test/heap-types.wast.from-wast b/test/heap-types.wast.from-wast index 5835ba7d9..1e2df009d 100644 --- a/test/heap-types.wast.from-wast +++ b/test/heap-types.wast.from-wast @@ -1,20 +1,22 @@ (module (type $struct.A (struct (field i32) (field f32) (field $named f64))) (type $struct.B (struct (field i8) (field (mut i16)) (field (ref null $struct.A)) (field (mut (ref null $struct.A))))) + (type $grandchild (struct (field i32) (field i64))) (type $matrix (array (ref null $vector))) (type $vector (array (mut f64))) (type $anyref_=>_none (func (param anyref))) (type $parent (struct )) - (type $grandchild (struct (field i32) (field i64))) + (type $child (struct (field i32))) (type $struct.C (struct (field $named-mut (mut f32)))) (type $none_=>_none (func)) + (type $nested-child-struct (struct (field (mut (ref null $child))))) (type $rtt_1_$parent_=>_none (func (param (rtt 1 $parent)))) (type $rtt_$parent_=>_none (func (param (rtt $parent)))) (type $ref?|$struct.A|_=>_ref?|$struct.B| (func (param (ref null $struct.A)) (result (ref null $struct.B)))) (type $ref?|$vector|_=>_ref?|$matrix| (func (param (ref null $vector)) (result (ref null $matrix)))) - (type $child (struct (field i32))) (type $words (array (mut i32))) (type $bytes (array (mut i8))) + (type $nested-child-array (array (mut (ref null $child)))) (global $rttparent (rtt 0 $parent) (rtt.canon $parent)) (global $rttchild (rtt 1 $child) (rtt.sub $child (global.get $rttparent) @@ -102,6 +104,10 @@ (ref.null $struct.C) (f32.const 100) ) + (struct.set $nested-child-struct 0 + (ref.null $nested-child-struct) + (ref.null $grandchild) + ) (drop (struct.new_default_with_rtt $struct.A (rtt.canon $struct.A) @@ -146,6 +152,11 @@ (i32.const 2) (f64.const 2.18281828) ) + (array.set $nested-child-array + (ref.null $nested-child-array) + (i32.const 3) + (ref.null $grandchild) + ) (drop (array.len $vector (local.get $x) diff --git a/test/heap-types.wast.fromBinary b/test/heap-types.wast.fromBinary index 3b75de68f..e6338dffd 100644 --- a/test/heap-types.wast.fromBinary +++ b/test/heap-types.wast.fromBinary @@ -1,20 +1,22 @@ (module (type $struct.A (struct (field i32) (field f32) (field $named f64))) (type $struct.B (struct (field i8) (field (mut i16)) (field (ref null $struct.A)) (field (mut (ref null $struct.A))))) + (type $grandchild (struct (field i32) (field i64))) (type $matrix (array (ref null $vector))) (type $vector (array (mut f64))) (type $anyref_=>_none (func (param anyref))) (type $parent (struct )) - (type $grandchild (struct (field i32) (field i64))) + (type $child (struct (field i32))) (type $struct.C (struct (field $named-mut (mut f32)))) (type $none_=>_none (func)) + (type $nested-child-struct (struct (field (mut (ref null $child))))) (type $rtt_1_$parent_=>_none (func (param (rtt 1 $parent)))) (type $rtt_$parent_=>_none (func (param (rtt $parent)))) (type $ref?|$struct.A|_=>_ref?|$struct.B| (func (param (ref null $struct.A)) (result (ref null $struct.B)))) (type $ref?|$vector|_=>_ref?|$matrix| (func (param (ref null $vector)) (result (ref null $matrix)))) - (type $child (struct (field i32))) (type $words (array (mut i32))) (type $bytes (array (mut i8))) + (type $nested-child-array (array (mut (ref null $child)))) (global $rttparent (rtt 0 $parent) (rtt.canon $parent)) (global $rttchild (rtt 1 $child) (rtt.sub $child (global.get $rttparent) @@ -102,6 +104,10 @@ (ref.null $struct.C) (f32.const 100) ) + (struct.set $nested-child-struct 0 + (ref.null $nested-child-struct) + (ref.null $grandchild) + ) (drop (struct.new_default_with_rtt $struct.A (rtt.canon $struct.A) @@ -146,6 +152,11 @@ (i32.const 2) (f64.const 2.18281828) ) + (array.set $nested-child-array + (ref.null $nested-child-array) + (i32.const 3) + (ref.null $grandchild) + ) (drop (array.len $vector (local.get $x) diff --git a/test/heap-types.wast.fromBinary.noDebugInfo b/test/heap-types.wast.fromBinary.noDebugInfo index a4b16afd8..2651ba0d4 100644 --- a/test/heap-types.wast.fromBinary.noDebugInfo +++ b/test/heap-types.wast.fromBinary.noDebugInfo @@ -1,20 +1,22 @@ (module (type ${i32_f32_f64} (struct (field i32) (field f32) (field f64))) (type ${i8_mut:i16_ref?|{i32_f32_f64}|_mut:ref?|{i32_f32_f64}|} (struct (field i8) (field (mut i16)) (field (ref null ${i32_f32_f64})) (field (mut (ref null ${i32_f32_f64}))))) + (type ${i32_i64} (struct (field i32) (field i64))) (type $[ref?|[mut:f64]|] (array (ref null $[mut:f64]))) (type $[mut:f64] (array (mut f64))) (type $anyref_=>_none (func (param anyref))) (type ${} (struct )) - (type ${i32_i64} (struct (field i32) (field i64))) + (type ${i32} (struct (field i32))) (type ${mut:f32} (struct (field (mut f32)))) (type $none_=>_none (func)) + (type ${mut:ref?|{i32}|} (struct (field (mut (ref null ${i32}))))) (type $rtt_1_{}_=>_none (func (param (rtt 1 ${})))) (type $rtt_{}_=>_none (func (param (rtt ${})))) (type $ref?|{i32_f32_f64}|_=>_ref?|{i8_mut:i16_ref?|{i32_f32_f64}|_mut:ref?|{i32_f32_f64}|}| (func (param (ref null ${i32_f32_f64})) (result (ref null ${i8_mut:i16_ref?|{i32_f32_f64}|_mut:ref?|{i32_f32_f64}|})))) (type $ref?|[mut:f64]|_=>_ref?|[ref?|[mut:f64]|]| (func (param (ref null $[mut:f64])) (result (ref null $[ref?|[mut:f64]|])))) - (type ${i32} (struct (field i32))) (type $[mut:i32] (array (mut i32))) (type $[mut:i8] (array (mut i8))) + (type $[mut:ref?|{i32}|] (array (mut (ref null ${i32})))) (global $global$0 (rtt 0 ${}) (rtt.canon ${})) (global $global$1 (rtt 1 ${i32}) (rtt.sub ${i32} (global.get $global$0) @@ -102,6 +104,10 @@ (ref.null ${mut:f32}) (f32.const 100) ) + (struct.set ${mut:ref?|{i32}|} 0 + (ref.null ${mut:ref?|{i32}|}) + (ref.null ${i32_i64}) + ) (drop (struct.new_default_with_rtt ${i32_f32_f64} (rtt.canon ${i32_f32_f64}) @@ -146,6 +152,11 @@ (i32.const 2) (f64.const 2.18281828) ) + (array.set $[mut:ref?|{i32}|] + (ref.null $[mut:ref?|{i32}|]) + (i32.const 3) + (ref.null ${i32_i64}) + ) (drop (array.len $[mut:f64] (local.get $0) |