From 58bedde3ac54f82657d5de092e7142ffb2ff735c Mon Sep 17 00:00:00 2001 From: Thomas Lively <7121787+tlively@users.noreply.github.com> Date: Thu, 22 Sep 2022 18:00:50 -0500 Subject: Add a type annotation to return_call_ref (#5068) The GC spec has been updated to have heap type annotations on call_ref and return_call_ref. To avoid breaking users, we will have a graceful, multi-step upgrade to the annotated version of call_ref, but since return_call_ref has no users yet, update it in a single step. --- src/passes/Print.cpp | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 'src/passes/Print.cpp') diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index d1e08e0ec..04d487c08 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -2043,9 +2043,31 @@ struct PrintExpressionContents void visitI31Get(I31Get* curr) { printMedium(o, curr->signed_ ? "i31.get_s" : "i31.get_u"); } + + // If we cannot print a valid unreachable instruction (say, a struct.get, + // where if the ref is unreachable, we don't know what heap type to print), + // then print the children in a block, which is good enough as this + // instruction is never reached anyhow. + // + // This function checks if the input is in fact unreachable, and if so, begins + // to emit a replacement for it and returns true. + bool printUnreachableReplacement(Expression* curr) { + if (curr->type == Type::unreachable) { + printMedium(o, "block"); + return true; + } + return false; + } + void visitCallRef(CallRef* curr) { if (curr->isReturn) { - printMedium(o, "return_call_ref"); + if (printUnreachableReplacement(curr->target)) { + return; + } + printMedium(o, "return_call_ref "); + assert(curr->target->type != Type::unreachable); + // TODO: Workaround if target has bottom type. + printHeapType(o, curr->target->type.getHeapType(), wasm); } else { printMedium(o, "call_ref"); } @@ -2106,22 +2128,6 @@ struct PrintExpressionContents } printName(curr->name, o); } - - // If we cannot print a valid unreachable instruction (say, a struct.get, - // where if the ref is unreachable, we don't know what heap type to print), - // then print the children in a block, which is good enough as this - // instruction is never reached anyhow. - // - // This function checks if the input is in fact unreachable, and if so, begins - // to emit a replacement for it and returns true. - bool printUnreachableReplacement(Expression* curr) { - if (curr->type == Type::unreachable) { - printMedium(o, "block"); - return true; - } - return false; - } - void visitStructNew(StructNew* curr) { if (printUnreachableReplacement(curr)) { return; @@ -2748,6 +2754,13 @@ struct PrintSExpression : public UnifiedExpressionVisitor { } decIndent(); } + void visitCallRef(CallRef* curr) { + if (curr->isReturn) { + maybePrintUnreachableReplacement(curr, curr->target->type); + } else { + visitExpression(curr); + } + } void visitStructNew(StructNew* curr) { maybePrintUnreachableReplacement(curr, curr->type); } -- cgit v1.2.3