@@ -90,39 +90,45 @@ void Evaluator::finishedRequest(const ActiveRequest &request) {
9090}
9191
9292void Evaluator::diagnoseCycle (const ActiveRequest &request) {
93- if (debugDumpCycles) {
94- const auto printIndent = [](llvm::raw_ostream &OS, unsigned indent) {
95- OS.indent (indent);
96- OS << " `--" ;
97- };
98-
99- unsigned indent = 1 ;
100- auto &OS = llvm::errs ();
101-
102- OS << " ===CYCLE DETECTED===\n " ;
103- for (const auto &step : activeRequests) {
104- printIndent (OS, indent);
105- if (step == request) {
106- OS.changeColor (llvm::raw_ostream::GREEN);
107- simple_display (OS, step);
108- OS.resetColor ();
109- } else {
110- simple_display (OS, step);
93+ auto dumpCycles = [&]() {
94+ if (debugDumpCycles) {
95+ const auto printIndent = [](llvm::raw_ostream &OS, unsigned indent) {
96+ OS.indent (indent);
97+ OS << " `--" ;
98+ };
99+
100+ unsigned indent = 1 ;
101+ auto &OS = llvm::errs ();
102+
103+ OS << " ===CYCLE DETECTED===\n " ;
104+ for (const auto &step : activeRequests) {
105+ printIndent (OS, indent);
106+ if (step == request) {
107+ OS.changeColor (llvm::raw_ostream::GREEN);
108+ simple_display (OS, step);
109+ OS.resetColor ();
110+ } else {
111+ simple_display (OS, step);
112+ }
113+ OS << " \n " ;
114+ indent += 4 ;
111115 }
112- OS << " \n " ;
113- indent += 4 ;
114- }
115116
116- printIndent (OS, indent);
117- OS.changeColor (llvm::raw_ostream::GREEN);
118- simple_display (OS, request);
117+ printIndent (OS, indent);
118+ OS.changeColor (llvm::raw_ostream::GREEN);
119+ simple_display (OS, request);
119120
120- OS.changeColor (llvm::raw_ostream::RED);
121- OS << " (cyclic dependency)" ;
122- OS.resetColor ();
121+ OS.changeColor (llvm::raw_ostream::RED);
122+ OS << " (cyclic dependency)" ;
123+ OS.resetColor ();
123124
124- OS << " \n " ;
125- }
125+ OS << " \n " ;
126+ }
127+ };
128+
129+ // -debug-cycles is deferred to allow SimpleRequest to enable dumping if
130+ // the request has not overridden diagnoseCycle.
131+ SWIFT_DEFER { dumpCycles (); }
126132
127133 // Perform some filtering to avoid emitting duplicate 'through reference here'
128134 // notes.
0 commit comments