@@ -4694,26 +4694,7 @@ OpaqueTypeArchetypeType *OpaqueTypeArchetypeType::getNew(
4694
4694
4695
4695
Type OpaqueTypeArchetypeType::get (
4696
4696
OpaqueTypeDecl *Decl, Type interfaceType, SubstitutionMap Substitutions) {
4697
- // TODO: We could attempt to preserve type sugar in the substitution map.
4698
- // Currently archetypes are assumed to be always canonical in many places,
4699
- // though, so doing so would require fixing those places.
4700
- Substitutions = Substitutions.getCanonical ();
4701
-
4702
- auto &ctx = Decl->getASTContext ();
4703
-
4704
- // Look for an opaque archetype environment in the appropriate arena.
4705
- auto properties = getOpaqueTypeArchetypeProperties (Substitutions);
4706
- auto arena = getArena (properties);
4707
- auto &environments
4708
- = ctx.getImpl ().getArena (arena).OpaqueArchetypeEnvironments ;
4709
- GenericEnvironment *env = environments[{Decl, Substitutions}];
4710
-
4711
- // Create the environment if it's missing.
4712
- if (!env) {
4713
- env = GenericEnvironment::forOpaqueType (Decl, Substitutions, arena);
4714
- environments[{Decl, Substitutions}] = env;
4715
- }
4716
-
4697
+ auto *env = GenericEnvironment::forOpaqueType (Decl, Substitutions);
4717
4698
return env->getOrCreateArchetypeFromInterfaceType (interfaceType);
4718
4699
}
4719
4700
@@ -4940,18 +4921,34 @@ GenericEnvironment *GenericEnvironment::forPrimary(GenericSignature signature) {
4940
4921
// / Create a new generic environment for an opaque type with the given set of
4941
4922
// / outer substitutions.
4942
4923
GenericEnvironment *GenericEnvironment::forOpaqueType (
4943
- OpaqueTypeDecl *opaque, SubstitutionMap subs, AllocationArena arena) {
4924
+ OpaqueTypeDecl *opaque, SubstitutionMap subs) {
4925
+ // TODO: We could attempt to preserve type sugar in the substitution map.
4926
+ // Currently archetypes are assumed to be always canonical in many places,
4927
+ // though, so doing so would require fixing those places.
4928
+ subs = subs.getCanonical ();
4929
+
4944
4930
auto &ctx = opaque->getASTContext ();
4945
4931
4946
- // Allocate and construct the new environment.
4947
- auto signature = opaque->getOpaqueInterfaceGenericSignature ();
4948
- unsigned numGenericParams = signature.getGenericParams ().size ();
4949
- size_t bytes = totalSizeToAlloc<OpaqueEnvironmentData,
4950
- OpenedExistentialEnvironmentData,
4951
- OpenedElementEnvironmentData, Type>(
4952
- 1 , 0 , 0 , numGenericParams);
4953
- void *mem = ctx.Allocate (bytes, alignof (GenericEnvironment), arena);
4954
- auto env = new (mem) GenericEnvironment (signature, opaque, subs);
4932
+ auto properties = getOpaqueTypeArchetypeProperties (subs);
4933
+ auto arena = getArena (properties);
4934
+ auto &environments
4935
+ = ctx.getImpl ().getArena (arena).OpaqueArchetypeEnvironments ;
4936
+ GenericEnvironment *env = environments[{opaque, subs}];
4937
+
4938
+ if (!env) {
4939
+ // Allocate and construct the new environment.
4940
+ auto signature = opaque->getOpaqueInterfaceGenericSignature ();
4941
+ unsigned numGenericParams = signature.getGenericParams ().size ();
4942
+ size_t bytes = totalSizeToAlloc<OpaqueEnvironmentData,
4943
+ OpenedExistentialEnvironmentData,
4944
+ OpenedElementEnvironmentData, Type>(
4945
+ 1 , 0 , 0 , numGenericParams);
4946
+ void *mem = ctx.Allocate (bytes, alignof (GenericEnvironment), arena);
4947
+ env = new (mem) GenericEnvironment (signature, opaque, subs);
4948
+
4949
+ environments[{opaque, subs}] = env;
4950
+ }
4951
+
4955
4952
return env;
4956
4953
}
4957
4954
0 commit comments