[wasm-gc] Test improvements
- Adapt subtyping unittest to the new HeapType API - Generalize WASM_REF_TYPE macro Bug: v8:7748 Change-Id: Ifdb24408d7a34a6470ddccdf3dc8536cbb93dece Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2274610 Commit-Queue: Manos Koukoutos <manoskouk@chromium.org> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Cr-Commit-Position: refs/heads/master@{#68652}
This commit is contained in:
parent
3b467cb52a
commit
0a819023d1
@ -208,19 +208,18 @@ TEST(WasmRefAsNonNull) {
|
||||
ValueType kOptRefType = optref(type_index);
|
||||
FunctionSig sig_q_v(1, 0, kRefTypes);
|
||||
|
||||
uint32_t k_global_index = tester.AddGlobal(
|
||||
uint32_t global_index = tester.AddGlobal(
|
||||
kOptRefType, true, WasmInitExpr(WasmInitExpr::kRefNullConst));
|
||||
uint32_t k_field_index = 0;
|
||||
uint32_t field_index = 0;
|
||||
tester.DefineFunction(
|
||||
"f", tester.sigs.i_v(), {},
|
||||
{WASM_SET_GLOBAL(
|
||||
k_global_index,
|
||||
WASM_STRUCT_NEW(type_index, WASM_I32V(55), WASM_I32V(66))),
|
||||
{WASM_SET_GLOBAL(global_index, WASM_STRUCT_NEW(type_index, WASM_I32V(55),
|
||||
WASM_I32V(66))),
|
||||
WASM_STRUCT_GET(
|
||||
type_index, k_field_index,
|
||||
WASM_REF_AS_NON_NULL(WASM_IF_ELSE_R(kOptRefType, WASM_I32V(1),
|
||||
WASM_GET_GLOBAL(k_global_index),
|
||||
WASM_REF_NULL(type_index)))),
|
||||
type_index, field_index,
|
||||
WASM_REF_AS_NON_NULL(WASM_IF_ELSE_R(
|
||||
kOptRefType, WASM_I32V(1), WASM_GET_GLOBAL(global_index),
|
||||
WASM_REF_NULL(static_cast<byte>(type_index))))),
|
||||
kExprEnd});
|
||||
|
||||
tester.CompileModule();
|
||||
@ -265,30 +264,30 @@ TEST(WasmBrOnNull) {
|
||||
|
||||
TEST(WasmRefEq) {
|
||||
WasmGCTester tester;
|
||||
uint32_t type_index =
|
||||
tester.DefineStruct({F(kWasmI32, true), F(kWasmI32, true)});
|
||||
byte type_index = static_cast<byte>(
|
||||
tester.DefineStruct({F(kWasmI32, true), F(kWasmI32, true)}));
|
||||
ValueType kRefTypes[] = {ref(type_index)};
|
||||
ValueType kOptRefType = optref(type_index);
|
||||
FunctionSig sig_q_v(1, 0, kRefTypes);
|
||||
|
||||
uint32_t n_local_index = 0;
|
||||
byte local_index = 0;
|
||||
tester.DefineFunction(
|
||||
"f", tester.sigs.i_v(), {kOptRefType},
|
||||
{WASM_SET_LOCAL(n_local_index, WASM_STRUCT_NEW(type_index, WASM_I32V(55),
|
||||
WASM_I32V(66))),
|
||||
{WASM_SET_LOCAL(local_index, WASM_STRUCT_NEW(type_index, WASM_I32V(55),
|
||||
WASM_I32V(66))),
|
||||
WASM_I32_ADD(
|
||||
WASM_I32_SHL(WASM_REF_EQ( // true
|
||||
WASM_GET_LOCAL(n_local_index),
|
||||
WASM_GET_LOCAL(n_local_index)),
|
||||
WASM_I32V(0)),
|
||||
WASM_I32_SHL(
|
||||
WASM_REF_EQ( // true
|
||||
WASM_GET_LOCAL(local_index), WASM_GET_LOCAL(local_index)),
|
||||
WASM_I32V(0)),
|
||||
WASM_I32_ADD(
|
||||
WASM_I32_SHL(WASM_REF_EQ( // false
|
||||
WASM_GET_LOCAL(n_local_index),
|
||||
WASM_GET_LOCAL(local_index),
|
||||
WASM_STRUCT_NEW(type_index, WASM_I32V(55),
|
||||
WASM_I32V(66))),
|
||||
WASM_I32V(1)),
|
||||
WASM_I32_ADD(WASM_I32_SHL( // false
|
||||
WASM_REF_EQ(WASM_GET_LOCAL(n_local_index),
|
||||
WASM_REF_EQ(WASM_GET_LOCAL(local_index),
|
||||
WASM_REF_NULL(type_index)),
|
||||
WASM_I32V(2)),
|
||||
WASM_I32_SHL(WASM_REF_EQ( // true
|
||||
@ -380,7 +379,7 @@ TEST(WasmLetInstruction) {
|
||||
uint32_t let_field_index = 0;
|
||||
tester.DefineFunction(
|
||||
"let_test_1", tester.sigs.i_v(), {},
|
||||
{WASM_LET_1_I(WASM_REF_TYPE(type_index),
|
||||
{WASM_LET_1_I(WASM_SEQ(kLocalRef, static_cast<byte>(type_index)),
|
||||
WASM_STRUCT_NEW(type_index, WASM_I32V(42), WASM_I32V(52)),
|
||||
WASM_STRUCT_GET(type_index, let_field_index,
|
||||
WASM_GET_LOCAL(let_local_index))),
|
||||
@ -390,7 +389,7 @@ TEST(WasmLetInstruction) {
|
||||
tester.DefineFunction(
|
||||
"let_test_2", tester.sigs.i_v(), {},
|
||||
{WASM_LET_2_I(kLocalI32, WASM_I32_ADD(WASM_I32V(42), WASM_I32V(-32)),
|
||||
WASM_REF_TYPE(type_index),
|
||||
WASM_SEQ(kLocalRef, static_cast<byte>(type_index)),
|
||||
WASM_STRUCT_NEW(type_index, WASM_I32V(42), WASM_I32V(52)),
|
||||
WASM_I32_MUL(WASM_STRUCT_GET(type_index, let_2_field_index,
|
||||
WASM_GET_LOCAL(1)),
|
||||
|
@ -83,19 +83,23 @@
|
||||
#define DEPTH_2 2
|
||||
#define ARITY_2 2
|
||||
|
||||
#define WASM_HEAP_TYPE(heap_type) static_cast<byte>(0x7F & heap_type.code())
|
||||
|
||||
#define WASM_REF_TYPE(type) \
|
||||
static_cast<byte>(type.kind() == ValueType::kRef ? kLocalRef \
|
||||
: kLocalOptRef), \
|
||||
WASM_HEAP_TYPE(type.heap_type())
|
||||
|
||||
#define WASM_BLOCK(...) kExprBlock, kLocalVoid, __VA_ARGS__, kExprEnd
|
||||
#define WASM_BLOCK_I(...) kExprBlock, kLocalI32, __VA_ARGS__, kExprEnd
|
||||
#define WASM_BLOCK_L(...) kExprBlock, kLocalI64, __VA_ARGS__, kExprEnd
|
||||
#define WASM_BLOCK_F(...) kExprBlock, kLocalF32, __VA_ARGS__, kExprEnd
|
||||
#define WASM_BLOCK_D(...) kExprBlock, kLocalF64, __VA_ARGS__, kExprEnd
|
||||
|
||||
#define TYPE_IMM(t) \
|
||||
static_cast<byte>((t).value_type_code()), U32V_1((t).ref_index())
|
||||
|
||||
#define WASM_BLOCK_T(t, ...) \
|
||||
kExprBlock, static_cast<byte>((t).value_type_code()), __VA_ARGS__, kExprEnd
|
||||
|
||||
#define WASM_BLOCK_R(t, ...) kExprBlock, TYPE_IMM(t), __VA_ARGS__, kExprEnd
|
||||
#define WASM_BLOCK_R(type, ...) \
|
||||
kExprBlock, WASM_REF_TYPE(type), __VA_ARGS__, kExprEnd
|
||||
|
||||
#define WASM_BLOCK_X(index, ...) \
|
||||
kExprBlock, static_cast<byte>(index), __VA_ARGS__, kExprEnd
|
||||
@ -124,7 +128,7 @@
|
||||
#define WASM_IF_R(t, cond, ...) \
|
||||
cond, kExprIf, TYPE_IMM(t), __VA_ARGS__, kExprEnd
|
||||
|
||||
#define WASM_IF_X(index, cond, ...) \
|
||||
#define WASM_IF_X(index, cond, ...) \
|
||||
cond, kExprIf, static_cast<byte>(index), __VA_ARGS__, kExprEnd
|
||||
|
||||
#define WASM_IF_ELSE(cond, tstmt, fstmt) \
|
||||
@ -144,7 +148,7 @@
|
||||
fstmt, kExprEnd
|
||||
|
||||
#define WASM_IF_ELSE_R(t, cond, tstmt, fstmt) \
|
||||
cond, kExprIf, TYPE_IMM(t), tstmt, kExprElse, fstmt, kExprEnd
|
||||
cond, kExprIf, WASM_REF_TYPE(t), tstmt, kExprElse, fstmt, kExprEnd
|
||||
|
||||
#define WASM_IF_ELSE_X(index, cond, tstmt, fstmt) \
|
||||
cond, kExprIf, static_cast<byte>(index), tstmt, kExprElse, fstmt, kExprEnd
|
||||
@ -153,7 +157,7 @@
|
||||
kExprTry, static_cast<byte>((t).value_type_code()), trystmt, kExprCatch, \
|
||||
catchstmt, kExprEnd
|
||||
#define WASM_TRY_CATCH_R(t, trystmt, catchstmt) \
|
||||
kExprTry, TYPE_IMM(t), trystmt, kExprCatch, catchstmt, kExprEnd
|
||||
kExprTry, WASM_REF_TYPE(t), trystmt, kExprCatch, catchstmt, kExprEnd
|
||||
|
||||
#define WASM_SELECT(tval, fval, cond) tval, fval, cond, kExprSelect
|
||||
#define WASM_SELECT_I(tval, fval, cond) \
|
||||
@ -440,7 +444,7 @@ inline WasmOpcode LoadStoreOpcodeOf(MachineType type, bool store) {
|
||||
#define WASM_STRUCT_SET(typeidx, fieldidx, struct_obj, value) \
|
||||
struct_obj, value, WASM_GC_OP(kExprStructSet), static_cast<byte>(typeidx), \
|
||||
static_cast<byte>(fieldidx)
|
||||
#define WASM_REF_NULL(type) kExprRefNull, static_cast<byte>(type)
|
||||
#define WASM_REF_NULL(type_encoding) kExprRefNull, type_encoding
|
||||
#define WASM_REF_FUNC(val) kExprRefFunc, val
|
||||
#define WASM_REF_IS_NULL(val) val, kExprRefIsNull
|
||||
#define WASM_REF_AS_NON_NULL(val) val, kExprRefAsNonNull
|
||||
@ -485,7 +489,6 @@ inline WasmOpcode LoadStoreOpcodeOf(MachineType type, bool store) {
|
||||
#define WASM_RETURN_CALL_INDIRECT(sig_index, ...) \
|
||||
__VA_ARGS__, kExprReturnCallIndirect, static_cast<byte>(sig_index), TABLE_ZERO
|
||||
|
||||
#define WASM_REF_TYPE(typeidx) kLocalOptRef, U32V_1(typeidx)
|
||||
#define WASM_RTT(depth, typeidx) kLocalRtt, U32V_1(depth), U32V_1(typeidx)
|
||||
|
||||
// shift locals by 1; let (locals[0]: local_type) = value in ...
|
||||
|
@ -13,12 +13,8 @@ namespace subtyping_unittest {
|
||||
class WasmSubtypingTest : public TestWithZone {};
|
||||
using FieldInit = std::pair<ValueType, bool>;
|
||||
|
||||
ValueType ref(uint32_t index) {
|
||||
return ValueType::Ref(static_cast<HeapType>(index), kNonNullable);
|
||||
}
|
||||
ValueType optRef(uint32_t index) {
|
||||
return ValueType::Ref(static_cast<HeapType>(index), kNullable);
|
||||
}
|
||||
ValueType ref(uint32_t index) { return ValueType::Ref(index, kNonNullable); }
|
||||
ValueType optRef(uint32_t index) { return ValueType::Ref(index, kNullable); }
|
||||
|
||||
FieldInit mut(ValueType type) { return FieldInit(type, true); }
|
||||
FieldInit immut(ValueType type) { return FieldInit(type, false); }
|
||||
|
Loading…
Reference in New Issue
Block a user