From dc278daff914c401201c1476035de30dc5bc0bd2 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 13 Jan 2023 10:45:45 -0800 Subject: [Wasm GC] SignaturePruning should not prune fields from a type with subtypes (#5427) For subtyping to not break, we must leave the number of fields equal in both super and subtype, for each such pair. --- src/passes/SignaturePruning.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/passes/SignaturePruning.cpp b/src/passes/SignaturePruning.cpp index 168ef8454..292feeca5 100644 --- a/src/passes/SignaturePruning.cpp +++ b/src/passes/SignaturePruning.cpp @@ -31,6 +31,7 @@ #include "ir/intrinsics.h" #include "ir/lubs.h" #include "ir/module-utils.h" +#include "ir/subtypes.h" #include "ir/type-updating.h" #include "param-utils.h" #include "pass.h" @@ -149,6 +150,13 @@ struct SignaturePruning : public Pass { } } + // A type must have the same number of parameters and results as its + // supertypes and subtypes, so we only attempt to modify types without + // supertypes or subtypes. + // TODO We could handle "cycles" where we remove fields from a group of + // types with subtyping relations at once. + SubTypes subTypes(*module); + // Find parameters to prune. for (auto& [type, funcs] : sigFuncs) { auto sig = type.getSignature(); @@ -160,9 +168,9 @@ struct SignaturePruning : public Pass { continue; } - // A type with a signature supertype cannot be optimized: we'd need to - // remove the field from the super as well, which atm we don't attempt to - // do. TODO + if (!subTypes.getStrictSubTypes(type).empty()) { + continue; + } if (auto super = type.getSuperType()) { if (super->isSignature()) { continue; -- cgit v1.2.3