summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2024-08-19 14:23:29 -0700
committerGitHub <noreply@github.com>2024-08-19 14:23:29 -0700
commit127844ca1f6d182797e925b3d062c3484aaf5c23 (patch)
treef46a4149e8e275e54b9f5cd9d673cb639ac37c2f /src
parent0b05a3ebc7feedfd28f54b6486cf3f2ec1864edb (diff)
downloadbinaryen-127844ca1f6d182797e925b3d062c3484aaf5c23.tar.gz
binaryen-127844ca1f6d182797e925b3d062c3484aaf5c23.tar.bz2
binaryen-127844ca1f6d182797e925b3d062c3484aaf5c23.zip
Print explicit typeuses for non-MVP function types (#6851)
We previously printed explicit typeuses (e.g. `(type $f)`) in function signatures when GC was enabled. But even when GC is not enabled, function types may use non-MVP features that require the explicit typeuse to be printed. Fix the printer to always print the explicit type use for such types. Fixes #6850.
Diffstat (limited to 'src')
-rw-r--r--src/passes/Print.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 3abe1f738..6350347c4 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -2804,13 +2804,21 @@ bool PrintSExpression::maybePrintUnreachableOrNullReplacement(Expression* curr,
return maybePrintUnreachableReplacement(curr, type);
}
+static bool requiresExplicitFuncType(HeapType type) {
+ // When the `(type $f)` in a function's typeuse is omitted, the typeuse
+ // matches or declares an MVP function type. When the intended type is not an
+ // MVP function type, we therefore need the explicit `(type $f)`.
+ return type.isOpen() || type.isShared() || type.getRecGroup().size() > 1;
+}
+
void PrintSExpression::handleSignature(HeapType curr, Name name) {
Signature sig = curr.getSignature();
o << "(func";
if (name.is()) {
o << ' ';
name.print(o);
- if (currModule && currModule->features.hasGC()) {
+ if ((currModule && currModule->features.hasGC()) ||
+ requiresExplicitFuncType(curr)) {
o << " (type ";
printHeapType(curr) << ')';
}
@@ -2947,7 +2955,8 @@ void PrintSExpression::visitDefinedFunction(Function* curr) {
o << '(';
printMajor(o, "func ");
curr->name.print(o);
- if (currModule && currModule->features.hasGC()) {
+ if ((currModule && currModule->features.hasGC()) ||
+ requiresExplicitFuncType(curr->type)) {
o << " (type ";
printHeapType(curr->type) << ')';
}