Skip to content

Commit 2283b4f

Browse files
authored
Merge pull request swiftlang#31195 from slavapestov/tiny-gsb-cleanups
GenericSignatureBuilder: Improved counters
2 parents fab3576 + 8d2a410 commit 2283b4f

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class GenericSignatureBuilder {
9595
llvm::PointerUnion<Type, PotentialArchetype *, LayoutConstraint>;
9696

9797
using RequirementRHS =
98-
llvm::PointerUnion<Type, PotentialArchetype *, LayoutConstraint>;
98+
llvm::PointerUnion<Type, LayoutConstraint>;
9999

100100
/// The location of a requirement as written somewhere in the source.
101101
typedef llvm::PointerUnion<const TypeRepr *, const RequirementRepr *>
@@ -1546,17 +1546,10 @@ class GenericSignatureBuilder::PotentialArchetype {
15461546
llvm::MapVector<Identifier, StoredNestedType> NestedTypes;
15471547

15481548
/// Construct a new potential archetype for a concrete declaration.
1549-
PotentialArchetype(PotentialArchetype *parent, AssociatedTypeDecl *assocType)
1550-
: parentOrContext(parent), identifier(assocType) {
1551-
assert(parent != nullptr && "Not a nested type?");
1552-
assert(assocType->getOverriddenDecls().empty());
1553-
}
1549+
PotentialArchetype(PotentialArchetype *parent, AssociatedTypeDecl *assocType);
15541550

15551551
/// Construct a new potential archetype for a generic parameter.
1556-
PotentialArchetype(ASTContext &ctx, GenericParamKey genericParam)
1557-
: parentOrContext(&ctx), identifier(genericParam)
1558-
{
1559-
}
1552+
PotentialArchetype(ASTContext &ctx, GenericParamKey genericParam);
15601553

15611554
public:
15621555
/// Retrieve the representative for this archetype, performing

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ namespace llvm {
8080

8181
#define DEBUG_TYPE "Generic signature builder"
8282
STATISTIC(NumPotentialArchetypes, "# of potential archetypes");
83+
STATISTIC(NumEquivalenceClassesAllocated, "# of equivalence classes allocated");
84+
STATISTIC(NumEquivalenceClassesFreed, "# of equivalence classes freed");
8385
STATISTIC(NumConformances, "# of conformances tracked");
8486
STATISTIC(NumConformanceConstraints, "# of conformance constraints tracked");
8587
STATISTIC(NumSameTypeConstraints, "# of same-type constraints tracked");
@@ -529,13 +531,18 @@ GenericSignatureBuilder::Implementation::allocateEquivalenceClass(
529531

530532
auto equivClass = new (mem) EquivalenceClass(representative);
531533
EquivalenceClasses.push_back(equivClass);
534+
535+
++NumEquivalenceClassesAllocated;
536+
532537
return equivClass;
533538
}
534539

535540
void GenericSignatureBuilder::Implementation::deallocateEquivalenceClass(
536541
EquivalenceClass *equivClass) {
537542
EquivalenceClasses.erase(equivClass);
538543
FreeEquivalenceClasses.push_back(equivClass);
544+
545+
++NumEquivalenceClassesFreed;
539546
}
540547

541548
namespace {
@@ -1620,9 +1627,22 @@ bool FloatingRequirementSource::isRecursive(
16201627
return false;
16211628
}
16221629

1623-
GenericSignatureBuilder::PotentialArchetype::~PotentialArchetype() {
1630+
GenericSignatureBuilder::PotentialArchetype::PotentialArchetype(
1631+
PotentialArchetype *parent, AssociatedTypeDecl *assocType)
1632+
: parentOrContext(parent), identifier(assocType) {
1633+
++NumPotentialArchetypes;
1634+
assert(parent != nullptr && "Not a nested type?");
1635+
assert(assocType->getOverriddenDecls().empty());
1636+
}
1637+
1638+
1639+
GenericSignatureBuilder::PotentialArchetype::PotentialArchetype(
1640+
ASTContext &ctx, GenericParamKey genericParam)
1641+
: parentOrContext(&ctx), identifier(genericParam) {
16241642
++NumPotentialArchetypes;
1643+
}
16251644

1645+
GenericSignatureBuilder::PotentialArchetype::~PotentialArchetype() {
16261646
for (const auto &nested : NestedTypes) {
16271647
for (auto pa : nested.second) {
16281648
pa->~PotentialArchetype();
@@ -7138,11 +7158,8 @@ void GenericSignatureBuilder::dump(llvm::raw_ostream &out) {
71387158
case RequirementKind::SameType:
71397159
out << "\n ";
71407160
out << type.getString() << " == " ;
7141-
if (auto secondType = constraint.dyn_cast<Type>()) {
7142-
out << secondType.getString();
7143-
} else {
7144-
out << constraint.get<PotentialArchetype *>()->getDebugName();
7145-
}
7161+
auto secondType = constraint.get<Type>();
7162+
out << secondType.getString();
71467163
out << " [";
71477164
source->print(out, &Context.SourceMgr);
71487165
out << "]";

0 commit comments

Comments
 (0)