From 5472313c96a96a7ef2c2f74b6a9b631bba1a107a Mon Sep 17 00:00:00 2001 From: Jakob Kummerow Date: Mon, 6 Feb 2023 15:31:05 +0100 Subject: [PATCH] [wasm-gc] Update ref.cast_nop to behave like ref.cast This updates the (experimental, unsafe, non-standard) ref.cast_nop to take the same immediate as the new ref.cast. This is being done in order to align with Binaryen, per discussion in https://github.com/WebAssembly/binaryen/pull/5473. Bug: v8:7748 Change-Id: Ifcd2bab95a1601406370939301a5c6dfd854347c Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4224632 Commit-Queue: Jakob Kummerow Auto-Submit: Jakob Kummerow Reviewed-by: Matthias Liedtke Cr-Commit-Position: refs/heads/main@{#85685} --- src/wasm/function-body-decoder-impl.h | 28 ++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/wasm/function-body-decoder-impl.h b/src/wasm/function-body-decoder-impl.h index c52a26a547..9cb7f84722 100644 --- a/src/wasm/function-body-decoder-impl.h +++ b/src/wasm/function-body-decoder-impl.h @@ -5128,27 +5128,29 @@ class WasmFullDecoder : public WasmDecoder { // Temporary non-standard instruction, for performance experiments. if (!VALIDATE(this->enabled_.has_ref_cast_nop())) { this->DecodeError( - "Invalid opcode 0xfb48 (enable with " + "Invalid opcode 0xfb4c (enable with " "--experimental-wasm-ref-cast-nop)"); return 0; } - IndexImmediate imm(this, this->pc_ + opcode_length, "type index", - validate); - if (!this->ValidateType(this->pc_ + opcode_length, imm)) return 0; + HeapTypeImmediate imm(this->enabled_, this, this->pc_ + opcode_length, + validate); + if (!this->Validate(this->pc_ + opcode_length, imm)) return 0; opcode_length += imm.length; + HeapType target_type = imm.type; Value obj = Peek(0); - if (!VALIDATE(IsSubtypeOf(obj.type, kWasmFuncRef, this->module_) || - IsSubtypeOf(obj.type, kWasmStructRef, this->module_) || - IsSubtypeOf(obj.type, kWasmArrayRef, this->module_) || + if (!VALIDATE((obj.type.is_object_reference() && + IsSameTypeHierarchy(obj.type.heap_type(), target_type, + this->module_)) || obj.type.is_bottom())) { - PopTypeError(0, obj, - "subtype of (ref null func), (ref null struct) or (ref " - "null array)"); + this->DecodeError( + obj.pc(), + "Invalid types for %s: %s of type %s has to " + "be in the same reference type hierarchy as (ref %s)", + WasmOpcodes::OpcodeName(opcode), SafeOpcodeNameAt(obj.pc()), + obj.type.name().c_str(), target_type.name().c_str()); return 0; } - Value value = CreateValue(ValueType::RefMaybeNull( - imm.index, - obj.type.is_bottom() ? kNonNullable : obj.type.nullability())); + Value value = CreateValue(ValueType::Ref(target_type)); CALL_INTERFACE_IF_OK_AND_REACHABLE(Forward, obj, &value); Drop(obj); Push(value);