Commit 05b38588 authored by Manos Koukoutos's avatar Manos Koukoutos Committed by Commit Bot

[wasm] Update br_table with the latest spec changes

The typing of br_table was relaxed in
https://github.com/WebAssembly/spec/pull/1305. Before, we had to compute
the greatest lower bound of all branch types and make sure that stack
values are subtypes of that type. Now, we have to check that the stack
values are subtypes of each individual branch. This makes a difference
only in polymorphic stacks, but greatly simplifies the code, especially
with the upcoming introduction of a much more complex type system in
wasm-gc.

Change-Id: I6e3b410cfe0e71a97623b3030b3575ef707c4900
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2827897
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73982}
parent be9ff65a
This diff is collapsed.
...@@ -435,13 +435,6 @@ V8_NOINLINE bool EquivalentTypes(ValueType type1, ValueType type2, ...@@ -435,13 +435,6 @@ V8_NOINLINE bool EquivalentTypes(ValueType type1, ValueType type2,
module2); module2);
} }
ValueType CommonSubtype(ValueType a, ValueType b, const WasmModule* module) {
if (a == b) return a;
if (IsSubtypeOf(a, b, module)) return a;
if (IsSubtypeOf(b, a, module)) return b;
return kWasmBottom;
}
} // namespace wasm } // namespace wasm
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -93,12 +93,6 @@ V8_INLINE bool IsHeapSubtypeOf(uint32_t subtype_index, uint32_t supertype_index, ...@@ -93,12 +93,6 @@ V8_INLINE bool IsHeapSubtypeOf(uint32_t subtype_index, uint32_t supertype_index,
ValueType::Ref(supertype_index, kNonNullable), module); ValueType::Ref(supertype_index, kNonNullable), module);
} }
// Returns the weakest type that is a subtype of both a and b
// (which is currently always one of a, b, or kWasmBottom).
// TODO(manoskouk): Update this once we have settled on a type system for
// reference types.
ValueType CommonSubtype(ValueType a, ValueType b, const WasmModule* module);
} // namespace wasm } // namespace wasm
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
...@@ -29,5 +29,5 @@ kExprEnd, // @21 ...@@ -29,5 +29,5 @@ kExprEnd, // @21
assertThrows( assertThrows(
() => {builder.toModule()}, WebAssembly.CompileError, () => {builder.toModule()}, WebAssembly.CompileError,
'WebAssembly.Module(): Compiling function #0:\"main\" failed: ' + 'WebAssembly.Module(): Compiling function #0:\"main\" failed: ' +
'type error in merge[0] (expected <bot>, got i32) @+57'); 'type error in merge[0] (expected f32, got i32) @+57');
})(); })();
...@@ -125,7 +125,7 @@ run(I, "U (iblock 0 (block br1)) drop", [unr, ...iblock, ...zero, ...block, ...b ...@@ -125,7 +125,7 @@ run(I, "U (iblock 0 (block br1)) drop", [unr, ...iblock, ...zero, ...block, ...b
run(I, "U (iblock 0 (block 0 brt1)) drop", [unr, ...iblock, ...zero, ...block, ...zero, ...brt1, end, end, drop]); run(I, "U (iblock 0 (block 0 brt1)) drop", [unr, ...iblock, ...zero, ...block, ...zero, ...brt1, end, end, drop]);
run(I, "U (block (iblock 0 0 brt01) drop)", [unr, ...block, ...iblock, ...zero, ...zero, ...brt01, end, drop, end]); run(I, "U (block (iblock 0 0 brt01) drop)", [unr, ...block, ...iblock, ...zero, ...zero, ...brt01, end, drop, end]);
run(V, "(iblock (iblock U 0 brt01)) drop", [...iblock, ...iblock, unr, ...zero, ...brt01, end, end, drop]); run(V, "(iblock (iblock U 0 brt01)) drop", [...iblock, ...iblock, unr, ...zero, ...brt01, end, end, drop]);
run(I, "(block (fblock U 0 brt01) drop)", [...iblock, ...fblock, unr, ...zero, ...brt01, end, drop, end]); run(I, "(block (fblock U 0 brt01) drop)", [...block, ...fblock, unr, ...zero, ...brt01, end, drop, end]);
run(I, "(iblock (fblock U 0 brt01) drop 0) drop", [...iblock, ...fblock, unr, ...zero, ...brt01, end, drop, ...zero, end, drop]); run(V, "(iblock (fblock U 0 brt01) drop 0) drop", [...iblock, ...fblock, unr, ...zero, ...brt01, end, drop, ...zero, end, drop]);
run(I, "(iblock (block (U brif 1))", [...iblock, ...block, unr, kExprBrIf, 0, end, end, kExprDrop]); run(I, "(iblock (block (U brif 1))", [...iblock, ...block, unr, kExprBrIf, 0, end, end, kExprDrop]);
...@@ -2644,6 +2644,29 @@ TEST_F(FunctionBodyDecoderTest, BrTable2b) { ...@@ -2644,6 +2644,29 @@ TEST_F(FunctionBodyDecoderTest, BrTable2b) {
WASM_I32V_2(67), 1, BR_TARGET(0), BR_TARGET(1))))}); WASM_I32V_2(67), 1, BR_TARGET(0), BR_TARGET(1))))});
} }
TEST_F(FunctionBodyDecoderTest, BrTableSubtyping) {
WASM_FEATURE_SCOPE(reftypes);
WASM_FEATURE_SCOPE(typed_funcref);
WASM_FEATURE_SCOPE(gc);
TestModuleBuilder builder;
byte supertype1 = builder.AddStruct({F(kWasmI8, true), F(kWasmI16, false)});
byte supertype2 = builder.AddStruct({F(kWasmI8, true)});
byte subtype = builder.AddStruct(
{F(kWasmI8, true), F(kWasmI16, false), F(kWasmI32, true)});
module = builder.module();
ExpectValidates(
sigs.v_v(),
{WASM_BLOCK_R(
wasm::ValueType::Ref(supertype1, kNonNullable),
WASM_BLOCK_R(
wasm::ValueType::Ref(supertype2, kNonNullable),
WASM_STRUCT_NEW_DEFAULT(subtype, WASM_RTT_CANON(subtype)),
WASM_BR_TABLE(WASM_I32V(5), 1, BR_TARGET(0), BR_TARGET(1))),
WASM_UNREACHABLE),
WASM_DROP});
}
TEST_F(FunctionBodyDecoderTest, BrTable_off_end) { TEST_F(FunctionBodyDecoderTest, BrTable_off_end) {
static byte code[] = {B1(WASM_BR_TABLE(WASM_LOCAL_GET(0), 0, BR_TARGET(0)))}; static byte code[] = {B1(WASM_BR_TABLE(WASM_LOCAL_GET(0), 0, BR_TARGET(0)))};
for (size_t len = 1; len < sizeof(code); len++) { for (size_t len = 1; len < sizeof(code); len++) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment