diff options
Diffstat (limited to 'src/wasm/wasm.cpp')
-rw-r--r-- | src/wasm/wasm.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index c3f262998..552ec7e57 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -947,10 +947,24 @@ void RefCast::finalize() { type = Type::unreachable; return; } - // Do not unnecessarily lose non-nullability information. + + // 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()); + } } void BrOn::finalize() { |