[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 <jkummerow@chromium.org>
Auto-Submit: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: Matthias Liedtke <mliedtke@chromium.org>
Cr-Commit-Position: refs/heads/main@{#85685}
This commit is contained in:
Jakob Kummerow 2023-02-06 15:31:05 +01:00 committed by V8 LUCI CQ
parent e0d7681e31
commit 5472313c96

View File

@ -5128,27 +5128,29 @@ class WasmFullDecoder : public WasmDecoder<ValidationTag, decoding_mode> {
// 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);