summaryrefslogtreecommitdiff
path: root/src/wasm-builder.h
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2022-07-20 20:13:18 -0700
committerGitHub <noreply@github.com>2022-07-20 20:13:18 -0700
commitda5035f893ce9e046f99cf3ede92b576024aa9da (patch)
tree9db48e77502a646d74ef1a9d11f9b8f0967ff856 /src/wasm-builder.h
parent1c53f7dd29e79bc1894959cad817b22f087689f7 (diff)
downloadbinaryen-da5035f893ce9e046f99cf3ede92b576024aa9da.tar.gz
binaryen-da5035f893ce9e046f99cf3ede92b576024aa9da.tar.bz2
binaryen-da5035f893ce9e046f99cf3ede92b576024aa9da.zip
Remove basic reference types (#4802)
Basic reference types like `Type::funcref`, `Type::anyref`, etc. made it easy to accidentally forget to handle reference types with the same basic HeapTypes but the opposite nullability. In principle there is nothing special about the types with shorthands except in the binary and text formats. Removing these shorthands from the internal type representation by removing all basic reference types makes some code more complicated locally, but simplifies code globally and encourages properly handling both nullable and non-nullable reference types.
Diffstat (limited to 'src/wasm-builder.h')
-rw-r--r--src/wasm-builder.h33
1 files changed, 11 insertions, 22 deletions
diff --git a/src/wasm-builder.h b/src/wasm-builder.h
index eec86bc50..d76d24b21 100644
--- a/src/wasm-builder.h
+++ b/src/wasm-builder.h
@@ -82,7 +82,8 @@ public:
}
static std::unique_ptr<Table> makeTable(Name name,
- Type type = Type::funcref,
+ Type type = Type(HeapType::func,
+ Nullable),
Address initial = 0,
Address max = Table::kMaxSize) {
auto table = std::make_unique<Table>();
@@ -97,7 +98,7 @@ public:
makeElementSegment(Name name,
Name table,
Expression* offset = nullptr,
- Type type = Type::funcref) {
+ Type type = Type(HeapType::func, Nullable)) {
auto seg = std::make_unique<ElementSegment>();
seg->name = name;
seg->table = table;
@@ -1114,20 +1115,14 @@ public:
if (type.isFunction()) {
return makeRefFunc(value.getFunc(), type.getHeapType());
}
+ if (type.isRef() && type.getHeapType() == HeapType::i31) {
+ return makeI31New(makeConst(value.geti31()));
+ }
if (type.isRtt()) {
return makeRtt(value.type);
}
TODO_SINGLE_COMPOUND(type);
- switch (type.getBasic()) {
- case Type::anyref:
- case Type::eqref:
- assert(value.isNull() && "unexpected non-null reference type literal");
- return makeRefNull(type);
- case Type::i31ref:
- return makeI31New(makeConst(value.geti31()));
- default:
- WASM_UNREACHABLE("invalid constant expression");
- }
+ WASM_UNREACHABLE("unsupported constant expression");
}
Expression* makeConstantExpression(Literals values) {
@@ -1273,7 +1268,10 @@ public:
if (curr->type.isNullable()) {
return ExpressionManipulator::refNull(curr, curr->type);
}
- if (curr->type.isFunction() || !curr->type.isBasic()) {
+ if (curr->type.isRef() && curr->type.getHeapType() == HeapType::i31) {
+ return makeI31New(makeConst(0));
+ }
+ if (!curr->type.isBasic()) {
// We can't do any better, keep the original.
return curr;
}
@@ -1298,15 +1296,6 @@ public:
value = Literal(bytes.data());
break;
}
- case Type::funcref:
- WASM_UNREACHABLE("handled above");
- case Type::anyref:
- case Type::eqref:
- return ExpressionManipulator::refNull(curr, curr->type);
- case Type::i31ref:
- return makeI31New(makeConst(0));
- case Type::dataref:
- return curr;
case Type::none:
return ExpressionManipulator::nop(curr);
case Type::unreachable: