Skip to content

Commit e7f38db

Browse files
committed
[NFC] Have Evaluator's Constructor Read LangOptions
It's a touch cleaner to do this than passing around a pile of bools.
1 parent ec60746 commit e7f38db

File tree

4 files changed

+21
-24
lines changed

4 files changed

+21
-24
lines changed

include/swift/AST/Evaluator.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,7 @@ class Evaluator {
243243
public:
244244
/// Construct a new evaluator that can emit cyclic-dependency
245245
/// diagnostics through the given diagnostics engine.
246-
Evaluator(DiagnosticEngine &diags,
247-
bool debugDumpCycles,
248-
bool buildDependencyGraph,
249-
bool enableExperimentalPrivateDeps);
246+
Evaluator(DiagnosticEngine &diags, const LangOptions &opts);
250247

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

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,10 +549,7 @@ ASTContext::ASTContext(LangOptions &langOpts, TypeCheckerOptions &typeckOpts,
549549
: LangOpts(langOpts),
550550
TypeCheckerOpts(typeckOpts),
551551
SearchPathOpts(SearchPathOpts), SourceMgr(SourceMgr), Diags(Diags),
552-
evaluator(Diags,
553-
langOpts.DebugDumpCycles,
554-
langOpts.BuildRequestDependencyGraph,
555-
langOpts.EnableExperientalPrivateIntransitiveDependencies),
552+
evaluator(Diags, langOpts),
556553
TheBuiltinModule(createBuiltinModule(*this)),
557554
StdlibModuleName(getIdentifier(STDLIB_NAME)),
558555
SwiftShimsModuleName(getIdentifier(SWIFT_SHIMS_NAME)),

lib/AST/Evaluator.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
//===----------------------------------------------------------------------===//
1717
#include "swift/AST/Evaluator.h"
1818
#include "swift/AST/DiagnosticEngine.h"
19+
#include "swift/Basic/LangOptions.h"
1920
#include "swift/Basic/Range.h"
2021
#include "swift/Basic/SourceManager.h"
2122
#include "llvm/ADT/StringExtras.h"
@@ -62,21 +63,20 @@ void Evaluator::registerRequestFunctions(
6263
}
6364

6465
static evaluator::DependencyRecorder::Mode
65-
computeDependencyModeFromFlags(bool enableExperimentalPrivateDeps) {
66+
computeDependencyModeFromFlags(const LangOptions &opts) {
6667
using Mode = evaluator::DependencyRecorder::Mode;
67-
if (enableExperimentalPrivateDeps) {
68+
if (opts.EnableExperientalPrivateIntransitiveDependencies) {
6869
return Mode::ExperimentalPrivateDependencies;
6970
}
7071

7172
return Mode::StatusQuo;
7273
}
7374

74-
Evaluator::Evaluator(DiagnosticEngine &diags, bool debugDumpCycles,
75-
bool buildDependencyGraph,
76-
bool enableExperimentalPrivateDeps)
77-
: diags(diags), debugDumpCycles(debugDumpCycles),
78-
buildDependencyGraph(buildDependencyGraph),
79-
recorder{computeDependencyModeFromFlags(enableExperimentalPrivateDeps)} {}
75+
Evaluator::Evaluator(DiagnosticEngine &diags, const LangOptions &opts)
76+
: diags(diags),
77+
debugDumpCycles(opts.DebugDumpCycles),
78+
buildDependencyGraph(opts.BuildRequestDependencyGraph),
79+
recorder{computeDependencyModeFromFlags(opts)} {}
8080

8181
void Evaluator::emitRequestEvaluatorGraphViz(llvm::StringRef graphVizPath) {
8282
std::error_code error;

unittests/AST/ArithmeticEvaluator.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "swift/AST/DiagnosticEngine.h"
1717
#include "swift/AST/Evaluator.h"
1818
#include "swift/AST/SimpleRequest.h"
19+
#include "swift/Basic/LangOptions.h"
1920
#include "swift/Basic/SourceManager.h"
2021
#include "gtest/gtest.h"
2122
#include <cmath>
@@ -218,10 +219,11 @@ TEST(ArithmeticEvaluator, Simple) {
218219

219220
SourceManager sourceMgr;
220221
DiagnosticEngine diags(sourceMgr);
221-
Evaluator evaluator(diags,
222-
/*debugDumpCycles=*/false,
223-
/*buildDependencyGraph=*/true,
224-
/*privateDependencies*/false);
222+
LangOptions opts;
223+
opts.DebugDumpCycles = false;
224+
opts.BuildRequestDependencyGraph = true;
225+
opts.EnableExperientalPrivateIntransitiveDependencies = false;
226+
Evaluator evaluator(diags, opts);
225227
evaluator.registerRequestFunctions(Zone::ArithmeticEvaluator,
226228
arithmeticRequestFunctions);
227229

@@ -344,10 +346,11 @@ TEST(ArithmeticEvaluator, Cycle) {
344346

345347
SourceManager sourceMgr;
346348
DiagnosticEngine diags(sourceMgr);
347-
Evaluator evaluator(diags,
348-
/*debugDumpCycles=*/false,
349-
/*buildDependencyGraph=*/false,
350-
/*privateDependencies*/false);
349+
LangOptions opts;
350+
opts.DebugDumpCycles = false;
351+
opts.BuildRequestDependencyGraph = false;
352+
opts.EnableExperientalPrivateIntransitiveDependencies = false;
353+
Evaluator evaluator(diags, opts);
351354
evaluator.registerRequestFunctions(Zone::ArithmeticEvaluator,
352355
arithmeticRequestFunctions);
353356

0 commit comments

Comments
 (0)