From 48eb700ba16e8c98c4283fdde2064b78c3561fbd Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 13 May 2022 10:11:01 -0700 Subject: [NFC] Make Literal::makeNull take a HeapType (#4664) Taking a Type is redundant as we only care about the heap type - the nullability must be Nullable. This avoids needing an assertion in the function, that is, it makes the API more type-safe. --- src/binaryen-c.cpp | 2 +- src/literal.h | 5 ++--- src/wasm-interpreter.h | 6 +++--- src/wasm/literal.cpp | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index aa9f7e641..709672aa4 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -101,7 +101,7 @@ Literal fromBinaryenLiteral(BinaryenLiteral x) { return Literal::makeFunc(x.func); case Type::anyref: case Type::eqref: - return Literal::makeNull(Type(x.type)); + return Literal::makeNull(Type(x.type).getHeapType()); case Type::i31ref: WASM_UNREACHABLE("TODO: i31ref"); case Type::dataref: diff --git a/src/literal.h b/src/literal.h index 555f89e5c..4caeab9d4 100644 --- a/src/literal.h +++ b/src/literal.h @@ -248,9 +248,8 @@ public: WASM_UNREACHABLE("unexpected type"); } } - static Literal makeNull(Type type) { - assert(type.isNullable()); - return Literal(type); + static Literal makeNull(HeapType type) { + return Literal(Type(type, Nullable)); } static Literal makeFunc(Name func, Type type = Type::funcref) { return Literal(func, type); diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 641684fe9..ef86b35f0 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -1337,7 +1337,7 @@ public: Flow visitCallRef(CallRef* curr) { WASM_UNREACHABLE("unimp"); } Flow visitRefNull(RefNull* curr) { NOTE_ENTER("RefNull"); - return Literal::makeNull(curr->type); + return Literal::makeNull(curr->type.getHeapType()); } Flow visitRefIs(RefIs* curr) { NOTE_ENTER("RefIs"); @@ -1531,7 +1531,7 @@ public: if (auto* breaking = cast.getBreaking()) { return *breaking; } else if (cast.getNull()) { - return Literal::makeNull(Type(curr->type.getHeapType(), Nullable)); + return Literal::makeNull(curr->type.getHeapType()); } else if (auto* result = cast.getSuccess()) { return *result; } @@ -2573,7 +2573,7 @@ private: if (table->type.isNullable()) { // Initial with nulls in a nullable table. auto info = getTableInterfaceInfo(table->name); - auto null = Literal::makeNull(table->type); + auto null = Literal::makeNull(table->type.getHeapType()); for (Address i = 0; i < table->initial; i++) { info.interface->tableStore(info.name, i, null); } diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index b7bb83155..80af9535e 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -238,7 +238,7 @@ Literal Literal::makeZero(Type type) { if (type == Type::i31ref) { return makeI31(0); } else { - return makeNull(type); + return makeNull(type.getHeapType()); } } else if (type.isRtt()) { return Literal(type); -- cgit v1.2.3