From 4201ed3d8799555a8fd08f4a44032fc7169b1edd Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 12 Dec 2025 18:09:07 -0500 Subject: [PATCH] AST: Canonicalize opaque archetype substitution maps in the solver arena Preserving sugar if we have type variables uses way too much memory. Canonicalize these substitution maps for now, as a (temporary?) workaround. In the future, if we decide preserving sugar is more important than a few dozen Mb of memory usage, we can also bump the arena memory limit, instead. Fixes rdar://166237860. Fixes rdar://165863647. --- lib/AST/ASTContext.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 1b359c0e843f5..8e0e0a74868e0 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -6086,6 +6086,11 @@ GenericEnvironment *GenericEnvironment::forPrimary(GenericSignature signature) { /// outer substitutions. GenericEnvironment *GenericEnvironment::forOpaqueType( OpaqueTypeDecl *opaque, SubstitutionMap subs) { + // Don't preserve sugar if we have type variables, because this leads to + // excessive solver arena memory usage. + if (subs.getRecursiveProperties().hasTypeVariable()) + subs = subs.getCanonical(); + auto &ctx = opaque->getASTContext(); auto properties = ArchetypeType::archetypeProperties(