Skip to content

Commit 18fcad6

Browse files
authored
Allow subtypes in tuple operations (#2700)
Some optimizations may replace tuple elements with simpler values, and those simpler values may be a subtype of the original value. Tuple operations should continue to validate without being refinalized in these cases.
1 parent 03ae7fc commit 18fcad6

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/wasm/wasm-validator.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,9 +1917,10 @@ void FunctionValidator::visitTupleMake(TupleMake* curr) {
19171917
}
19181918
types.push_back(op->type);
19191919
}
1920-
shouldBeTrue(Type(types) == curr->type,
1921-
curr,
1922-
"Type of tuple.make does not match types of its operands");
1920+
shouldBeSubType(Type(types),
1921+
curr->type,
1922+
curr,
1923+
"Type of tuple.make does not match types of its operands");
19231924
}
19241925

19251926
void FunctionValidator::visitTupleExtract(TupleExtract* curr) {
@@ -1929,13 +1930,15 @@ void FunctionValidator::visitTupleExtract(TupleExtract* curr) {
19291930
curr,
19301931
"If tuple.extract has an unreachable operand, it must be unreachable");
19311932
} else {
1932-
shouldBeTrue(curr->index < curr->tuple->type.size(),
1933-
curr,
1934-
"tuple.extract index out of bounds");
1935-
shouldBeTrue(
1936-
curr->type == curr->tuple->type.expand()[curr->index],
1937-
curr,
1938-
"tuple.extract type does not match the type of the extracted element");
1933+
bool inBounds = curr->index < curr->tuple->type.size();
1934+
shouldBeTrue(inBounds, curr, "tuple.extract index out of bounds");
1935+
if (inBounds) {
1936+
shouldBeSubType(
1937+
curr->tuple->type.expand()[curr->index],
1938+
curr->type,
1939+
curr,
1940+
"tuple.extract type does not match the type of the extracted element");
1941+
}
19391942
}
19401943
}
19411944

0 commit comments

Comments
 (0)