@@ -606,6 +606,8 @@ struct ASTContext::Implementation {
606
606
void dump (llvm::raw_ostream &out) const ;
607
607
};
608
608
609
+ using OpenedExistentialKey = std::pair<SubstitutionMap, UUID>;
610
+
609
611
llvm::DenseMap<ModuleDecl*, ModuleType*> ModuleTypes;
610
612
llvm::DenseMap<std::pair<unsigned , unsigned >, GenericTypeParamType *>
611
613
GenericParamTypes;
@@ -618,7 +620,8 @@ struct ASTContext::Implementation {
618
620
llvm::DenseMap<BuiltinIntegerWidth, BuiltinIntegerType*> IntegerTypes;
619
621
llvm::FoldingSet<BuiltinVectorType> BuiltinVectorTypes;
620
622
llvm::FoldingSet<DeclName::CompoundDeclName> CompoundNames;
621
- llvm::DenseMap<UUID, GenericEnvironment *> OpenedExistentialEnvironments;
623
+ llvm::DenseMap<OpenedExistentialKey, GenericEnvironment *>
624
+ OpenedExistentialEnvironments;
622
625
llvm::DenseMap<UUID, GenericEnvironment *> OpenedElementEnvironments;
623
626
llvm::FoldingSet<IndexSubset> IndexSubsets;
624
627
llvm::FoldingSet<AutoDiffDerivativeFunctionIdentifier>
@@ -5295,7 +5298,7 @@ OpaqueTypeArchetypeType *OpaqueTypeArchetypeType::getNew(
5295
5298
ArrayRef<ProtocolDecl *> conformsTo, Type superclass,
5296
5299
LayoutConstraint layout) {
5297
5300
auto properties = getOpaqueTypeArchetypeProperties (
5298
- environment->getOpaqueSubstitutions ());
5301
+ environment->getOuterSubstitutions ());
5299
5302
auto arena = getArena (properties);
5300
5303
auto size = OpaqueTypeArchetypeType::totalSizeToAlloc<
5301
5304
ProtocolDecl *, Type, LayoutConstraint>(
@@ -5353,7 +5356,7 @@ CanOpenedArchetypeType OpenedArchetypeType::get(CanType existential,
5353
5356
5354
5357
auto *genericEnv =
5355
5358
GenericEnvironment::forOpenedExistential (
5356
- existential, GenericSignature (), *knownID);
5359
+ existential, SubstitutionMap (), *knownID);
5357
5360
5358
5361
// Map the interface type into that environment.
5359
5362
auto result = genericEnv->mapTypeIntoContext (interfaceType)
@@ -5508,10 +5511,11 @@ GenericEnvironment *GenericEnvironment::forPrimary(GenericSignature signature) {
5508
5511
5509
5512
// Allocate and construct the new environment.
5510
5513
unsigned numGenericParams = signature.getGenericParams ().size ();
5511
- size_t bytes = totalSizeToAlloc<OpaqueEnvironmentData,
5514
+ size_t bytes = totalSizeToAlloc<SubstitutionMap,
5515
+ OpaqueEnvironmentData,
5512
5516
OpenedExistentialEnvironmentData,
5513
5517
OpenedElementEnvironmentData, Type>(
5514
- 0 , 0 , 0 , numGenericParams);
5518
+ 0 , 0 , 0 , 0 , numGenericParams);
5515
5519
void *mem = ctx.Allocate (bytes, alignof (GenericEnvironment));
5516
5520
return new (mem) GenericEnvironment (signature);
5517
5521
}
@@ -5537,10 +5541,11 @@ GenericEnvironment *GenericEnvironment::forOpaqueType(
5537
5541
// Allocate and construct the new environment.
5538
5542
auto signature = opaque->getOpaqueInterfaceGenericSignature ();
5539
5543
unsigned numGenericParams = signature.getGenericParams ().size ();
5540
- size_t bytes = totalSizeToAlloc<OpaqueEnvironmentData,
5544
+ size_t bytes = totalSizeToAlloc<SubstitutionMap,
5545
+ OpaqueEnvironmentData,
5541
5546
OpenedExistentialEnvironmentData,
5542
5547
OpenedElementEnvironmentData, Type>(
5543
- 1 , 0 , 0 , numGenericParams);
5548
+ 1 , 1 , 0 , 0 , numGenericParams);
5544
5549
void *mem = ctx.Allocate (bytes, alignof (GenericEnvironment), arena);
5545
5550
env = new (mem) GenericEnvironment (signature, opaque, subs);
5546
5551
@@ -5553,7 +5558,7 @@ GenericEnvironment *GenericEnvironment::forOpaqueType(
5553
5558
// / Create a new generic environment for an opened archetype.
5554
5559
GenericEnvironment *
5555
5560
GenericEnvironment::forOpenedExistential (
5556
- Type existential, GenericSignature parentSig , UUID uuid) {
5561
+ Type existential, SubstitutionMap subs , UUID uuid) {
5557
5562
assert (existential->isExistentialType ());
5558
5563
// FIXME: Opened archetypes can't be transformed because the
5559
5564
// the identity of the archetype has to be preserved. This
@@ -5567,32 +5572,36 @@ GenericEnvironment::forOpenedExistential(
5567
5572
5568
5573
auto &ctx = existential->getASTContext ();
5569
5574
5575
+ auto key = std::make_pair (subs, uuid);
5576
+
5570
5577
auto &openedExistentialEnvironments =
5571
5578
ctx.getImpl ().OpenedExistentialEnvironments ;
5572
- auto found = openedExistentialEnvironments.find (uuid );
5579
+ auto found = openedExistentialEnvironments.find (key );
5573
5580
5574
5581
if (found != openedExistentialEnvironments.end ()) {
5575
5582
auto *existingEnv = found->second ;
5576
5583
assert (existingEnv->getOpenedExistentialType ()->isEqual (existential));
5577
- assert (existingEnv->getOpenedExistentialParentSignature (). getPointer () == parentSig. getPointer () );
5584
+ assert (existingEnv->getOuterSubstitutions () == subs );
5578
5585
assert (existingEnv->getOpenedExistentialUUID () == uuid);
5579
5586
5580
5587
return existingEnv;
5581
5588
}
5582
5589
5590
+ auto parentSig = subs.getGenericSignature ().getCanonicalSignature ();
5583
5591
auto signature = ctx.getOpenedExistentialSignature (existential, parentSig);
5584
5592
5585
5593
// Allocate and construct the new environment.
5586
5594
unsigned numGenericParams = signature.getGenericParams ().size ();
5587
- size_t bytes = totalSizeToAlloc<OpaqueEnvironmentData,
5595
+ size_t bytes = totalSizeToAlloc<SubstitutionMap,
5596
+ OpaqueEnvironmentData,
5588
5597
OpenedExistentialEnvironmentData,
5589
5598
OpenedElementEnvironmentData, Type>(
5590
- 0 , 1 , 0 , numGenericParams);
5599
+ 1 , 0 , 1 , 0 , numGenericParams);
5591
5600
void *mem = ctx.Allocate (bytes, alignof (GenericEnvironment));
5592
5601
auto *genericEnv =
5593
- new (mem) GenericEnvironment (signature, existential, parentSig , uuid);
5602
+ new (mem) GenericEnvironment (signature, existential, subs , uuid);
5594
5603
5595
- openedExistentialEnvironments[uuid ] = genericEnv;
5604
+ openedExistentialEnvironments[key ] = genericEnv;
5596
5605
5597
5606
return genericEnv;
5598
5607
}
@@ -5621,11 +5630,12 @@ GenericEnvironment::forOpenedElement(GenericSignature signature,
5621
5630
// Allocate and construct the new environment.
5622
5631
unsigned numGenericParams = signature.getGenericParams ().size ();
5623
5632
unsigned numOpenedParams = signature.getInnermostGenericParams ().size ();
5624
- size_t bytes = totalSizeToAlloc<OpaqueEnvironmentData,
5633
+ size_t bytes = totalSizeToAlloc<SubstitutionMap,
5634
+ OpaqueEnvironmentData,
5625
5635
OpenedExistentialEnvironmentData,
5626
5636
OpenedElementEnvironmentData,
5627
5637
Type>(
5628
- 0 , 0 , 1 , numGenericParams + numOpenedParams);
5638
+ 1 , 0 , 0 , 1 , numGenericParams + numOpenedParams);
5629
5639
void *mem = ctx.Allocate (bytes, alignof (GenericEnvironment));
5630
5640
auto *genericEnv = new (mem) GenericEnvironment (signature,
5631
5641
uuid, shapeClass,
0 commit comments