summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2022-11-15 08:39:03 -0800
committerGitHub <noreply@github.com>2022-11-15 08:39:03 -0800
commitb2054b72b7daa89b7ad161c0693befad06a20c90 (patch)
tree3f2691dadc7af9ee6c86d701ebfebcb8e525c843 /src/wasm
parent8225e485a24c5fa6fffb0c9f0a3ee8615bcfa0d9 (diff)
downloadbinaryen-b2054b72b7daa89b7ad161c0693befad06a20c90.tar.gz
binaryen-b2054b72b7daa89b7ad161c0693befad06a20c90.tar.bz2
binaryen-b2054b72b7daa89b7ad161c0693befad06a20c90.zip
Make `call_ref` type annotations mandatory (#5246)
They were optional for a while to allow users to gracefully transition to using them, but now make them mandatory to match the upstream WasmGC spec.
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-binary.cpp31
-rw-r--r--src/wasm/wasm-s-parser.cpp35
2 files changed, 16 insertions, 50 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index e2bb0075b..782979520 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -3846,15 +3846,12 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) {
visitMemoryGrow(grow);
break;
}
- case BinaryConsts::CallRefUnannotated:
- visitCallRef((curr = allocator.alloc<CallRef>())->cast<CallRef>());
- break;
case BinaryConsts::CallRef:
case BinaryConsts::RetCallRef: {
auto call = allocator.alloc<CallRef>();
call->isReturn = code == BinaryConsts::RetCallRef;
curr = call;
- visitCallRef(call, getTypeByIndex(getU32LEB()));
+ visitCallRef(call);
break;
}
case BinaryConsts::AtomicPrefix: {
@@ -6851,29 +6848,13 @@ void WasmBinaryBuilder::visitRethrow(Rethrow* curr) {
curr->finalize();
}
-void WasmBinaryBuilder::visitCallRef(CallRef* curr,
- std::optional<HeapType> maybeType) {
+void WasmBinaryBuilder::visitCallRef(CallRef* curr) {
BYN_TRACE("zz node: CallRef\n");
curr->target = popNonVoidExpression();
- HeapType heapType;
- if (maybeType) {
- heapType = *maybeType;
- if (!Type::isSubType(curr->target->type, Type(heapType, Nullable))) {
- throwError("Call target has invalid type: " +
- curr->target->type.toString());
- }
- } else {
- auto type = curr->target->type;
- if (type == Type::unreachable) {
- // If our input is unreachable, then we cannot even find out how many
- // inputs we have, and just set ourselves to unreachable as well.
- curr->finalize(type);
- return;
- }
- if (!type.isRef()) {
- throwError("Non-ref type for a call_ref: " + type.toString());
- }
- heapType = type.getHeapType();
+ HeapType heapType = getTypeByIndex(getU32LEB());
+ if (!Type::isSubType(curr->target->type, Type(heapType, Nullable))) {
+ throwError("Call target has invalid type: " +
+ curr->target->type.toString());
}
if (!heapType.isSignature()) {
throwError("Invalid reference type for a call_ref: " + heapType.toString());
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index a9fd2de77..ab6230442 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -2744,35 +2744,20 @@ Expression* SExpressionWasmBuilder::makeTupleExtract(Element& s) {
}
Expression* SExpressionWasmBuilder::makeCallRef(Element& s, bool isReturn) {
- Index operandsStart = 1;
- std::optional<HeapType> sigType;
- try {
- sigType = parseHeapType(*s[1]);
- operandsStart = 2;
- } catch (ParseException& p) {
- // The type annotation is required for return_call_ref but temporarily
- // optional for call_ref.
- if (isReturn) {
- throw;
- }
- }
+ HeapType sigType = parseHeapType(*s[1]);
std::vector<Expression*> operands;
- parseOperands(s, operandsStart, s.size() - 1, operands);
+ parseOperands(s, 2, s.size() - 1, operands);
auto* target = parseExpression(s[s.size() - 1]);
- if (sigType) {
- if (!sigType->isSignature()) {
- throw ParseException(
- std::string(isReturn ? "return_call_ref" : "call_ref") +
- " type annotation should be a signature",
- s.line,
- s.col);
- }
- return Builder(wasm).makeCallRef(
- target, operands, sigType->getSignature().results, isReturn);
+ if (!sigType.isSignature()) {
+ throw ParseException(
+ std::string(isReturn ? "return_call_ref" : "call_ref") +
+ " type annotation should be a signature",
+ s.line,
+ s.col);
}
- return ValidatingBuilder(wasm, s.line, s.col)
- .validateAndMakeCallRef(target, operands, isReturn);
+ return Builder(wasm).makeCallRef(
+ target, operands, sigType.getSignature().results, isReturn);
}
Expression* SExpressionWasmBuilder::makeI31New(Element& s) {