From 082dbe25b7377809b1b3dc429cb334fc80fac286 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Fri, 9 Dec 2022 17:56:10 -0600 Subject: Use non-nullable ref.cast for non-nullable input (#5335) We switched from emitting the legacy `ref.cast_static` instruction to emitting `ref.cast null` in #5331, but that wasn't quite correct. The legacy instruction had polymorphic typing so that its output type was nullable if and only if its input type was nullable. In contrast, `ref.cast null` always has a a nullable output type. Fix our output by instead emitting non-nullable `ref.cast` if the output should be non-nullable. Parse `ref.cast` in binary and text forms as well. Since the IR can only represent the legacy polymorphic semantics, disallow unsupported casts from nullable to non-nullable references or vice versa for now. --- src/passes/Print.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/passes/Print.cpp') diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index d700f85f3..68a2d16dc 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -2116,7 +2116,12 @@ struct PrintExpressionContents if (curr->safety == RefCast::Unsafe) { printMedium(o, "ref.cast_nop "); } else { - printMedium(o, "ref.cast null "); + // Emulate legacy polymorphic behavior for now. + if (curr->ref->type.isNullable()) { + printMedium(o, "ref.cast null "); + } else { + printMedium(o, "ref.cast "); + } } printHeapType(o, curr->intendedType, wasm); } -- cgit v1.2.3