From 570007dbecf86db5ddba8d303896d841fc2b2d27 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Wed, 16 Nov 2022 13:44:33 -0800 Subject: Revert "Make `call_ref` type annotations mandatory (#5246)" (#5265) This reverts commit b2054b72b7daa89b7ad161c0693befad06a20c90. It looks like the necessary V8 change has not rolled out everywhere yet. --- src/wasm/wasm-binary.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'src/wasm/wasm-binary.cpp') diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 782979520..e2bb0075b 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -3846,12 +3846,15 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) { visitMemoryGrow(grow); break; } + case BinaryConsts::CallRefUnannotated: + visitCallRef((curr = allocator.alloc())->cast()); + break; case BinaryConsts::CallRef: case BinaryConsts::RetCallRef: { auto call = allocator.alloc(); call->isReturn = code == BinaryConsts::RetCallRef; curr = call; - visitCallRef(call); + visitCallRef(call, getTypeByIndex(getU32LEB())); break; } case BinaryConsts::AtomicPrefix: { @@ -6848,13 +6851,29 @@ void WasmBinaryBuilder::visitRethrow(Rethrow* curr) { curr->finalize(); } -void WasmBinaryBuilder::visitCallRef(CallRef* curr) { +void WasmBinaryBuilder::visitCallRef(CallRef* curr, + std::optional maybeType) { BYN_TRACE("zz node: CallRef\n"); curr->target = popNonVoidExpression(); - HeapType heapType = getTypeByIndex(getU32LEB()); - if (!Type::isSubType(curr->target->type, Type(heapType, Nullable))) { - throwError("Call target has invalid type: " + - curr->target->type.toString()); + 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(); } if (!heapType.isSignature()) { throwError("Invalid reference type for a call_ref: " + heapType.toString()); -- cgit v1.2.3