Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions src/wasm/wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ void MemoryGrow::finalize() {

void RefNull::finalize(HeapType heapType) {
assert(heapType.isBottom());
// TODO: Make this exact.
type = Type(heapType, Nullable);
}

Expand Down Expand Up @@ -922,6 +923,7 @@ static void populateTryTableSentTypes(TryTable* curr, Module* wasm) {
// wasm spec defines when GC is enabled (=== non-nullable types are allowed).
// If GC is not enabled then we emit a nullable type in the binary format in
// WasmBinaryWriter::writeType.
// TODO: Make this exact.
Type exnref = Type(HeapType::exn, NonNullable);
for (Index i = 0; i < curr->catchTags.size(); i++) {
auto tagName = curr->catchTags[i];
Expand Down Expand Up @@ -976,6 +978,7 @@ void RefI31::finalize() {
if (value->type == Type::unreachable) {
type = Type::unreachable;
} else {
// TODO: Make this exact.
assert(type.isRef() && type.getHeapType().isMaybeShared(HeapType::i31));
}
}
Expand Down Expand Up @@ -1011,10 +1014,12 @@ void CallRef::finalize() {
// unreachable instead (and similar in other GC accessors), although this
// would currently cause the parser to admit more invalid modules.
if (type.isRef()) {
// TODO: Make this exact.
type = Type(type.getHeapType().getBottom(), NonNullable);
} else if (type.isTuple()) {
Tuple elems;
for (auto t : type) {
// TODO: Make this exact.
elems.push_back(
t.isRef() ? Type(t.getHeapType().getBottom(), NonNullable) : t);
}
Expand Down Expand Up @@ -1071,7 +1076,8 @@ void BrOn::finalize() {
switch (op) {
case BrOnNull:
// If we do not branch, we flow out the existing value as non-null.
type = Type(ref->type.getHeapType(), NonNullable);
type =
Type(ref->type.getHeapType(), NonNullable, ref->type.getExactness());
break;
case BrOnNonNull:
// If we do not branch, we flow out nothing (the spec could also have had
Expand All @@ -1081,7 +1087,8 @@ void BrOn::finalize() {
case BrOnCast:
if (castType.isNullable()) {
// Nulls take the branch, so the result is non-nullable.
type = Type(ref->type.getHeapType(), NonNullable);
type =
Type(ref->type.getHeapType(), NonNullable, ref->type.getExactness());
} else {
// Nulls do not take the branch, so the result is non-nullable only if
// the input is.
Expand All @@ -1092,7 +1099,9 @@ void BrOn::finalize() {
if (castType.isNullable()) {
// Nulls do not take the branch, so the result is non-nullable only if
// the input is.
type = Type(castType.getHeapType(), ref->type.getNullability());
type = Type(castType.getHeapType(),
ref->type.getNullability(),
castType.getExactness());
} else {
// Nulls take the branch, so the result is non-nullable.
type = castType;
Expand All @@ -1115,11 +1124,14 @@ Type BrOn::getSentType() {
return Type::unreachable;
}
// BrOnNonNull sends the non-nullable type on the branch.
return Type(ref->type.getHeapType(), NonNullable);
return Type(
ref->type.getHeapType(), NonNullable, ref->type.getExactness());
case BrOnCast:
// The same as the result type of br_on_cast_fail.
if (castType.isNullable()) {
return Type(castType.getHeapType(), ref->type.getNullability());
return Type(castType.getHeapType(),
ref->type.getNullability(),
castType.getExactness());
} else {
return castType;
}
Expand All @@ -1129,7 +1141,8 @@ Type BrOn::getSentType() {
return Type::unreachable;
}
if (castType.isNullable()) {
return Type(ref->type.getHeapType(), NonNullable);
return Type(
ref->type.getHeapType(), NonNullable, ref->type.getExactness());
} else {
return ref->type;
}
Expand All @@ -1150,6 +1163,7 @@ void StructGet::finalize() {
} else if (ref->type.isNull()) {
// See comment on CallRef for explanation.
if (type.isRef()) {
// TODO: Make this exact.
type = Type(type.getHeapType().getBottom(), NonNullable);
}
} else {
Expand Down Expand Up @@ -1225,6 +1239,7 @@ void ArrayGet::finalize() {
} else if (ref->type.isNull()) {
// See comment on CallRef for explanation.
if (type.isRef()) {
// TODO: Make this exact.
type = Type(type.getHeapType().getBottom(), NonNullable);
}
} else {
Expand Down Expand Up @@ -1302,15 +1317,17 @@ void RefAs::finalize() {
auto valHeapType = value->type.getHeapType();
switch (op) {
case RefAsNonNull:
type = Type(valHeapType, NonNullable);
type = Type(valHeapType, NonNullable, value->type.getExactness());
break;
case AnyConvertExtern:
type = Type(HeapTypes::any.getBasic(valHeapType.getShared()),
value->type.getNullability());
value->type.getNullability(),
Inexact);
break;
case ExternConvertAny:
type = Type(HeapTypes::ext.getBasic(valHeapType.getShared()),
value->type.getNullability());
value->type.getNullability(),
Inexact);
break;
default:
WASM_UNREACHABLE("invalid ref.as_*");
Expand All @@ -1323,11 +1340,15 @@ void StringNew::finalize() {
(end && end->type == Type::unreachable)) {
type = Type::unreachable;
} else {
// TODO: Make this exact.
type = Type(HeapType::string, NonNullable);
}
}

void StringConst::finalize() { type = Type(HeapType::string, NonNullable); }
void StringConst::finalize() {
// TODO: Make this exact.
type = Type(HeapType::string, NonNullable);
}

void StringMeasure::finalize() {
if (ref->type == Type::unreachable) {
Expand All @@ -1350,6 +1371,7 @@ void StringConcat::finalize() {
if (left->type == Type::unreachable || right->type == Type::unreachable) {
type = Type::unreachable;
} else {
// TODO: Make this exact.
type = Type(HeapType::string, NonNullable);
}
}
Expand All @@ -1375,6 +1397,7 @@ void StringSliceWTF::finalize() {
end->type == Type::unreachable) {
type = Type::unreachable;
} else {
// TODO: Make this exact.
type = Type(HeapType::string, NonNullable);
}
}
Expand Down
Loading