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) {
#define WASM_REF_IS_NULL(val) val, kExprRefIsNull
#define WASM_REF_AS_NON_NULL(val) val, kExprRefAsNonNull
#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) \
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) \
ref, WASM_GC_OP(kExprRefCastStatic), static_cast<byte>(typeidx)
// 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");
builder.addFunction("main", makeSig([wasmRefType(kWasmFuncRef)], [kWasmI32]))
.addBody([
// Type check the function
kExprLocalGet, 0, kGCPrefix, kExprRttCanon, sig, kGCPrefix, kExprRefCast,
kExprLocalGet, 0, kGCPrefix, kExprRefCastStatic, sig,
kExprDrop,
// Introduce unknown effect
kExprCallFunction, effect,
// TF should be able to eliminate the second type check, and return the
// constant 1.
kExprLocalGet, 0, kGCPrefix, kExprRttCanon, sig,
kGCPrefix, kExprRefTest])
kExprLocalGet, 0,
kGCPrefix, kExprRefTestStatic, sig])
.exportFunc();
var instance = builder.instantiate({m : { f: function () {} }});
......
......@@ -27,21 +27,19 @@ function createArray_i() {
builder.addFunction("array_get", sig_i_ai)
.addBody([
kExprLocalGet, 0, // --
kGCPrefix, kExprRttCanon, type_index, // --
kGCPrefix, kExprRefCast, // --
kExprLocalGet, 1, // --
kGCPrefix, kExprArrayGet, type_index]) // --
kExprLocalGet, 0, // --
kGCPrefix, kExprRefCastStatic, type_index, // --
kExprLocalGet, 1, // --
kGCPrefix, kExprArrayGet, type_index]) // --
.exportAs("array_get");
builder.addFunction("array_set", sig_v_aii)
.addBody([
kExprLocalGet, 0, // --
kGCPrefix, kExprRttCanon, type_index, // --
kGCPrefix, kExprRefCast, // --
kExprLocalGet, 1, // --
kExprLocalGet, 2, // --
kGCPrefix, kExprArraySet, type_index]) // --
kExprLocalGet, 0, // --
kGCPrefix, kExprRefCastStatic, type_index, // --
kExprLocalGet, 1, // --
kExprLocalGet, 2, // --
kGCPrefix, kExprArraySet, type_index]) // --
.exportAs("array_set");
let instance = builder.instantiate();
......
......@@ -504,8 +504,6 @@ let kExprI31GetU = 0x22;
let kExprRttCanon = 0x30;
let kExprRttSub = 0x31;
let kExprRttFreshSub = 0x32;
let kExprRefTest = 0x40;
let kExprRefCast = 0x41;
let kExprBrOnCast = 0x42;
let kExprBrOnCastFail = 0x43;
let kExprRefTestStatic = 0x44;
......
......@@ -33,16 +33,14 @@ function createSimpleStruct(field_type, value1, value2) {
builder.addFunction("get_field", sig_t_a)
.addBody([
kExprLocalGet, 0, // --
kGCPrefix, kExprRttCanon, type_index, // --
kGCPrefix, kExprRefCast, // --
kGCPrefix, kExprRefCastStatic, type_index, // --
kGCPrefix, struct_get_opcode, type_index, 0]) // --
.exportAs("get_field");
builder.addFunction("set_field", sig_v_at)
.addBody([
kExprLocalGet, 0, // --
kGCPrefix, kExprRttCanon, type_index, // --
kGCPrefix, kExprRefCast, // --
kGCPrefix, kExprRefCastStatic, type_index, // --
kExprLocalGet, 1, // --
kGCPrefix, kExprStructSet, type_index, 0]) // --
.exportAs("set_field");
......
......@@ -1154,16 +1154,12 @@ TEST_F(FunctionBodyDecoderTest, UnreachableRefTypes) {
{WASM_UNREACHABLE, WASM_GC_OP(kExprArrayNewDefault),
array_index, kExprDrop});
ExpectValidates(sigs.i_v(), {WASM_UNREACHABLE, WASM_GC_OP(kExprRefTest),
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.i_v(), {WASM_UNREACHABLE, WASM_GC_OP(kExprRefTestStatic),
struct_index});
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, WASM_GC_OP(kExprRefCast),
struct_index, struct_index, kExprDrop});
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, WASM_RTT_CANON(struct_index),
WASM_GC_OP(kExprRefCast), struct_index,
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, WASM_GC_OP(kExprRefCastStatic),
struct_index, kExprDrop});
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, WASM_GC_OP(kExprRefCastStatic),
struct_index, kExprDrop});
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, kExprBrOnNull, 0, WASM_DROP});
......@@ -1171,9 +1167,9 @@ TEST_F(FunctionBodyDecoderTest, UnreachableRefTypes) {
ExpectValidates(&sig_v_s, {WASM_UNREACHABLE, WASM_LOCAL_GET(0), kExprBrOnNull,
0, kExprCallFunction, struct_consumer});
ExpectValidates(FunctionSig::Build(zone(), {struct_type}, {}),
{WASM_UNREACHABLE, WASM_RTT_CANON(struct_index),
WASM_GC_OP(kExprRefCast)});
ExpectValidates(
FunctionSig::Build(zone(), {struct_type}, {}),
{WASM_UNREACHABLE, WASM_GC_OP(kExprRefCastStatic), struct_index});
ExpectValidates(FunctionSig::Build(zone(), {kWasmDataRef}, {}),
{WASM_UNREACHABLE, WASM_GC_OP(kExprRefAsData)});
......@@ -4280,56 +4276,44 @@ TEST_F(FunctionBodyDecoderTest, RefTestCast) {
ValueType test_reps[] = {kWasmI32, ValueType::RefNull(from_heap)};
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::RefNull(from_heap),
ValueType::Rtt(to_heap.ref_index())};
FunctionSig cast_sig(1, 2, cast_reps);
ValueType::RefNull(from_heap)};
FunctionSig cast_sig(1, 1, cast_reps);
if (should_pass) {
ExpectValidates(&test_sig,
{WASM_REF_TEST(WASM_LOCAL_GET(0),
WASM_RTT_CANON(WASM_HEAP_TYPE(to_heap)))});
ExpectValidates(&cast_sig_with_depth,
{WASM_REF_CAST(WASM_LOCAL_GET(0),
WASM_RTT_CANON(WASM_HEAP_TYPE(to_heap)))});
ExpectValidates(&cast_sig,
{WASM_REF_CAST(WASM_LOCAL_GET(0), WASM_LOCAL_GET(1))});
ExpectValidates(
&test_sig,
{WASM_REF_TEST_STATIC(WASM_LOCAL_GET(0), WASM_HEAP_TYPE(to_heap))});
ExpectValidates(
&cast_sig,
{WASM_REF_CAST_STATIC(WASM_LOCAL_GET(0), WASM_HEAP_TYPE(to_heap))});
} else {
std::string error_message =
"[0] expected subtype of (ref null func) or (ref null data), found "
"local.get of type " +
test_reps[1].name();
ExpectFailure(&test_sig,
{WASM_REF_TEST(WASM_LOCAL_GET(0),
WASM_RTT_CANON(WASM_HEAP_TYPE(to_heap)))},
kAppendEnd, ("ref.test" + error_message).c_str());
ExpectFailure(&cast_sig_with_depth,
{WASM_REF_CAST(WASM_LOCAL_GET(0),
WASM_RTT_CANON(WASM_HEAP_TYPE(to_heap)))},
kAppendEnd, ("ref.cast" + 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());
ExpectFailure(
&test_sig,
{WASM_REF_TEST_STATIC(WASM_LOCAL_GET(0), WASM_HEAP_TYPE(to_heap))},
kAppendEnd, ("ref.test_static" + error_message).c_str());
ExpectFailure(
&cast_sig,
{WASM_REF_CAST_STATIC(WASM_LOCAL_GET(0), WASM_HEAP_TYPE(to_heap))},
kAppendEnd, ("ref.cast_static" + error_message).c_str());
}
}
// Trivial type error.
ExpectFailure(
sigs.v_v(),
{WASM_REF_TEST(WASM_I32V(1), WASM_RTT_CANON(array_heap)), kExprDrop},
kAppendEnd,
"ref.test[0] expected subtype of (ref null func) or (ref null data), "
"found i32.const of type i32");
ExpectFailure(
sigs.v_v(),
{WASM_REF_CAST(WASM_I32V(1), WASM_RTT_CANON(array_heap)), kExprDrop},
kAppendEnd,
"ref.cast[0] expected subtype of (ref null func) or (ref null data), "
"found i32.const of type i32");
ExpectFailure(sigs.v_v(),
{WASM_REF_TEST_STATIC(WASM_I32V(1), array_heap), kExprDrop},
kAppendEnd,
"ref.test_static[0] expected subtype of (ref null func) or "
"(ref null data), found i32.const of type i32");
ExpectFailure(sigs.v_v(),
{WASM_REF_CAST_STATIC(WASM_I32V(1), array_heap), kExprDrop},
kAppendEnd,
"ref.cast_static[0] expected subtype of (ref null func) or "
"(ref null data), found i32.const of type i32");
}
TEST_F(FunctionBodyDecoderTest, BrOnCastOrCastFail) {
......@@ -4348,7 +4332,7 @@ TEST_F(FunctionBodyDecoderTest, BrOnCastOrCastFail) {
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_RTT_CANON(sub_struct), WASM_GC_OP(kExprRefCast)});
WASM_GC_OP(kExprRefCastStatic), sub_struct});
ExpectValidates(
FunctionSig::Build(this->zone(), {kWasmI32, supertype}, {supertype}),
{WASM_I32V(42), WASM_LOCAL_GET(0),
......@@ -4383,7 +4367,7 @@ TEST_F(FunctionBodyDecoderTest, BrOnCastOrCastFail) {
ExpectFailure(
FunctionSig::Build(this->zone(), {subtype}, {kWasmAnyRef}),
{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,
"br_on_cast[0] expected subtype of (ref null func) or (ref null data), "
"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