From 36e2abbcdd22b2b1707757b49fb4ac8844f28e5d Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Tue, 10 Jan 2023 13:53:12 -0600 Subject: Represent ref.as_{func,data,i31} with RefCast (#5413) These operations are deprecated and directly representable as casts, so remove their opcodes in the internal IR and parse them as casts instead. For now, add logic to the printing and binary writing of RefCast to continue emitting the legacy instructions to minimize test changes. The few test changes necessary are because it is no longer valid to perform a ref.as_func on values outside the func type hierarchy now that ref.as_func is subject to the ref.cast validation rules. RefAsExternInternalize, RefAsExternExternalize, and RefAsNonNull are left unmodified. A future PR may remove RefAsNonNull as well, since it is also expressible with casts. --- src/passes/Print.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/passes/Print.cpp') diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 12c185e69..e0d9a46a3 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -2122,6 +2122,23 @@ struct PrintExpressionContents if (curr->safety == RefCast::Unsafe) { printMedium(o, "ref.cast_nop "); } else { + // TODO: These instructions are deprecated. Remove them. + if (auto type = curr->type.getHeapType(); + type.isBasic() && curr->type.isNonNullable()) { + switch (type.getBasic()) { + case HeapType::func: + printMedium(o, "ref.as_func"); + return; + case HeapType::data: + printMedium(o, "ref.as_data"); + return; + case HeapType::i31: + printMedium(o, "ref.as_i31"); + return; + default: + break; + } + } if (curr->type.isNullable()) { printMedium(o, "ref.cast null "); } else { @@ -2329,15 +2346,6 @@ struct PrintExpressionContents case RefAsNonNull: printMedium(o, "ref.as_non_null"); break; - case RefAsFunc: - printMedium(o, "ref.as_func"); - break; - case RefAsData: - printMedium(o, "ref.as_data"); - break; - case RefAsI31: - printMedium(o, "ref.as_i31"); - break; case ExternInternalize: printMedium(o, "extern.internalize"); break; -- cgit v1.2.3