Skip to content

Commit 4eaa5ce

Browse files
committed
AST: Move a few things from ASTContext::Implementation::Arena up to Implementation
Normal conformances, self conformances, and availability contexts cannot contain types with type variables, so there is no reason to duplicate the uniquing maps between the permanent arena and solver arena.
1 parent 28f9641 commit 4eaa5ce

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

lib/AST/ASTContext.cpp

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -575,12 +575,6 @@ struct ASTContext::Implementation {
575575
/// The set of function types.
576576
llvm::FoldingSet<FunctionType> FunctionTypes;
577577

578-
/// The set of normal protocol conformances.
579-
llvm::FoldingSet<NormalProtocolConformance> NormalConformances;
580-
581-
// The set of self protocol conformances.
582-
llvm::DenseMap<ProtocolDecl*, SelfProtocolConformance*> SelfConformances;
583-
584578
/// The set of specialized protocol conformances.
585579
llvm::FoldingSet<SpecializedProtocolConformance> SpecializedConformances;
586580

@@ -597,9 +591,6 @@ struct ASTContext::Implementation {
597591
/// The set of substitution maps (uniqued by their storage).
598592
llvm::FoldingSet<SubstitutionMap::Storage> SubstitutionMaps;
599593

600-
/// The set of unique AvailabilityContexts (uniqued by their storage).
601-
llvm::FoldingSet<AvailabilityContext::Storage> AvailabilityContexts;
602-
603594
~Arena() {
604595
for (auto &conformance : SpecializedConformances)
605596
conformance.~SpecializedProtocolConformance();
@@ -613,11 +604,6 @@ struct ASTContext::Implementation {
613604
#if SWIFT_COMPILER_IS_MSVC
614605
#pragma warning (default: 4189)
615606
#endif
616-
617-
// Call the normal conformance destructors last since they could be
618-
// referenced by the other conformance types.
619-
for (auto &conformance : NormalConformances)
620-
conformance.~NormalProtocolConformance();
621607
}
622608

623609
size_t getTotalMemory() const;
@@ -645,6 +631,11 @@ struct ASTContext::Implementation {
645631
AutoDiffDerivativeFunctionIdentifiers;
646632

647633
llvm::FoldingSet<GenericSignatureImpl> GenericSignatures;
634+
llvm::FoldingSet<NormalProtocolConformance> NormalConformances;
635+
llvm::DenseMap<ProtocolDecl*, SelfProtocolConformance*> SelfConformances;
636+
637+
/// The set of unique AvailabilityContexts (uniqued by their storage).
638+
llvm::FoldingSet<AvailabilityContext::Storage> AvailabilityContexts;
648639

649640
/// A cache of information about whether particular nominal types
650641
/// are representable in a foreign language.
@@ -720,6 +711,9 @@ ASTContext::Implementation::Implementation()
720711
: IdentifierTable(Allocator),
721712
IntrinsicScratchContext(new llvm::LLVMContext()) {}
722713
ASTContext::Implementation::~Implementation() {
714+
for (auto &conformance : NormalConformances)
715+
conformance.~NormalProtocolConformance();
716+
723717
for (auto &cleanup : Cleanups)
724718
cleanup();
725719
}
@@ -889,6 +883,9 @@ void ASTContext::Implementation::dump(llvm::raw_ostream &os) const {
889883
SIZE_AND_BYTES(SILMoveOnlyWrappedTypes);
890884
SIZE_AND_BYTES(BuiltinIntegerTypes);
891885
SIZE_AND_BYTES(OpenedElementEnvironments);
886+
SIZE(NormalConformances);
887+
SIZE(SelfConformances);
888+
SIZE(AvailabilityContexts);
892889
SIZE_AND_BYTES(ForeignRepresentableCache);
893890
SIZE(SearchPathsSet);
894891

@@ -2912,15 +2909,14 @@ ASTContext::getNormalConformance(Type conformingType,
29122909

29132910
// Did we already record the normal conformance?
29142911
void *insertPos;
2915-
auto &normalConformances =
2916-
getImpl().getArena(AllocationArena::Permanent).NormalConformances;
2912+
auto &normalConformances = getImpl().NormalConformances;
29172913
if (auto result = normalConformances.FindNodeOrInsertPos(id, insertPos))
29182914
return result;
29192915

29202916
// Build a new normal protocol conformance.
2921-
auto result = new (*this, AllocationArena::Permanent)
2922-
NormalProtocolConformance(conformingType, protocol, loc, dc, state,
2923-
options, preconcurrencyLoc);
2917+
auto result = new (*this) NormalProtocolConformance(
2918+
conformingType, protocol, loc, dc, state,
2919+
options, preconcurrencyLoc);
29242920
normalConformances.InsertNode(result, insertPos);
29252921

29262922
return result;
@@ -2929,12 +2925,11 @@ ASTContext::getNormalConformance(Type conformingType,
29292925
/// Produce a self-conformance for the given protocol.
29302926
SelfProtocolConformance *
29312927
ASTContext::getSelfConformance(ProtocolDecl *protocol) {
2932-
auto &selfConformances =
2933-
getImpl().getArena(AllocationArena::Permanent).SelfConformances;
2928+
auto &selfConformances = getImpl().SelfConformances;
29342929
auto &entry = selfConformances[protocol];
29352930
if (!entry) {
2936-
entry = new (*this, AllocationArena::Permanent)
2937-
SelfProtocolConformance(protocol->getDeclaredExistentialType());
2931+
entry = new (*this) SelfProtocolConformance(
2932+
protocol->getDeclaredExistentialType());
29382933
}
29392934
return entry;
29402935
}
@@ -3274,6 +3269,9 @@ size_t ASTContext::getTotalMemory() const {
32743269
// getImpl().GenericSignatures ?
32753270
// getImpl().CompoundNames ?
32763271
// getImpl().IntegerTypes ?
3272+
// getImpl().NormalConformances ?
3273+
// getImpl().SelfConformances ?
3274+
// getImpl().AvailabilityContexts
32773275
getImpl().Permanent.getTotalMemory();
32783276

32793277
Size += getSolverMemory();
@@ -3315,7 +3313,6 @@ size_t ASTContext::Implementation::Arena::getTotalMemory() const {
33153313
// FunctionTypes ?
33163314
// UnboundGenericTypes ?
33173315
// BoundGenericTypes ?
3318-
// NormalConformances ?
33193316
// SpecializedConformances ?
33203317
// InheritedConformances ?
33213318
// BuiltinConformances ?
@@ -3360,14 +3357,11 @@ void ASTContext::Implementation::Arena::dump(llvm::raw_ostream &os) const {
33603357
SIZE_AND_BYTES(OpaqueArchetypeEnvironments);
33613358
SIZE_AND_BYTES(OpenedExistentialEnvironments);
33623359
SIZE(FunctionTypes);
3363-
SIZE(NormalConformances);
3364-
SIZE(SelfConformances);
33653360
SIZE(SpecializedConformances);
33663361
SIZE(InheritedConformances);
33673362
SIZE_AND_BYTES(BuiltinConformances);
33683363
SIZE(PackConformances);
33693364
SIZE(SubstitutionMaps);
3370-
SIZE(AvailabilityContexts);
33713365

33723366
#undef SIZE
33733367
#undef SIZE_AND_BYTES
@@ -5720,8 +5714,7 @@ const AvailabilityContext::Storage *AvailabilityContext::Storage::get(
57205714
AvailabilityContext::Storage::Profile(id, platformRange, isDeprecated,
57215715
domainInfos);
57225716

5723-
auto &foldingSet =
5724-
ctx.getImpl().getArena(AllocationArena::Permanent).AvailabilityContexts;
5717+
auto &foldingSet = ctx.getImpl().AvailabilityContexts;
57255718
void *insertPos;
57265719
auto *existing = foldingSet.FindNodeOrInsertPos(id, insertPos);
57275720
if (existing)

0 commit comments

Comments
 (0)