@@ -5731,7 +5731,8 @@ OpaqueTypeArchetypeType *OpaqueTypeArchetypeType::getNew(
5731
5731
ASTContext &ctx = interfaceType->getASTContext ();
5732
5732
auto mem = ctx.Allocate (size, alignof (OpaqueTypeArchetypeType), arena);
5733
5733
return ::new (mem)
5734
- OpaqueTypeArchetypeType (environment, properties, interfaceType,
5734
+ OpaqueTypeArchetypeType (environment->isCanonical () ? &ctx : nullptr ,
5735
+ environment, properties, interfaceType,
5735
5736
conformsTo, superclass, layout);
5736
5737
}
5737
5738
@@ -5759,6 +5760,7 @@ CanTypeWrapper<ExistentialArchetypeType> ExistentialArchetypeType::getNew(
5759
5760
void *mem = ctx.Allocate (size, alignof (ExistentialArchetypeType), arena);
5760
5761
5761
5762
return CanExistentialArchetypeType (::new (mem) ExistentialArchetypeType (
5763
+ environment->isCanonical () ? &ctx : nullptr ,
5762
5764
environment, interfaceType, conformsTo, superclass, layout,
5763
5765
properties));
5764
5766
}
@@ -6014,8 +6016,8 @@ GenericEnvironment *GenericEnvironment::forPrimary(GenericSignature signature) {
6014
6016
unsigned numGenericParams = signature.getGenericParams ().size ();
6015
6017
size_t bytes = totalSizeToAlloc<SubstitutionMap,
6016
6018
OpaqueEnvironmentData,
6017
- OpenedExistentialEnvironmentData ,
6018
- OpenedElementEnvironmentData , Type>(
6019
+ ExistentialEnvironmentData ,
6020
+ ElementEnvironmentData , Type>(
6019
6021
0 , 0 , 0 , 0 , numGenericParams);
6020
6022
void *mem = ctx.Allocate (bytes, alignof (GenericEnvironment));
6021
6023
return new (mem) GenericEnvironment (signature);
@@ -6025,11 +6027,6 @@ GenericEnvironment *GenericEnvironment::forPrimary(GenericSignature signature) {
6025
6027
// / outer substitutions.
6026
6028
GenericEnvironment *GenericEnvironment::forOpaqueType (
6027
6029
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
-
6033
6030
auto &ctx = opaque->getASTContext ();
6034
6031
6035
6032
auto properties = ArchetypeType::archetypeProperties (
@@ -6044,9 +6041,9 @@ GenericEnvironment *GenericEnvironment::forOpaqueType(
6044
6041
auto signature = opaque->getOpaqueInterfaceGenericSignature ();
6045
6042
unsigned numGenericParams = signature.getGenericParams ().size ();
6046
6043
size_t bytes = totalSizeToAlloc<SubstitutionMap,
6047
- OpaqueEnvironmentData,
6048
- OpenedExistentialEnvironmentData ,
6049
- OpenedElementEnvironmentData , Type>(
6044
+ OpaqueEnvironmentData,
6045
+ ExistentialEnvironmentData ,
6046
+ ElementEnvironmentData , Type>(
6050
6047
1 , 1 , 0 , 0 , numGenericParams);
6051
6048
void *mem = ctx.Allocate (bytes, alignof (GenericEnvironment), arena);
6052
6049
env = new (mem) GenericEnvironment (signature, opaque, subs);
@@ -6108,8 +6105,8 @@ GenericEnvironment::forOpenedExistential(
6108
6105
unsigned numGenericParams = signature.getGenericParams ().size ();
6109
6106
size_t bytes = totalSizeToAlloc<SubstitutionMap,
6110
6107
OpaqueEnvironmentData,
6111
- OpenedExistentialEnvironmentData ,
6112
- OpenedElementEnvironmentData , Type>(
6108
+ ExistentialEnvironmentData ,
6109
+ ElementEnvironmentData , Type>(
6113
6110
1 , 0 , 1 , 0 , numGenericParams);
6114
6111
void *mem = ctx.Allocate (bytes, alignof (GenericEnvironment));
6115
6112
auto *genericEnv =
@@ -6146,8 +6143,8 @@ GenericEnvironment::forOpenedElement(GenericSignature signature,
6146
6143
unsigned numOpenedParams = signature.getInnermostGenericParams ().size ();
6147
6144
size_t bytes = totalSizeToAlloc<SubstitutionMap,
6148
6145
OpaqueEnvironmentData,
6149
- OpenedExistentialEnvironmentData ,
6150
- OpenedElementEnvironmentData ,
6146
+ ExistentialEnvironmentData ,
6147
+ ElementEnvironmentData ,
6151
6148
Type>(
6152
6149
1 , 0 , 0 , 1 , numGenericParams + numOpenedParams);
6153
6150
void *mem = ctx.Allocate (bytes, alignof (GenericEnvironment));
0 commit comments