Skip to content

Commit 50f84cb

Browse files
committed
RequirementMachine: Tweak debug output
1 parent f5212e7 commit 50f84cb

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

lib/AST/RequirementMachine/Debug.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,17 @@ enum class DebugFlags : unsigned {
4848
/// Print debug output from the homotopy reduction algorithm.
4949
HomotopyReduction = (1<<8),
5050

51+
/// Print more detailed debug output from the homotopy reduction algorithm.
52+
HomotopyReductionDetail = (1<<9),
53+
5154
/// Print debug output from the minimal conformances algorithm.
52-
MinimalConformances = (1<<9),
55+
MinimalConformances = (1<<10),
5356

5457
/// Print debug output from the protocol dependency graph.
55-
ProtocolDependencies = (1<<10),
58+
ProtocolDependencies = (1<<11),
5659

5760
/// Print debug output from generic signature minimization.
58-
Minimization = (1<<11),
61+
Minimization = (1<<12),
5962
};
6063

6164
using DebugOptions = OptionSet<DebugFlags>;

lib/AST/RequirementMachine/HomotopyReduction.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,10 @@ findRuleToDelete(llvm::function_ref<bool(unsigned)> isRedundantRuleFn) {
375375

376376
Optional<std::pair<unsigned, unsigned>> found;
377377

378+
if (Debug.contains(DebugFlags::HomotopyReduction)) {
379+
llvm::dbgs() << "\n";
380+
}
381+
378382
for (const auto &pair : redundancyCandidates) {
379383
unsigned ruleID = pair.second;
380384
const auto &rule = getRule(ruleID);
@@ -402,7 +406,7 @@ findRuleToDelete(llvm::function_ref<bool(unsigned)> isRedundantRuleFn) {
402406
continue;
403407
}
404408

405-
if (Debug.contains(DebugFlags::HomotopyReduction)) {
409+
if (Debug.contains(DebugFlags::HomotopyReductionDetail)) {
406410
llvm::dbgs() << "** Candidate " << rule << " from loop #"
407411
<< pair.first << "\n";
408412
}
@@ -474,7 +478,8 @@ void RewriteSystem::deleteRule(unsigned ruleID,
474478
const RewritePath &replacementPath) {
475479
// Replace all occurrences of the rule with the replacement path in
476480
// all remaining rewrite loops.
477-
for (auto &loop : Loops) {
481+
for (unsigned loopID : indices(Loops)) {
482+
auto &loop = Loops[loopID];
478483
if (loop.isDeleted())
479484
continue;
480485

@@ -486,8 +491,8 @@ void RewriteSystem::deleteRule(unsigned ruleID,
486491
// result of findRulesAppearingOnceInEmptyContext().
487492
loop.markDirty();
488493

489-
if (Debug.contains(DebugFlags::HomotopyReduction)) {
490-
llvm::dbgs() << "** Updated loop: ";
494+
if (Debug.contains(DebugFlags::HomotopyReductionDetail)) {
495+
llvm::dbgs() << "** Updated loop #" << loopID << ": ";
491496
loop.dump(llvm::dbgs(), *this);
492497
llvm::dbgs() << "\n";
493498
}
@@ -534,6 +539,12 @@ void RewriteSystem::performHomotopyReduction(
534539
///
535540
/// Redundant rules are mutated to set their isRedundant() bit.
536541
void RewriteSystem::minimizeRewriteSystem() {
542+
if (Debug.contains(DebugFlags::HomotopyReduction)) {
543+
llvm::dbgs() << "-----------------------------\n";
544+
llvm::dbgs() << "- Minimizing rewrite system -\n";
545+
llvm::dbgs() << "-----------------------------\n";
546+
}
547+
537548
assert(Complete);
538549
assert(!Minimized);
539550
Minimized = 1;
@@ -545,7 +556,9 @@ void RewriteSystem::minimizeRewriteSystem() {
545556
// - Eliminate all RHS-simplified and substitution-simplified rules.
546557
// - Eliminate all rules with unresolved symbols.
547558
if (Debug.contains(DebugFlags::HomotopyReduction)) {
548-
llvm::dbgs() << "\nFirst pass: simplified and unresolved rules\n\n";
559+
llvm::dbgs() << "---------------------------------------------\n";
560+
llvm::dbgs() << "First pass: simplified and unresolved rules -\n";
561+
llvm::dbgs() << "---------------------------------------------\n";
549562
}
550563

551564
performHomotopyReduction([&](unsigned ruleID) -> bool {
@@ -577,7 +590,9 @@ void RewriteSystem::minimizeRewriteSystem() {
577590

578591
// Second pass: Eliminate all non-minimal conformance rules.
579592
if (Debug.contains(DebugFlags::HomotopyReduction)) {
580-
llvm::dbgs() << "\nSecond pass: non-minimal conformance rules\n\n";
593+
llvm::dbgs() << "--------------------------------------------\n";
594+
llvm::dbgs() << "Second pass: non-minimal conformance rules -\n";
595+
llvm::dbgs() << "--------------------------------------------\n";
581596
}
582597

583598
performHomotopyReduction([&](unsigned ruleID) -> bool {
@@ -592,7 +607,9 @@ void RewriteSystem::minimizeRewriteSystem() {
592607

593608
// Third pass: Eliminate all other redundant non-conformance rules.
594609
if (Debug.contains(DebugFlags::HomotopyReduction)) {
595-
llvm::dbgs() << "\nThird pass: all other redundant rules\n\n";
610+
llvm::dbgs() << "---------------------------------------\n";
611+
llvm::dbgs() << "Third pass: all other redundant rules -\n";
612+
llvm::dbgs() << "---------------------------------------\n";
596613
}
597614

598615
performHomotopyReduction([&](unsigned ruleID) -> bool {

lib/AST/RequirementMachine/RequirementMachineRequests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ RequirementMachine::buildRequirementsFromRules(
171171
};
172172

173173
if (getDebugOptions().contains(DebugFlags::Minimization)) {
174-
llvm::dbgs() << "Minimized rules:\n";
174+
llvm::dbgs() << "\nMinimized rules:\n";
175175
}
176176

177177
// Build the list of requirements, storing same-type requirements off

lib/AST/RequirementMachine/RewriteContext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ static DebugOptions parseDebugFlags(StringRef debugFlags) {
3636
.Case("concretize-nested-types", DebugFlags::ConcretizeNestedTypes)
3737
.Case("conditional-requirements", DebugFlags::ConditionalRequirements)
3838
.Case("homotopy-reduction", DebugFlags::HomotopyReduction)
39+
.Case("homotopy-reduction-detail", DebugFlags::HomotopyReductionDetail)
3940
.Case("minimal-conformances", DebugFlags::MinimalConformances)
4041
.Case("protocol-dependencies", DebugFlags::ProtocolDependencies)
4142
.Case("minimization", DebugFlags::Minimization)

0 commit comments

Comments
 (0)