Commit 81bd4a55 authored by Matthias Liedtke's avatar Matthias Liedtke Committed by V8 LUCI CQ

[test][wasm-gc] Replace ref.(cast|test) usages with static variant

Bug: v8:7748
Change-Id: Iec95162ec86a0d96fdd64764864604fc3e26cc39
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3771902Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Auto-Submit: Matthias Liedtke <mliedtke@google.com>
Commit-Queue: Matthias Liedtke <mliedtke@google.com>
Cr-Commit-Position: refs/heads/main@{#81821}
parent 7e935314
This diff is collapsed.
...@@ -521,10 +521,8 @@ inline uint16_t ExtractPrefixedOpcodeBytes(WasmOpcode opcode) { ...@@ -521,10 +521,8 @@ inline uint16_t ExtractPrefixedOpcodeBytes(WasmOpcode opcode) {
#define WASM_REF_IS_NULL(val) val, kExprRefIsNull #define WASM_REF_IS_NULL(val) val, kExprRefIsNull
#define WASM_REF_AS_NON_NULL(val) val, kExprRefAsNonNull #define WASM_REF_AS_NON_NULL(val) val, kExprRefAsNonNull
#define WASM_REF_EQ(lhs, rhs) lhs, rhs, kExprRefEq #define WASM_REF_EQ(lhs, rhs) lhs, rhs, kExprRefEq
#define WASM_REF_TEST(ref, rtt) ref, rtt, WASM_GC_OP(kExprRefTest)
#define WASM_REF_TEST_STATIC(ref, typeidx) \ #define WASM_REF_TEST_STATIC(ref, typeidx) \
ref, WASM_GC_OP(kExprRefTestStatic), static_cast<byte>(typeidx) ref, WASM_GC_OP(kExprRefTestStatic), static_cast<byte>(typeidx)
#define WASM_REF_CAST(ref, rtt) ref, rtt, WASM_GC_OP(kExprRefCast)
#define WASM_REF_CAST_STATIC(ref, typeidx) \ #define WASM_REF_CAST_STATIC(ref, typeidx) \
ref, WASM_GC_OP(kExprRefCastStatic), static_cast<byte>(typeidx) ref, WASM_GC_OP(kExprRefCastStatic), static_cast<byte>(typeidx)
// Takes a reference value from the value stack to allow sequences of // Takes a reference value from the value stack to allow sequences of
......
...@@ -121,14 +121,14 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -121,14 +121,14 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
builder.addFunction("main", makeSig([wasmRefType(kWasmFuncRef)], [kWasmI32])) builder.addFunction("main", makeSig([wasmRefType(kWasmFuncRef)], [kWasmI32]))
.addBody([ .addBody([
// Type check the function // Type check the function
kExprLocalGet, 0, kGCPrefix, kExprRttCanon, sig, kGCPrefix, kExprRefCast, kExprLocalGet, 0, kGCPrefix, kExprRefCastStatic, sig,
kExprDrop, kExprDrop,
// Introduce unknown effect // Introduce unknown effect
kExprCallFunction, effect, kExprCallFunction, effect,
// TF should be able to eliminate the second type check, and return the // TF should be able to eliminate the second type check, and return the
// constant 1. // constant 1.
kExprLocalGet, 0, kGCPrefix, kExprRttCanon, sig, kExprLocalGet, 0,
kGCPrefix, kExprRefTest]) kGCPrefix, kExprRefTestStatic, sig])
.exportFunc(); .exportFunc();
var instance = builder.instantiate({m : { f: function () {} }}); var instance = builder.instantiate({m : { f: function () {} }});
......
...@@ -28,8 +28,7 @@ function createArray_i() { ...@@ -28,8 +28,7 @@ function createArray_i() {
builder.addFunction("array_get", sig_i_ai) builder.addFunction("array_get", sig_i_ai)
.addBody([ .addBody([
kExprLocalGet, 0, // -- kExprLocalGet, 0, // --
kGCPrefix, kExprRttCanon, type_index, // -- kGCPrefix, kExprRefCastStatic, type_index, // --
kGCPrefix, kExprRefCast, // --
kExprLocalGet, 1, // -- kExprLocalGet, 1, // --
kGCPrefix, kExprArrayGet, type_index]) // -- kGCPrefix, kExprArrayGet, type_index]) // --
.exportAs("array_get"); .exportAs("array_get");
...@@ -37,8 +36,7 @@ function createArray_i() { ...@@ -37,8 +36,7 @@ function createArray_i() {
builder.addFunction("array_set", sig_v_aii) builder.addFunction("array_set", sig_v_aii)
.addBody([ .addBody([
kExprLocalGet, 0, // -- kExprLocalGet, 0, // --
kGCPrefix, kExprRttCanon, type_index, // -- kGCPrefix, kExprRefCastStatic, type_index, // --
kGCPrefix, kExprRefCast, // --
kExprLocalGet, 1, // -- kExprLocalGet, 1, // --
kExprLocalGet, 2, // -- kExprLocalGet, 2, // --
kGCPrefix, kExprArraySet, type_index]) // -- kGCPrefix, kExprArraySet, type_index]) // --
......
...@@ -504,8 +504,6 @@ let kExprI31GetU = 0x22; ...@@ -504,8 +504,6 @@ let kExprI31GetU = 0x22;
let kExprRttCanon = 0x30; let kExprRttCanon = 0x30;
let kExprRttSub = 0x31; let kExprRttSub = 0x31;
let kExprRttFreshSub = 0x32; let kExprRttFreshSub = 0x32;
let kExprRefTest = 0x40;
let kExprRefCast = 0x41;
let kExprBrOnCast = 0x42; let kExprBrOnCast = 0x42;
let kExprBrOnCastFail = 0x43; let kExprBrOnCastFail = 0x43;
let kExprRefTestStatic = 0x44; let kExprRefTestStatic = 0x44;
......
...@@ -33,16 +33,14 @@ function createSimpleStruct(field_type, value1, value2) { ...@@ -33,16 +33,14 @@ function createSimpleStruct(field_type, value1, value2) {
builder.addFunction("get_field", sig_t_a) builder.addFunction("get_field", sig_t_a)
.addBody([ .addBody([
kExprLocalGet, 0, // -- kExprLocalGet, 0, // --
kGCPrefix, kExprRttCanon, type_index, // -- kGCPrefix, kExprRefCastStatic, type_index, // --
kGCPrefix, kExprRefCast, // --
kGCPrefix, struct_get_opcode, type_index, 0]) // -- kGCPrefix, struct_get_opcode, type_index, 0]) // --
.exportAs("get_field"); .exportAs("get_field");
builder.addFunction("set_field", sig_v_at) builder.addFunction("set_field", sig_v_at)
.addBody([ .addBody([
kExprLocalGet, 0, // -- kExprLocalGet, 0, // --
kGCPrefix, kExprRttCanon, type_index, // -- kGCPrefix, kExprRefCastStatic, type_index, // --
kGCPrefix, kExprRefCast, // --
kExprLocalGet, 1, // -- kExprLocalGet, 1, // --
kGCPrefix, kExprStructSet, type_index, 0]) // -- kGCPrefix, kExprStructSet, type_index, 0]) // --
.exportAs("set_field"); .exportAs("set_field");
......
...@@ -1154,16 +1154,12 @@ TEST_F(FunctionBodyDecoderTest, UnreachableRefTypes) { ...@@ -1154,16 +1154,12 @@ TEST_F(FunctionBodyDecoderTest, UnreachableRefTypes) {
{WASM_UNREACHABLE, WASM_GC_OP(kExprArrayNewDefault), {WASM_UNREACHABLE, WASM_GC_OP(kExprArrayNewDefault),
array_index, kExprDrop}); array_index, kExprDrop});
ExpectValidates(sigs.i_v(), {WASM_UNREACHABLE, WASM_GC_OP(kExprRefTest), ExpectValidates(sigs.i_v(), {WASM_UNREACHABLE, WASM_GC_OP(kExprRefTestStatic),
struct_index, struct_index}); struct_index});
ExpectValidates(sigs.i_v(),
{WASM_UNREACHABLE, WASM_RTT_CANON(struct_index),
WASM_GC_OP(kExprRefTest), struct_index, struct_index});
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, WASM_GC_OP(kExprRefCast), ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, WASM_GC_OP(kExprRefCastStatic),
struct_index, struct_index, kExprDrop}); struct_index, kExprDrop});
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, WASM_RTT_CANON(struct_index), ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, WASM_GC_OP(kExprRefCastStatic),
WASM_GC_OP(kExprRefCast), struct_index,
struct_index, kExprDrop}); struct_index, kExprDrop});
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, kExprBrOnNull, 0, WASM_DROP}); ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, kExprBrOnNull, 0, WASM_DROP});
...@@ -1171,9 +1167,9 @@ TEST_F(FunctionBodyDecoderTest, UnreachableRefTypes) { ...@@ -1171,9 +1167,9 @@ TEST_F(FunctionBodyDecoderTest, UnreachableRefTypes) {
ExpectValidates(&sig_v_s, {WASM_UNREACHABLE, WASM_LOCAL_GET(0), kExprBrOnNull, ExpectValidates(&sig_v_s, {WASM_UNREACHABLE, WASM_LOCAL_GET(0), kExprBrOnNull,
0, kExprCallFunction, struct_consumer}); 0, kExprCallFunction, struct_consumer});
ExpectValidates(FunctionSig::Build(zone(), {struct_type}, {}), ExpectValidates(
{WASM_UNREACHABLE, WASM_RTT_CANON(struct_index), FunctionSig::Build(zone(), {struct_type}, {}),
WASM_GC_OP(kExprRefCast)}); {WASM_UNREACHABLE, WASM_GC_OP(kExprRefCastStatic), struct_index});
ExpectValidates(FunctionSig::Build(zone(), {kWasmDataRef}, {}), ExpectValidates(FunctionSig::Build(zone(), {kWasmDataRef}, {}),
{WASM_UNREACHABLE, WASM_GC_OP(kExprRefAsData)}); {WASM_UNREACHABLE, WASM_GC_OP(kExprRefAsData)});
...@@ -4280,56 +4276,44 @@ TEST_F(FunctionBodyDecoderTest, RefTestCast) { ...@@ -4280,56 +4276,44 @@ TEST_F(FunctionBodyDecoderTest, RefTestCast) {
ValueType test_reps[] = {kWasmI32, ValueType::RefNull(from_heap)}; ValueType test_reps[] = {kWasmI32, ValueType::RefNull(from_heap)};
FunctionSig test_sig(1, 1, test_reps); FunctionSig test_sig(1, 1, test_reps);
ValueType cast_reps_with_depth[] = {ValueType::RefNull(to_heap),
ValueType::RefNull(from_heap)};
FunctionSig cast_sig_with_depth(1, 1, cast_reps_with_depth);
ValueType cast_reps[] = {ValueType::RefNull(to_heap), ValueType cast_reps[] = {ValueType::RefNull(to_heap),
ValueType::RefNull(from_heap), ValueType::RefNull(from_heap)};
ValueType::Rtt(to_heap.ref_index())}; FunctionSig cast_sig(1, 1, cast_reps);
FunctionSig cast_sig(1, 2, cast_reps);
if (should_pass) { if (should_pass) {
ExpectValidates(&test_sig, ExpectValidates(
{WASM_REF_TEST(WASM_LOCAL_GET(0), &test_sig,
WASM_RTT_CANON(WASM_HEAP_TYPE(to_heap)))}); {WASM_REF_TEST_STATIC(WASM_LOCAL_GET(0), WASM_HEAP_TYPE(to_heap))});
ExpectValidates(&cast_sig_with_depth, ExpectValidates(
{WASM_REF_CAST(WASM_LOCAL_GET(0), &cast_sig,
WASM_RTT_CANON(WASM_HEAP_TYPE(to_heap)))}); {WASM_REF_CAST_STATIC(WASM_LOCAL_GET(0), WASM_HEAP_TYPE(to_heap))});
ExpectValidates(&cast_sig,
{WASM_REF_CAST(WASM_LOCAL_GET(0), WASM_LOCAL_GET(1))});
} else { } else {
std::string error_message = std::string error_message =
"[0] expected subtype of (ref null func) or (ref null data), found " "[0] expected subtype of (ref null func) or (ref null data), found "
"local.get of type " + "local.get of type " +
test_reps[1].name(); test_reps[1].name();
ExpectFailure(&test_sig, ExpectFailure(
{WASM_REF_TEST(WASM_LOCAL_GET(0), &test_sig,
WASM_RTT_CANON(WASM_HEAP_TYPE(to_heap)))}, {WASM_REF_TEST_STATIC(WASM_LOCAL_GET(0), WASM_HEAP_TYPE(to_heap))},
kAppendEnd, ("ref.test" + error_message).c_str()); kAppendEnd, ("ref.test_static" + error_message).c_str());
ExpectFailure(&cast_sig_with_depth, ExpectFailure(
{WASM_REF_CAST(WASM_LOCAL_GET(0), &cast_sig,
WASM_RTT_CANON(WASM_HEAP_TYPE(to_heap)))}, {WASM_REF_CAST_STATIC(WASM_LOCAL_GET(0), WASM_HEAP_TYPE(to_heap))},
kAppendEnd, ("ref.cast" + error_message).c_str()); kAppendEnd, ("ref.cast_static" + error_message).c_str());
ExpectFailure(&cast_sig,
{WASM_REF_CAST(WASM_LOCAL_GET(0), WASM_LOCAL_GET(1))},
kAppendEnd, ("ref.cast" + error_message).c_str());
} }
} }
// Trivial type error. // Trivial type error.
ExpectFailure( ExpectFailure(sigs.v_v(),
sigs.v_v(), {WASM_REF_TEST_STATIC(WASM_I32V(1), array_heap), kExprDrop},
{WASM_REF_TEST(WASM_I32V(1), WASM_RTT_CANON(array_heap)), kExprDrop},
kAppendEnd, kAppendEnd,
"ref.test[0] expected subtype of (ref null func) or (ref null data), " "ref.test_static[0] expected subtype of (ref null func) or "
"found i32.const of type i32"); "(ref null data), found i32.const of type i32");
ExpectFailure( ExpectFailure(sigs.v_v(),
sigs.v_v(), {WASM_REF_CAST_STATIC(WASM_I32V(1), array_heap), kExprDrop},
{WASM_REF_CAST(WASM_I32V(1), WASM_RTT_CANON(array_heap)), kExprDrop},
kAppendEnd, kAppendEnd,
"ref.cast[0] expected subtype of (ref null func) or (ref null data), " "ref.cast_static[0] expected subtype of (ref null func) or "
"found i32.const of type i32"); "(ref null data), found i32.const of type i32");
} }
TEST_F(FunctionBodyDecoderTest, BrOnCastOrCastFail) { TEST_F(FunctionBodyDecoderTest, BrOnCastOrCastFail) {
...@@ -4348,7 +4332,7 @@ TEST_F(FunctionBodyDecoderTest, BrOnCastOrCastFail) { ...@@ -4348,7 +4332,7 @@ TEST_F(FunctionBodyDecoderTest, BrOnCastOrCastFail) {
FunctionSig::Build(this->zone(), {kWasmI32, subtype}, {supertype}), FunctionSig::Build(this->zone(), {kWasmI32, subtype}, {supertype}),
{WASM_I32V(42), WASM_LOCAL_GET(0), {WASM_I32V(42), WASM_LOCAL_GET(0),
WASM_BR_ON_CAST(0, WASM_RTT_CANON(sub_struct)), WASM_BR_ON_CAST(0, WASM_RTT_CANON(sub_struct)),
WASM_RTT_CANON(sub_struct), WASM_GC_OP(kExprRefCast)}); WASM_GC_OP(kExprRefCastStatic), sub_struct});
ExpectValidates( ExpectValidates(
FunctionSig::Build(this->zone(), {kWasmI32, supertype}, {supertype}), FunctionSig::Build(this->zone(), {kWasmI32, supertype}, {supertype}),
{WASM_I32V(42), WASM_LOCAL_GET(0), {WASM_I32V(42), WASM_LOCAL_GET(0),
...@@ -4383,7 +4367,7 @@ TEST_F(FunctionBodyDecoderTest, BrOnCastOrCastFail) { ...@@ -4383,7 +4367,7 @@ TEST_F(FunctionBodyDecoderTest, BrOnCastOrCastFail) {
ExpectFailure( ExpectFailure(
FunctionSig::Build(this->zone(), {subtype}, {kWasmAnyRef}), FunctionSig::Build(this->zone(), {subtype}, {kWasmAnyRef}),
{WASM_LOCAL_GET(0), WASM_BR_ON_CAST(0, WASM_RTT_CANON(sub_struct)), {WASM_LOCAL_GET(0), WASM_BR_ON_CAST(0, WASM_RTT_CANON(sub_struct)),
WASM_RTT_CANON(sub_struct), WASM_GC_OP(kExprRefCast)}, WASM_GC_OP(kExprRefCastStatic), sub_struct},
kAppendEnd, kAppendEnd,
"br_on_cast[0] expected subtype of (ref null func) or (ref null data), " "br_on_cast[0] expected subtype of (ref null func) or (ref null data), "
"found local.get of type anyref"); "found local.get of type anyref");
......
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