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(