@@ -5731,7 +5731,8 @@ OpaqueTypeArchetypeType *OpaqueTypeArchetypeType::getNew(
57315731 ASTContext &ctx = interfaceType->getASTContext ();
57325732 auto mem = ctx.Allocate (size, alignof (OpaqueTypeArchetypeType), arena);
57335733 return ::new (mem)
5734- OpaqueTypeArchetypeType (environment, properties, interfaceType,
5734+ OpaqueTypeArchetypeType (environment->isCanonical () ? &ctx : nullptr ,
5735+ environment, properties, interfaceType,
57355736 conformsTo, superclass, layout);
57365737}
57375738
@@ -5759,6 +5760,7 @@ CanTypeWrapper<ExistentialArchetypeType> ExistentialArchetypeType::getNew(
57595760 void *mem = ctx.Allocate (size, alignof (ExistentialArchetypeType), arena);
57605761
57615762 return CanExistentialArchetypeType (::new (mem) ExistentialArchetypeType (
5763+ environment->isCanonical () ? &ctx : nullptr ,
57625764 environment, interfaceType, conformsTo, superclass, layout,
57635765 properties));
57645766}
@@ -6014,8 +6016,8 @@ GenericEnvironment *GenericEnvironment::forPrimary(GenericSignature signature) {
60146016 unsigned numGenericParams = signature.getGenericParams ().size ();
60156017 size_t bytes = totalSizeToAlloc<SubstitutionMap,
60166018 OpaqueEnvironmentData,
6017- OpenedExistentialEnvironmentData ,
6018- OpenedElementEnvironmentData , Type>(
6019+ ExistentialEnvironmentData ,
6020+ ElementEnvironmentData , Type>(
60196021 0 , 0 , 0 , 0 , numGenericParams);
60206022 void *mem = ctx.Allocate (bytes, alignof (GenericEnvironment));
60216023 return new (mem) GenericEnvironment (signature);
@@ -6025,11 +6027,6 @@ GenericEnvironment *GenericEnvironment::forPrimary(GenericSignature signature) {
60256027// / outer substitutions.
60266028GenericEnvironment *GenericEnvironment::forOpaqueType (
60276029 OpaqueTypeDecl *opaque, SubstitutionMap subs) {
6028- // TODO: We could attempt to preserve type sugar in the substitution map.
6029- // Currently archetypes are assumed to be always canonical in many places,
6030- // though, so doing so would require fixing those places.
6031- subs = subs.getCanonical ();
6032-
60336030 auto &ctx = opaque->getASTContext ();
60346031
60356032 auto properties = ArchetypeType::archetypeProperties (
@@ -6044,9 +6041,9 @@ GenericEnvironment *GenericEnvironment::forOpaqueType(
60446041 auto signature = opaque->getOpaqueInterfaceGenericSignature ();
60456042 unsigned numGenericParams = signature.getGenericParams ().size ();
60466043 size_t bytes = totalSizeToAlloc<SubstitutionMap,
6047- OpaqueEnvironmentData,
6048- OpenedExistentialEnvironmentData ,
6049- OpenedElementEnvironmentData , Type>(
6044+ OpaqueEnvironmentData,
6045+ ExistentialEnvironmentData ,
6046+ ElementEnvironmentData , Type>(
60506047 1 , 1 , 0 , 0 , numGenericParams);
60516048 void *mem = ctx.Allocate (bytes, alignof (GenericEnvironment), arena);
60526049 env = new (mem) GenericEnvironment (signature, opaque, subs);
@@ -6108,8 +6105,8 @@ GenericEnvironment::forOpenedExistential(
61086105 unsigned numGenericParams = signature.getGenericParams ().size ();
61096106 size_t bytes = totalSizeToAlloc<SubstitutionMap,
61106107 OpaqueEnvironmentData,
6111- OpenedExistentialEnvironmentData ,
6112- OpenedElementEnvironmentData , Type>(
6108+ ExistentialEnvironmentData ,
6109+ ElementEnvironmentData , Type>(
61136110 1 , 0 , 1 , 0 , numGenericParams);
61146111 void *mem = ctx.Allocate (bytes, alignof (GenericEnvironment));
61156112 auto *genericEnv =
@@ -6146,8 +6143,8 @@ GenericEnvironment::forOpenedElement(GenericSignature signature,
61466143 unsigned numOpenedParams = signature.getInnermostGenericParams ().size ();
61476144 size_t bytes = totalSizeToAlloc<SubstitutionMap,
61486145 OpaqueEnvironmentData,
6149- OpenedExistentialEnvironmentData ,
6150- OpenedElementEnvironmentData ,
6146+ ExistentialEnvironmentData ,
6147+ ElementEnvironmentData ,
61516148 Type>(
61526149 1 , 0 , 0 , 1 , numGenericParams + numOpenedParams);
61536150 void *mem = ctx.Allocate (bytes, alignof (GenericEnvironment));
0 commit comments