Skip to content

Commit cbccd2d

Browse files
committed
[GenericSignatureBuilder] Add some simple statistics to track work done.
1 parent 8483524 commit cbccd2d

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "llvm/ADT/SetVector.h"
3434
#include "llvm/ADT/SmallPtrSet.h"
3535
#include "llvm/ADT/SmallString.h"
36+
#include "llvm/ADT/Statistic.h"
3637
#include "llvm/ADT/STLExtras.h"
3738
#include "llvm/Support/raw_ostream.h"
3839
#include <algorithm>
@@ -54,6 +55,18 @@ namespace {
5455

5556
} // end anonymous namespace
5657

58+
#define DEBUG_TYPE "Generic signature builder"
59+
STATISTIC(NumPotentialArchetypes, "# of potential archetypes");
60+
STATISTIC(NumConformances, "# of conformances tracked");
61+
STATISTIC(NumConformanceConstraints, "# of conformance constraints tracked");
62+
STATISTIC(NumSameTypeConstraints, "# of same-type constraints tracked");
63+
STATISTIC(NumConcreteTypeConstraints,
64+
"# of same-type-to-concrete constraints tracked");
65+
STATISTIC(NumSuperclassConstraints, "# of superclass constraints tracked");
66+
STATISTIC(NumLayoutConstraints, "# of layout constraints tracked");
67+
STATISTIC(NumSelfDerived, "# of self-derived constraints removed");
68+
STATISTIC(NumRecursive, "# of recursive types we bail out on");
69+
5770
struct GenericSignatureBuilder::Implementation {
5871
/// Function used to look up conformances.
5972
std::function<GenericFunction> LookupConformance;
@@ -988,10 +1001,12 @@ bool FloatingRequirementSource::isRecursive(
9881001
->getAffectedPotentialArchetype();
9891002
while (auto parent = pa->getParent()) {
9901003
if (pa->getNestedName() == nestedName) {
991-
if (++grossCount > 4) return true;
1004+
if (++grossCount > 4) {
1005+
++NumRecursive;
1006+
return true;
1007+
}
9921008
}
9931009

994-
9951010
pa = parent;
9961011
}
9971012
}
@@ -1000,6 +1015,8 @@ bool FloatingRequirementSource::isRecursive(
10001015
}
10011016

10021017
GenericSignatureBuilder::PotentialArchetype::~PotentialArchetype() {
1018+
++NumPotentialArchetypes;
1019+
10031020
for (const auto &nested : NestedTypes) {
10041021
for (auto pa : nested.second) {
10051022
if (pa != this)
@@ -1218,6 +1235,7 @@ const RequirementSource *GenericSignatureBuilder::resolveSuperConformance(
12181235
superclassSource =
12191236
superclassSource->viaSuperclass(*this, conformance->getConcrete());
12201237
paEquivClass->conformsTo[proto].push_back({pa, proto, superclassSource});
1238+
++NumConformanceConstraints;
12211239
return superclassSource;
12221240
}
12231241

@@ -1295,11 +1313,14 @@ bool PotentialArchetype::addConformance(ProtocolDecl *proto,
12951313
if (known != equivClass->conformsTo.end()) {
12961314
// We already knew about this conformance; record this specific constraint.
12971315
known->second.push_back({this, proto, source});
1316+
++NumConformanceConstraints;
12981317
return false;
12991318
}
13001319

13011320
// Add the conformance along with this constraint.
13021321
equivClass->conformsTo[proto].push_back({this, proto, source});
1322+
++NumConformanceConstraints;
1323+
++NumConformances;
13031324

13041325
// Determine whether there is a superclass constraint where the
13051326
// superclass conforms to this protocol.
@@ -2716,6 +2737,7 @@ ConstraintResult GenericSignatureBuilder::addLayoutRequirementDirect(
27162737

27172738
// Record this layout constraint.
27182739
equivClass->layoutConstraints.push_back({PAT, Layout, Source});
2740+
++NumLayoutConstraints;
27192741

27202742
// Update the layout in the equivalence class, if we didn't have one already.
27212743
if (!equivClass->layout)
@@ -2840,6 +2862,7 @@ ConstraintResult GenericSignatureBuilder::addSuperclassRequirementDirect(
28402862
// Record the constraint.
28412863
T->getOrCreateEquivalenceClass()->superclassConstraints
28422864
.push_back(ConcreteConstraint{T, superclass, source});
2865+
++NumSuperclassConstraints;
28432866

28442867
// Update the equivalence class with the constraint.
28452868
updateSuperclass(T, superclass, source);
@@ -2976,11 +2999,13 @@ void GenericSignatureBuilder::PotentialArchetype::addSameTypeConstraint(
29762999
// Update the same-type constraints of this PA to reference the other PA.
29773000
getOrCreateEquivalenceClass()->sameTypeConstraints[this]
29783001
.push_back({this, otherPA, source});
3002+
++NumSameTypeConstraints;
29793003

29803004
if (this != otherPA) {
29813005
// Update the same-type constraints of the other PA to reference this PA.
29823006
otherPA->getOrCreateEquivalenceClass()->sameTypeConstraints[otherPA]
29833007
.push_back({otherPA, this, source});
3008+
++NumSameTypeConstraints;
29843009
}
29853010
}
29863011

@@ -3108,6 +3133,7 @@ ConstraintResult GenericSignatureBuilder::addSameTypeRequirementToConcrete(
31083133
// Record the concrete type and its source.
31093134
equivClass->concreteTypeConstraints.push_back(
31103135
ConcreteConstraint{T, Concrete, Source});
3136+
++NumConcreteTypeConstraints;
31113137

31123138
// If we've already been bound to a type, match that type.
31133139
if (equivClass->concreteType) {
@@ -3151,6 +3177,7 @@ ConstraintResult GenericSignatureBuilder::addSameTypeRequirementToConcrete(
31513177
? conformance->getConcrete()
31523178
: nullptr);
31533179
equivClass->conformsTo[protocol].push_back({T, protocol, concreteSource});
3180+
++NumConformanceConstraints;
31543181
}
31553182

31563183
// Eagerly resolve any existing nested types to their concrete forms (others
@@ -4107,8 +4134,10 @@ namespace {
41074134
[&](const Constraint<T> &constraint) {
41084135
bool derivedViaConcrete;
41094136
if (constraint.source->isSelfDerivedSource(
4110-
constraint.archetype, derivedViaConcrete))
4137+
constraint.archetype, derivedViaConcrete)) {
4138+
++NumSelfDerived;
41114139
return true;
4140+
}
41124141

41134142
if (!derivedViaConcrete)
41144143
return false;
@@ -4122,6 +4151,7 @@ namespace {
41224151
if (!remainingConcrete)
41234152
remainingConcrete = constraint;
41244153

4154+
++NumSelfDerived;
41254155
return true;
41264156
}),
41274157
constraints.end());
@@ -4274,15 +4304,19 @@ void GenericSignatureBuilder::checkConformanceConstraints(
42744304
bool derivedViaConcrete;
42754305
if (constraint.source->isSelfDerivedConformance(
42764306
constraint.archetype, entry.first,
4277-
derivedViaConcrete))
4307+
derivedViaConcrete)) {
4308+
++NumSelfDerived;
42784309
return true;
4310+
}
42794311

42804312
if (!derivedViaConcrete)
42814313
return false;
42824314

42834315
// Drop derived-via-concrete requirements.
42844316
if (!remainingConcrete)
42854317
remainingConcrete = constraint;
4318+
4319+
++NumSelfDerived;
42864320
return true;
42874321
}),
42884322
entry.second.end());

0 commit comments

Comments
 (0)