Commit 8ea6d397 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm][cleanup] Reorder parameters of ValueTypes::IsSubType

I realized that the parameter order of ValuesTypes::IsSubType is
inconsistent with the parameter of e.g. DCHECK_LT. DCHECK_LT(a, b) is
satisfied if a < b. For ValueTypes it was the other way around.
ValueTypes::IsSubType(a, b) returned true if b was a subtype of a.

R=mstarzinger@chromium.org

Bug: v8:9183
Change-Id: Ifb192bbecdcfe002ef8ca0887d1497393e16e11e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1649358Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62050}
parent 1eee4e1e
......@@ -1926,7 +1926,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
auto fval = Pop();
auto tval = Pop(0, fval.type);
ValueType type = tval.type == kWasmVar ? fval.type : tval.type;
if (ValueTypes::IsSubType(kWasmAnyRef, type)) {
if (ValueTypes::IsSubType(type, kWasmAnyRef)) {
this->error(
"select without type is only valid for value type inputs");
break;
......@@ -2823,7 +2823,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
V8_INLINE Value Pop(int index, ValueType expected) {
auto val = Pop();
if (!VALIDATE(ValueTypes::IsSubType(expected, val.type) ||
if (!VALIDATE(ValueTypes::IsSubType(val.type, expected) ||
val.type == kWasmVar || expected == kWasmVar)) {
this->errorf(val.pc, "%s[%d] expected type %s, found %s of type %s",
SafeOpcodeNameAt(this->pc_), index,
......@@ -2870,7 +2870,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
for (uint32_t i = 0; i < merge->arity; ++i) {
Value& val = stack_values[i];
Value& old = (*merge)[i];
if (ValueTypes::IsSubType(old.type, val.type)) continue;
if (ValueTypes::IsSubType(val.type, old.type)) continue;
// If {val.type} is polymorphic, which results from unreachable, make
// it more specific by using the merge value's expected type.
// If it is not polymorphic, this is a type error.
......@@ -2941,7 +2941,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
for (uint32_t i = 0; i < num_returns; ++i) {
auto& val = stack_values[i];
ValueType expected_type = this->sig_->GetReturn(i);
if (ValueTypes::IsSubType(expected_type, val.type)) continue;
if (ValueTypes::IsSubType(val.type, expected_type)) continue;
// If {val.type} is polymorphic, which results from unreachable,
// make it more specific by using the return's expected type.
// If it is not polymorphic, this is a type error.
......
......@@ -808,8 +808,8 @@ class ModuleDecoderImpl : public Decoder {
errorf(pos, "out of bounds table index %u", table_index);
break;
}
if (!ValueTypes::IsSubType(module_->tables[table_index].type,
kWasmAnyFunc)) {
if (!ValueTypes::IsSubType(kWasmAnyFunc,
module_->tables[table_index].type)) {
errorf(pos,
"Invalid element segment. Table %u is not of type AnyFunc",
table_index);
......@@ -817,7 +817,7 @@ class ModuleDecoderImpl : public Decoder {
}
} else {
ValueType type = consume_reference_type();
if (!ValueTypes::IsSubType(type, kWasmAnyFunc)) {
if (!ValueTypes::IsSubType(kWasmAnyFunc, type)) {
error(pc_ - 1, "invalid element segment type");
break;
}
......@@ -1269,7 +1269,7 @@ class ModuleDecoderImpl : public Decoder {
ValueTypes::TypeName(module->globals[other_index].type));
}
} else {
if (!ValueTypes::IsSubType(global->type, TypeOf(module, global->init))) {
if (!ValueTypes::IsSubType(TypeOf(module, global->init), global->type)) {
errorf(pos, "type error in global initialization, expected %s, got %s",
ValueTypes::TypeName(global->type),
ValueTypes::TypeName(TypeOf(module, global->init)));
......
......@@ -1068,7 +1068,7 @@ bool InstanceBuilder::ProcessImportedWasmGlobalObject(
return false;
}
bool is_sub_type = ValueTypes::IsSubType(global.type, global_object->type());
bool is_sub_type = ValueTypes::IsSubType(global_object->type(), global.type);
bool is_same_type = global_object->type() == global.type;
bool valid_type = global.mutability ? is_same_type : is_sub_type;
......
......@@ -178,7 +178,7 @@ class StoreType {
// A collection of ValueType-related static methods.
class V8_EXPORT_PRIVATE ValueTypes {
public:
static inline bool IsSubType(ValueType expected, ValueType actual) {
static inline bool IsSubType(ValueType actual, ValueType expected) {
return (expected == actual) ||
(expected == kWasmAnyRef && actual == kWasmNullRef) ||
(expected == kWasmAnyRef && actual == kWasmAnyFunc) ||
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment