Skip to content

Commit 294a1ab

Browse files
committed
GSB: Add some optional debugging output for the minimization algorithm
1 parent ad89fe5 commit 294a1ab

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,9 @@ struct GenericSignatureBuilder::Implementation {
663663
/// Whether there were any errors.
664664
bool HadAnyError = false;
665665

666+
/// Set this to true to get some debug output.
667+
bool DebugRedundantRequirements = false;
668+
666669
/// All explicit non-same type requirements that were added to the builder.
667670
SmallSetVector<ExplicitRequirement, 2> ExplicitRequirements;
668671

@@ -5770,7 +5773,12 @@ void GenericSignatureBuilder::ExplicitRequirement::dump(
57705773
break;
57715774
}
57725775

5773-
out << getSubjectType() << " : ";
5776+
out << getSubjectType();
5777+
if (getKind() == RequirementKind::SameType)
5778+
out << " : ";
5779+
else
5780+
out << " == ";
5781+
57745782
if (auto type = rhs.dyn_cast<Type>())
57755783
out << type;
57765784
else if (auto *proto = rhs.dyn_cast<ProtocolDecl *>())
@@ -8435,12 +8443,22 @@ GenericSignature GenericSignatureBuilder::rebuildSignatureWithoutRedundantRequir
84358443
};
84368444

84378445
for (const auto &req : Impl->ExplicitRequirements) {
8446+
if (Impl->DebugRedundantRequirements) {
8447+
req.dump(llvm::dbgs(), &Context.SourceMgr);
8448+
llvm::dbgs() << "\n";
8449+
}
8450+
84388451
assert(req.getKind() != RequirementKind::SameType &&
84398452
"Should not see same-type requirement here");
84408453

84418454
if (isRedundantExplicitRequirement(req) &&
8442-
Impl->ExplicitConformancesImpliedByConcrete.count(req))
8455+
Impl->ExplicitConformancesImpliedByConcrete.count(req)) {
8456+
if (Impl->DebugRedundantRequirements) {
8457+
llvm::dbgs() << "... skipping\n";
8458+
}
8459+
84438460
continue;
8461+
}
84448462

84458463
auto subjectType = req.getSubjectType();
84468464
subjectType = stripBoundDependentMemberTypes(subjectType);
@@ -8471,6 +8489,11 @@ GenericSignature GenericSignatureBuilder::rebuildSignatureWithoutRedundantRequir
84718489
}
84728490

84738491
for (const auto &req : Impl->ExplicitSameTypeRequirements) {
8492+
if (Impl->DebugRedundantRequirements) {
8493+
req.dump(llvm::dbgs(), &Context.SourceMgr);
8494+
llvm::dbgs() << "\n";
8495+
}
8496+
84748497
auto resolveType = [this](Type t) -> Type {
84758498
t = stripBoundDependentMemberTypes(t);
84768499
if (t->is<GenericTypeParamType>()) {
@@ -8499,6 +8522,11 @@ GenericSignature GenericSignatureBuilder::rebuildSignatureWithoutRedundantRequir
84998522
Requirement(RequirementKind::SameType,
85008523
subjectType, constraintType));
85018524

8525+
if (Impl->DebugRedundantRequirements) {
8526+
llvm::dbgs() << "=> ";
8527+
newReq.dump(llvm::dbgs());
8528+
llvm::dbgs() << "\n";
8529+
}
85028530
newBuilder.addRequirement(newReq, getRebuiltSource(req.getSource()),
85038531
nullptr);
85048532
}
@@ -8535,16 +8563,27 @@ GenericSignature GenericSignatureBuilder::computeGenericSignature(
85358563
diagnoseRedundantRequirements(
85368564
/*onlyDiagnoseExplicitConformancesImpliedByConcrete=*/true);
85378565

8566+
if (Impl->DebugRedundantRequirements) {
8567+
llvm::dbgs() << "Going to rebuild signature\n";
8568+
}
85388569
return std::move(*this).rebuildSignatureWithoutRedundantRequirements(
85398570
allowConcreteGenericParams,
85408571
requirementSignatureSelfProto);
85418572
}
85428573

85438574
if (Impl->RebuildingWithoutRedundantConformances) {
8575+
if (Impl->DebugRedundantRequirements) {
8576+
llvm::dbgs() << "Rebuilding signature\n";
8577+
}
8578+
85448579
#ifndef NDEBUG
85458580
for (const auto &req : Impl->ExplicitConformancesImpliedByConcrete) {
8546-
assert(!isRedundantExplicitRequirement(req) &&
8547-
"Rebuilt signature still had redundant conformance requirements");
8581+
if (isRedundantExplicitRequirement(req)) {
8582+
llvm::errs() << "Rebuilt signature still had redundant conformance requirement\n";
8583+
req.dump(llvm::errs(), &Context.SourceMgr);
8584+
llvm::errs() << "\n";
8585+
abort();
8586+
}
85488587
}
85498588
#endif
85508589
}

0 commit comments

Comments
 (0)