Skip to content

Commit 3f5a06b

Browse files
committed
AST: Always diagnose request evaluator cycles
1 parent 18dc8d4 commit 3f5a06b

File tree

8 files changed

+22
-69
lines changed

8 files changed

+22
-69
lines changed

include/swift/AST/Evaluator.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#include "swift/AST/AnyRequest.h"
2222
#include "swift/Basic/AnyValue.h"
23-
#include "swift/Basic/CycleDiagnosticKind.h"
2423
#include "swift/Basic/Defer.h"
2524
#include "swift/Basic/Statistic.h"
2625
#include "llvm/ADT/DenseMap.h"
@@ -184,8 +183,8 @@ class Evaluator {
184183
/// diagnostics will be emitted.
185184
DiagnosticEngine &diags;
186185

187-
/// Whether to diagnose cycles or ignore them completely.
188-
CycleDiagnosticKind shouldDiagnoseCycles;
186+
/// Whether to dump detailed debug info for cycles.
187+
bool debugDumpCycles;
189188

190189
/// Used to report statistics about which requests were evaluated, if
191190
/// non-null.
@@ -237,7 +236,7 @@ class Evaluator {
237236
public:
238237
/// Construct a new evaluator that can emit cyclic-dependency
239238
/// diagnostics through the given diagnostics engine.
240-
Evaluator(DiagnosticEngine &diags, CycleDiagnosticKind shouldDiagnoseCycles);
239+
Evaluator(DiagnosticEngine &diags, bool debugDumpCycles=false);
241240

242241
/// Emit GraphViz output visualizing the request graph.
243242
void emitRequestEvaluatorGraphViz(llvm::StringRef graphVizPath);

include/swift/Basic/CycleDiagnosticKind.h

Lines changed: 0 additions & 34 deletions
This file was deleted.

include/swift/Basic/LangOptions.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#define SWIFT_BASIC_LANGOPTIONS_H
2020

2121
#include "swift/Config.h"
22-
#include "swift/Basic/CycleDiagnosticKind.h"
2322
#include "swift/Basic/LLVM.h"
2423
#include "swift/Basic/Version.h"
2524
#include "llvm/ADT/ArrayRef.h"
@@ -185,9 +184,8 @@ namespace swift {
185184
/// This is for testing purposes.
186185
std::string DebugForbidTypecheckPrefix;
187186

188-
/// How to diagnose cycles encountered
189-
CycleDiagnosticKind EvaluatorCycleDiagnostics =
190-
CycleDiagnosticKind::NoDiagnose;
187+
/// Whether to dump debug info for request evaluator cycles.
188+
bool DebugDumpCycles = false;
191189

192190
/// The path to which we should emit GraphViz output for the complete
193191
/// request-evaluator graph.

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ ASTContext::ASTContext(LangOptions &langOpts, SearchPathOptions &SearchPathOpts,
479479
SearchPathOpts(SearchPathOpts),
480480
SourceMgr(SourceMgr),
481481
Diags(Diags),
482-
evaluator(Diags, langOpts.EvaluatorCycleDiagnostics),
482+
evaluator(Diags, langOpts.DebugDumpCycles),
483483
TheBuiltinModule(createBuiltinModule(*this)),
484484
StdlibModuleName(getIdentifier(STDLIB_NAME)),
485485
SwiftShimsModuleName(getIdentifier(SWIFT_SHIMS_NAME)),

lib/AST/Evaluator.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ void Evaluator::registerRequestFunctions(
5959
requestFunctionsByZone.push_back({zoneID, functions});
6060
}
6161

62-
Evaluator::Evaluator(DiagnosticEngine &diags,
63-
CycleDiagnosticKind shouldDiagnoseCycles)
64-
: diags(diags), shouldDiagnoseCycles(shouldDiagnoseCycles) { }
62+
Evaluator::Evaluator(DiagnosticEngine &diags, bool debugDumpCycles)
63+
: diags(diags), debugDumpCycles(debugDumpCycles) { }
6564

6665
void Evaluator::emitRequestEvaluatorGraphViz(llvm::StringRef graphVizPath) {
6766
std::error_code error;
@@ -80,24 +79,16 @@ bool Evaluator::checkDependency(const AnyRequest &request) {
8079
}
8180

8281
// Diagnose cycle.
83-
switch (shouldDiagnoseCycles) {
84-
case CycleDiagnosticKind::NoDiagnose:
85-
return true;
82+
diagnoseCycle(request);
8683

87-
case CycleDiagnosticKind::DebugDiagnose: {
84+
if (debugDumpCycles) {
8885
llvm::errs() << "===CYCLE DETECTED===\n";
8986
llvm::DenseSet<AnyRequest> visitedAnywhere;
9087
llvm::SmallVector<AnyRequest, 4> visitedAlongPath;
9188
std::string prefixStr;
9289
printDependencies(activeRequests.front(), llvm::errs(), visitedAnywhere,
9390
visitedAlongPath, activeRequests.getArrayRef(),
9491
prefixStr, /*lastChild=*/true);
95-
return true;
96-
}
97-
98-
case CycleDiagnosticKind::FullDiagnose:
99-
diagnoseCycle(request);
100-
return true;
10192
}
10293

10394
return true;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
360360
Opts.DebugForbidTypecheckPrefix = A->getValue();
361361
}
362362

363-
if (Args.getLastArg(OPT_debug_cycles)) {
364-
Opts.EvaluatorCycleDiagnostics = CycleDiagnosticKind::DebugDiagnose;
365-
}
363+
if (Args.getLastArg(OPT_debug_cycles))
364+
Opts.DebugDumpCycles = true;
366365

367366
if (const Arg *A = Args.getLastArg(OPT_output_request_graphviz)) {
368367
Opts.RequestEvaluatorGraphVizPath = A->getValue();

test/decl/class/circular_inheritance.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
// Check that we produced superclass type requests.
99
// RUN: %{python} %utils/process-stats-dir.py --evaluate 'SuperclassTypeRequest == 17' %t/stats-dir
1010

11-
class Left
12-
: Right.Hand {
11+
class Left // expected-error {{circular reference}}
12+
: Right.Hand { // expected-note {{through reference here}}
1313
class Hand {}
1414
}
1515

16-
class Right
17-
: Left.Hand {
16+
class Right // expected-note {{through reference here}}
17+
: Left.Hand { // expected-note {{through reference here}}
1818
class Hand {}
1919
}
2020

@@ -35,14 +35,14 @@ class Outer {
3535
class Inner : Outer {}
3636
}
3737

38-
class Outer2
39-
: Outer2.Inner {
38+
class Outer2 // expected-error {{circular reference}}
39+
: Outer2.Inner { // expected-note {{through reference here}}
4040

4141
class Inner {}
4242
}
4343

44-
class Outer3
45-
: Outer3.Inner<Int> {
44+
class Outer3 // expected-error {{circular reference}}
45+
: Outer3.Inner<Int> { // expected-note {{through reference here}}
4646
class Inner<T> {}
4747
}
4848

unittests/AST/ArithmeticEvaluator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ TEST(ArithmeticEvaluator, Simple) {
211211

212212
SourceManager sourceMgr;
213213
DiagnosticEngine diags(sourceMgr);
214-
Evaluator evaluator(diags, CycleDiagnosticKind::FullDiagnose);
214+
Evaluator evaluator(diags);
215215
evaluator.registerRequestFunctions(SWIFT_ARITHMETIC_EVALUATOR_ZONE,
216216
arithmeticRequestFunctions);
217217

@@ -334,7 +334,7 @@ TEST(ArithmeticEvaluator, Cycle) {
334334

335335
SourceManager sourceMgr;
336336
DiagnosticEngine diags(sourceMgr);
337-
Evaluator evaluator(diags, CycleDiagnosticKind::FullDiagnose);
337+
Evaluator evaluator(diags);
338338
evaluator.registerRequestFunctions(SWIFT_ARITHMETIC_EVALUATOR_ZONE,
339339
arithmeticRequestFunctions);
340340

0 commit comments

Comments
 (0)