[test][wasm-gc] replace remaining new and cast instructions using rtt
Bug: v8:7748 Change-Id: I09e9d919751945e99e0178168358a3f269fa34a3 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3776679 Auto-Submit: Matthias Liedtke <mliedtke@google.com> Commit-Queue: Matthias Liedtke <mliedtke@google.com> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Cr-Commit-Position: refs/heads/main@{#81850}
This commit is contained in:
parent
9b913366d4
commit
b9768c0d53
@ -574,10 +574,6 @@ WASM_COMPILED_EXEC_TEST(BrOnCast) {
|
||||
ValueType kDataRefNull = ValueType::RefNull(HeapType::kData);
|
||||
const byte type_index = tester.DefineStruct({F(kWasmI32, true)});
|
||||
const byte other_type_index = tester.DefineStruct({F(kWasmF32, true)});
|
||||
const byte rtt_index =
|
||||
tester.AddGlobal(ValueType::Rtt(type_index), false,
|
||||
WasmInitExpr::RttCanon(
|
||||
static_cast<HeapType::Representation>(type_index)));
|
||||
|
||||
const byte kTestStructStatic = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {kWasmI32, kDataRefNull},
|
||||
@ -608,7 +604,7 @@ WASM_COMPILED_EXEC_TEST(BrOnCast) {
|
||||
WASM_LOCAL_SET(0, WASM_I32V(111)),
|
||||
WASM_LOCAL_GET(1), // Put a nullref onto the value stack.
|
||||
// Not taken for nullref.
|
||||
WASM_BR_ON_CAST(0, WASM_GLOBAL_GET(rtt_index)),
|
||||
WASM_BR_ON_CAST_STATIC(0, type_index),
|
||||
WASM_GC_OP(kExprRefCastStatic), type_index,
|
||||
|
||||
WASM_LOCAL_SET(0, WASM_I32V(222))), // Final result.
|
||||
@ -621,7 +617,7 @@ WASM_COMPILED_EXEC_TEST(BrOnCast) {
|
||||
// The inner block should take the early branch with a struct
|
||||
// on the stack.
|
||||
WASM_BLOCK_R(ValueType::Ref(type_index), WASM_LOCAL_GET(1),
|
||||
WASM_BR_ON_CAST(0, WASM_GLOBAL_GET(rtt_index)),
|
||||
WASM_BR_ON_CAST_STATIC(0, type_index),
|
||||
// Returning 123 is the unreachable failure case.
|
||||
WASM_I32V(123), WASM_BR(1)),
|
||||
// The outer block catches the struct left behind by the inner block
|
||||
@ -658,7 +654,7 @@ WASM_COMPILED_EXEC_TEST(BrOnCastFail) {
|
||||
WASM_LOCAL_SET(0, WASM_SEQ(value)), \
|
||||
WASM_BLOCK( \
|
||||
WASM_BLOCK_R(kDataRefNull, WASM_LOCAL_GET(0), \
|
||||
WASM_BR_ON_CAST_FAIL(0, WASM_RTT_CANON(type0)), \
|
||||
WASM_BR_ON_CAST_STATIC_FAIL(0, type0), \
|
||||
WASM_GC_OP(kExprStructGet), type0, 0, kExprReturn), \
|
||||
kExprBrOnNull, 0, WASM_GC_OP(kExprRefCastStatic), type1, \
|
||||
WASM_GC_OP(kExprStructGet), type1, 1, kExprReturn), \
|
||||
@ -850,16 +846,15 @@ WASM_COMPILED_EXEC_TEST(WasmBasicArray) {
|
||||
|
||||
const byte kInit = tester.DefineFunction(
|
||||
&sig_q_v, {},
|
||||
{WASM_ARRAY_NEW_FIXED(type_index, 3, WASM_I32V(10), WASM_I32V(20),
|
||||
WASM_I32V(30), WASM_RTT_CANON(type_index)),
|
||||
{WASM_ARRAY_NEW_FIXED_STATIC(type_index, 3, WASM_I32V(10), WASM_I32V(20),
|
||||
WASM_I32V(30)),
|
||||
kExprEnd});
|
||||
|
||||
const byte kImmutable = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {},
|
||||
{WASM_ARRAY_GET(immut_type_index,
|
||||
WASM_ARRAY_NEW_FIXED(immut_type_index, 2, WASM_I32V(42),
|
||||
WASM_I32V(43),
|
||||
WASM_RTT_CANON(immut_type_index)),
|
||||
WASM_ARRAY_NEW_FIXED_STATIC(immut_type_index, 2,
|
||||
WASM_I32V(42), WASM_I32V(43)),
|
||||
WASM_I32V(0)),
|
||||
kExprEnd});
|
||||
|
||||
|
@ -527,13 +527,9 @@ inline uint16_t ExtractPrefixedOpcodeBytes(WasmOpcode opcode) {
|
||||
ref, WASM_GC_OP(kExprRefCastStatic), static_cast<byte>(typeidx)
|
||||
// Takes a reference value from the value stack to allow sequences of
|
||||
// conditional branches.
|
||||
#define WASM_BR_ON_CAST(depth, rtt) \
|
||||
rtt, WASM_GC_OP(kExprBrOnCast), static_cast<byte>(depth)
|
||||
#define WASM_BR_ON_CAST_STATIC(depth, typeidx) \
|
||||
WASM_GC_OP(kExprBrOnCastStatic), static_cast<byte>(depth), \
|
||||
static_cast<byte>(typeidx)
|
||||
#define WASM_BR_ON_CAST_FAIL(depth, rtt) \
|
||||
rtt, WASM_GC_OP(kExprBrOnCastFail), static_cast<byte>(depth)
|
||||
#define WASM_BR_ON_CAST_STATIC_FAIL(depth, typeidx) \
|
||||
WASM_GC_OP(kExprBrOnCastStaticFail), static_cast<byte>(depth), \
|
||||
static_cast<byte>(typeidx)
|
||||
@ -581,9 +577,6 @@ inline uint16_t ExtractPrefixedOpcodeBytes(WasmOpcode opcode) {
|
||||
dst_array, dst_index, src_array, src_index, length, \
|
||||
WASM_GC_OP(kExprArrayCopy), static_cast<byte>(dst_idx), \
|
||||
static_cast<byte>(src_idx)
|
||||
#define WASM_ARRAY_NEW_FIXED(index, length, ...) \
|
||||
__VA_ARGS__, WASM_GC_OP(kExprArrayNewFixed), static_cast<byte>(index), \
|
||||
static_cast<byte>(length)
|
||||
#define WASM_ARRAY_NEW_FIXED_STATIC(index, length, ...) \
|
||||
__VA_ARGS__, WASM_GC_OP(kExprArrayNewFixedStatic), static_cast<byte>(index), \
|
||||
static_cast<byte>(length)
|
||||
|
@ -125,8 +125,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
|
||||
let global = builder.addGlobal(
|
||||
wasmRefType(array_type_index), true,
|
||||
[...wasmI32Const(1), ...wasmI32Const(2),
|
||||
kGCPrefix, kExprRttCanon, array_type_index,
|
||||
kGCPrefix, kExprArrayNewData, array_type_index, data_segment],
|
||||
kGCPrefix, kExprArrayNewDataStatic, array_type_index, data_segment],
|
||||
builder);
|
||||
|
||||
builder.addFunction("global_get", kSig_i_i)
|
||||
@ -140,8 +139,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
|
||||
builder.addFunction("init_from_data", kSig_i_iii)
|
||||
.addBody([
|
||||
kExprLocalGet, 0, kExprLocalGet, 1,
|
||||
kGCPrefix, kExprRttCanon, array_type_index,
|
||||
kGCPrefix, kExprArrayNewData, array_type_index, data_segment,
|
||||
kGCPrefix, kExprArrayNewDataStatic, array_type_index, data_segment,
|
||||
kExprLocalGet, 2,
|
||||
kGCPrefix, kExprArrayGetS, array_type_index])
|
||||
.exportFunc();
|
||||
|
@ -200,8 +200,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
|
||||
var global = builder.addGlobal(
|
||||
wasmRefType(array_index), false,
|
||||
[kExprGlobalGet, global0.index, ...wasmI32Const(element1_value),
|
||||
kGCPrefix, kExprRttCanon, array_index,
|
||||
kGCPrefix, kExprArrayNewFixed, array_index, 2]);
|
||||
kGCPrefix, kExprArrayNewFixedStatic, array_index, 2]);
|
||||
|
||||
builder.addFunction("get_element", kSig_i_i)
|
||||
.addBody([
|
||||
@ -236,8 +235,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
|
||||
[kExprGlobalGet, global0.index, kExprRefNull, struct_index,
|
||||
...wasmI32Const(element2_value),
|
||||
kGCPrefix, kExprStructNew, struct_index,
|
||||
kGCPrefix, kExprRttCanon, array_index,
|
||||
kGCPrefix, kExprArrayNewFixed, array_index, 3]);
|
||||
kGCPrefix, kExprArrayNewFixedStatic, array_index, 3]);
|
||||
|
||||
builder.addFunction("element0", kSig_i_v)
|
||||
.addBody([
|
||||
|
@ -491,11 +491,9 @@ let kExprArrayGetU = 0x15;
|
||||
let kExprArraySet = 0x16;
|
||||
let kExprArrayLen = 0x17;
|
||||
let kExprArrayCopy = 0x18;
|
||||
let kExprArrayNewFixed = 0x19;
|
||||
let kExprArrayNewFixedStatic = 0x1a;
|
||||
let kExprArrayNew = 0x1b;
|
||||
let kExprArrayNewDefault = 0x1c;
|
||||
let kExprArrayNewData = 0x1e;
|
||||
let kExprArrayNewDataStatic = 0x1d;
|
||||
let kExprArrayNewElemStatic = 0x1f;
|
||||
let kExprI31New = 0x20;
|
||||
@ -504,8 +502,6 @@ let kExprI31GetU = 0x22;
|
||||
let kExprRttCanon = 0x30;
|
||||
let kExprRttSub = 0x31;
|
||||
let kExprRttFreshSub = 0x32;
|
||||
let kExprBrOnCast = 0x42;
|
||||
let kExprBrOnCastFail = 0x43;
|
||||
let kExprRefTestStatic = 0x44;
|
||||
let kExprRefCastStatic = 0x45;
|
||||
let kExprBrOnCastStatic = 0x46;
|
||||
|
@ -4125,11 +4125,10 @@ TEST_F(FunctionBodyDecoderTest, GCArray) {
|
||||
// Allocating and reading is OK:
|
||||
ExpectValidates(
|
||||
sigs.i_v(),
|
||||
{WASM_ARRAY_GET(
|
||||
immutable_array_type_index,
|
||||
WASM_ARRAY_NEW_FIXED(immutable_array_type_index, 1, WASM_I32V(42),
|
||||
WASM_RTT_CANON(immutable_array_type_index)),
|
||||
WASM_I32V(0))});
|
||||
{WASM_ARRAY_GET(immutable_array_type_index,
|
||||
WASM_ARRAY_NEW_FIXED_STATIC(immutable_array_type_index, 1,
|
||||
WASM_I32V(42)),
|
||||
WASM_I32V(0))});
|
||||
// Writing fails:
|
||||
ExpectFailure(&sig_v_r2,
|
||||
{WASM_ARRAY_SET(immutable_array_type_index, WASM_LOCAL_GET(0),
|
||||
@ -4330,59 +4329,49 @@ TEST_F(FunctionBodyDecoderTest, BrOnCastOrCastFail) {
|
||||
|
||||
ExpectValidates(
|
||||
FunctionSig::Build(this->zone(), {kWasmI32, subtype}, {supertype}),
|
||||
{WASM_I32V(42), WASM_LOCAL_GET(0),
|
||||
WASM_BR_ON_CAST(0, WASM_RTT_CANON(sub_struct)),
|
||||
{WASM_I32V(42), WASM_LOCAL_GET(0), WASM_BR_ON_CAST_STATIC(0, sub_struct),
|
||||
WASM_GC_OP(kExprRefCastStatic), sub_struct});
|
||||
ExpectValidates(
|
||||
FunctionSig::Build(this->zone(), {kWasmI32, supertype}, {supertype}),
|
||||
{WASM_I32V(42), WASM_LOCAL_GET(0),
|
||||
WASM_BR_ON_CAST_FAIL(0, WASM_RTT_CANON(sub_struct))});
|
||||
WASM_BR_ON_CAST_STATIC_FAIL(0, sub_struct)});
|
||||
|
||||
// Wrong branch type.
|
||||
ExpectFailure(
|
||||
FunctionSig::Build(this->zone(), {}, {supertype}),
|
||||
{WASM_LOCAL_GET(0), WASM_BR_ON_CAST(0, WASM_RTT_CANON(sub_struct)),
|
||||
WASM_UNREACHABLE},
|
||||
kAppendEnd, "br_on_cast must target a branch of arity at least 1");
|
||||
ExpectFailure(FunctionSig::Build(this->zone(), {}, {supertype}),
|
||||
{WASM_LOCAL_GET(0), WASM_BR_ON_CAST_STATIC(0, sub_struct),
|
||||
WASM_UNREACHABLE},
|
||||
kAppendEnd,
|
||||
"br_on_cast must target a branch of arity at least 1");
|
||||
ExpectFailure(
|
||||
FunctionSig::Build(this->zone(), {subtype}, {supertype}),
|
||||
{WASM_I32V(42), WASM_LOCAL_GET(0),
|
||||
WASM_BR_ON_CAST_FAIL(0, WASM_RTT_CANON(sub_struct))},
|
||||
WASM_BR_ON_CAST_STATIC_FAIL(0, sub_struct)},
|
||||
kAppendEnd,
|
||||
"type error in branch[0] (expected (ref null 1), got (ref null 0))");
|
||||
|
||||
// Wrong fallthrough type.
|
||||
ExpectFailure(
|
||||
FunctionSig::Build(this->zone(), {subtype}, {supertype}),
|
||||
{WASM_LOCAL_GET(0), WASM_BR_ON_CAST(0, WASM_RTT_CANON(sub_struct))},
|
||||
kAppendEnd,
|
||||
{WASM_LOCAL_GET(0), WASM_BR_ON_CAST_STATIC(0, sub_struct)}, kAppendEnd,
|
||||
"type error in fallthru[0] (expected (ref null 1), got (ref null 0))");
|
||||
ExpectFailure(
|
||||
FunctionSig::Build(this->zone(), {supertype}, {supertype}),
|
||||
{WASM_BLOCK_I(WASM_LOCAL_GET(0),
|
||||
WASM_BR_ON_CAST_FAIL(0, WASM_RTT_CANON(sub_struct)))},
|
||||
kAppendEnd, "type error in branch[0] (expected i32, got (ref null 0))");
|
||||
ExpectFailure(FunctionSig::Build(this->zone(), {supertype}, {supertype}),
|
||||
{WASM_BLOCK_I(WASM_LOCAL_GET(0),
|
||||
WASM_BR_ON_CAST_STATIC_FAIL(0, sub_struct))},
|
||||
kAppendEnd,
|
||||
"type error in branch[0] (expected i32, got (ref null 0))");
|
||||
|
||||
// Argument type error.
|
||||
ExpectFailure(
|
||||
FunctionSig::Build(this->zone(), {subtype}, {kWasmAnyRef}),
|
||||
{WASM_LOCAL_GET(0), WASM_BR_ON_CAST(0, WASM_RTT_CANON(sub_struct)),
|
||||
WASM_GC_OP(kExprRefCastStatic), sub_struct},
|
||||
kAppendEnd,
|
||||
"br_on_cast[0] expected subtype of (ref null func) or (ref null data), "
|
||||
"found local.get of type anyref");
|
||||
ExpectFailure(
|
||||
FunctionSig::Build(this->zone(), {supertype}, {kWasmAnyRef}),
|
||||
{WASM_LOCAL_GET(0), WASM_BR_ON_CAST_FAIL(0, WASM_RTT_CANON(sub_struct))},
|
||||
kAppendEnd,
|
||||
"br_on_cast_fail[0] expected subtype of (ref null func) or (ref null "
|
||||
"data), found local.get of type anyref");
|
||||
|
||||
// Trivial rtt type error.
|
||||
ExpectFailure(FunctionSig::Build(this->zone(), {supertype}, {supertype}),
|
||||
{WASM_LOCAL_GET(0), WASM_BR_ON_CAST_FAIL(0, WASM_I64V(42))},
|
||||
ExpectFailure(FunctionSig::Build(this->zone(), {subtype}, {kWasmAnyRef}),
|
||||
{WASM_LOCAL_GET(0), WASM_BR_ON_CAST_STATIC(0, sub_struct),
|
||||
WASM_GC_OP(kExprRefCastStatic), sub_struct},
|
||||
kAppendEnd,
|
||||
"br_on_cast_fail[1] expected rtt, found i64.const of type i64");
|
||||
"br_on_cast_static[0] expected subtype of (ref null func) or "
|
||||
"(ref null data), found local.get of type anyref");
|
||||
ExpectFailure(FunctionSig::Build(this->zone(), {supertype}, {kWasmAnyRef}),
|
||||
{WASM_LOCAL_GET(0), WASM_BR_ON_CAST_STATIC_FAIL(0, sub_struct)},
|
||||
kAppendEnd,
|
||||
"br_on_cast_static_fail[0] expected subtype of (ref null func) "
|
||||
"or (ref null data), found local.get of type anyref");
|
||||
}
|
||||
|
||||
TEST_F(FunctionBodyDecoderTest, BrOnAbstractType) {
|
||||
|
@ -37,11 +37,8 @@ namespace module_decoder_unittest {
|
||||
#define WASM_INIT_EXPR_GLOBAL(index) WASM_GLOBAL_GET(index), kExprEnd
|
||||
#define WASM_INIT_EXPR_STRUCT_NEW(index, ...) \
|
||||
WASM_STRUCT_NEW(index, __VA_ARGS__), kExprEnd
|
||||
#define WASM_INIT_EXPR_ARRAY_NEW_FIXED(index, length, ...) \
|
||||
WASM_ARRAY_NEW_FIXED(index, length, __VA_ARGS__), kExprEnd
|
||||
#define WASM_INIT_EXPR_ARRAY_NEW_FIXED_STATIC(index, length, ...) \
|
||||
WASM_ARRAY_NEW_FIXED_STATIC(index, length, __VA_ARGS__), kExprEnd
|
||||
#define WASM_INIT_EXPR_RTT_CANON(index) WASM_RTT_CANON(index), kExprEnd
|
||||
|
||||
#define REF_NULL_ELEMENT kExprRefNull, kFuncRefCode, kExprEnd
|
||||
#define REF_FUNC_ELEMENT(v) kExprRefFunc, U32V_1(v), kExprEnd
|
||||
@ -854,11 +851,10 @@ TEST_F(WasmModuleVerifyTest, ArrayNewFixedInitExpr) {
|
||||
|
||||
static const byte basic[] = {
|
||||
SECTION(Type, ENTRY_COUNT(1), WASM_ARRAY_DEF(kI16Code, true)),
|
||||
SECTION(
|
||||
Global, ENTRY_COUNT(1), // --
|
||||
kRefCode, 0, 0, // type, mutability
|
||||
WASM_INIT_EXPR_ARRAY_NEW_FIXED(0, 3, WASM_I32V(10), WASM_I32V(20),
|
||||
WASM_I32V(30), WASM_RTT_CANON(0)))};
|
||||
SECTION(Global, ENTRY_COUNT(1), // --
|
||||
kRefCode, 0, 0, // type, mutability
|
||||
WASM_INIT_EXPR_ARRAY_NEW_FIXED_STATIC(
|
||||
0, 3, WASM_I32V(10), WASM_I32V(20), WASM_I32V(30)))};
|
||||
EXPECT_VERIFIES(basic);
|
||||
|
||||
static const byte basic_nominal[] = {
|
||||
@ -871,11 +867,10 @@ TEST_F(WasmModuleVerifyTest, ArrayNewFixedInitExpr) {
|
||||
|
||||
static const byte basic_immutable[] = {
|
||||
SECTION(Type, ENTRY_COUNT(1), WASM_ARRAY_DEF(kI32Code, false)),
|
||||
SECTION(
|
||||
Global, ENTRY_COUNT(1), // --
|
||||
kRefCode, 0, 0, // type, mutability
|
||||
WASM_INIT_EXPR_ARRAY_NEW_FIXED(0, 3, WASM_I32V(10), WASM_I32V(20),
|
||||
WASM_I32V(30), WASM_RTT_CANON(0)))};
|
||||
SECTION(Global, ENTRY_COUNT(1), // --
|
||||
kRefCode, 0, 0, // type, mutability
|
||||
WASM_INIT_EXPR_ARRAY_NEW_FIXED_STATIC(
|
||||
0, 3, WASM_I32V(10), WASM_I32V(20), WASM_I32V(30)))};
|
||||
EXPECT_VERIFIES(basic_immutable);
|
||||
|
||||
static const byte type_error[] = {
|
||||
@ -884,8 +879,7 @@ TEST_F(WasmModuleVerifyTest, ArrayNewFixedInitExpr) {
|
||||
WASM_ARRAY_DEF(WASM_SEQ(kRefCode, 0), true)),
|
||||
SECTION(Global, ENTRY_COUNT(1), // --
|
||||
kRefCode, 1, 0, // type, mutability
|
||||
WASM_INIT_EXPR_ARRAY_NEW_FIXED(0, 1, WASM_I32V(42),
|
||||
WASM_RTT_CANON(0)))};
|
||||
WASM_INIT_EXPR_ARRAY_NEW_FIXED_STATIC(0, 1, WASM_I32V(42)))};
|
||||
EXPECT_FAILURE_WITH_MSG(
|
||||
type_error,
|
||||
"type error in constant expression[0] (expected (ref 1), got (ref 0))");
|
||||
@ -894,22 +888,21 @@ TEST_F(WasmModuleVerifyTest, ArrayNewFixedInitExpr) {
|
||||
SECTION(Type, ENTRY_COUNT(1), WASM_ARRAY_DEF(kI64Code, true)),
|
||||
SECTION(Global, ENTRY_COUNT(1), // --
|
||||
kRefCode, 0, 0, // type, mutability
|
||||
WASM_INIT_EXPR_ARRAY_NEW_FIXED(
|
||||
0, 2, WASM_I64V(42), WASM_I32V(142), WASM_RTT_CANON(0)))};
|
||||
EXPECT_FAILURE_WITH_MSG(
|
||||
subexpr_type_error,
|
||||
"array.new_fixed[1] expected type i64, found i32.const of type i32");
|
||||
WASM_INIT_EXPR_ARRAY_NEW_FIXED_STATIC(0, 2, WASM_I64V(42),
|
||||
WASM_I32V(142)))};
|
||||
EXPECT_FAILURE_WITH_MSG(subexpr_type_error,
|
||||
"array.new_fixed_static[1] expected type i64, found "
|
||||
"i32.const of type i32");
|
||||
|
||||
static const byte length_error[] = {
|
||||
SECTION(Type, ENTRY_COUNT(1), WASM_ARRAY_DEF(kI16Code, true)),
|
||||
SECTION(
|
||||
Global, ENTRY_COUNT(1), // --
|
||||
kRefCode, 0, 0, // type, mutability
|
||||
WASM_INIT_EXPR_ARRAY_NEW_FIXED(0, 10, WASM_I32V(10), WASM_I32V(20),
|
||||
WASM_I32V(30), WASM_RTT_CANON(0)))};
|
||||
EXPECT_FAILURE_WITH_MSG(
|
||||
length_error,
|
||||
"not enough arguments on the stack for array.new_fixed (need 11, got 4)");
|
||||
SECTION(Global, ENTRY_COUNT(1), // --
|
||||
kRefCode, 0, 0, // type, mutability
|
||||
WASM_INIT_EXPR_ARRAY_NEW_FIXED_STATIC(
|
||||
0, 10, WASM_I32V(10), WASM_I32V(20), WASM_I32V(30)))};
|
||||
EXPECT_FAILURE_WITH_MSG(length_error,
|
||||
"not enough arguments on the stack for "
|
||||
"array.new_fixed_static (need 11, got 4)");
|
||||
}
|
||||
|
||||
TEST_F(WasmModuleVerifyTest, EmptyStruct) {
|
||||
|
Loading…
Reference in New Issue
Block a user