summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/wasm/wasm.cpp27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index 648a25d9e..74b944bb6 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -948,23 +948,18 @@ void RefCast::finalize() {
return;
}
- // Do not unnecessarily lose non-nullability info. We could leave this for
- // optimizations, but doing it here as part of finalization/refinalization
- // ensures that type information flows through in an optimal manner and can be
- // used as soon as possible.
- if (ref->type.isNonNullable() && type.isNullable()) {
- type = Type(type.getHeapType(), NonNullable);
- }
-
- // Do not unnecessarily lose heap type info, as above for nullability. Note
- // that we must check if the ref has a heap type, as we reach this before
- // validation, which will error if the ref does not in fact have a heap type.
- // (This is a downside of propagating type information here, as opposed to
- // leaving it for an optimization pass.)
- if (ref->type.isRef() &&
- HeapType::isSubType(ref->type.getHeapType(), type.getHeapType())) {
- type = Type(ref->type.getHeapType(), type.getNullability());
+ // We reach this before validation, so the input type might be totally wrong.
+ // Return early in this case to avoid doing the wrong thing below.
+ if (!ref->type.isRef()) {
+ return;
}
+
+ // Do not unnecessarily lose type information. We could leave this for
+ // optimizations (and indeed we do a more powerful version of this in
+ // OptimizeInstructions), but doing it here as part of
+ // finalization/refinalization ensures that type information flows through in
+ // an optimal manner and can be used as soon as possible.
+ type = Type::getGreatestLowerBound(type, ref->type);
}
void BrOn::finalize() {