Skip to content

Commit 5498e86

Browse files
author
Harlan Haskins
committed
Use evaluator's dependency printing for cycles
1 parent c31d7f8 commit 5498e86

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

include/swift/AST/Evaluator.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,12 @@ struct CyclicalRequestError :
7878
public:
7979
static char ID;
8080
const Request &request;
81+
const Evaluator &evaluator;
8182

82-
CyclicalRequestError(const Request &request): request(request) {}
83+
CyclicalRequestError(const Request &request, const Evaluator &evaluator)
84+
: request(request), evaluator(evaluator) {}
8385

84-
virtual void log(llvm::raw_ostream &out) const {
85-
out << "Cycle detected:\n";
86-
simple_display(out, request);
87-
out << "\n";
88-
}
86+
virtual void log(llvm::raw_ostream &out) const;
8987

9088
virtual std::error_code convertToErrorCode() const {
9189
// This is essentially unused, but is a temporary requirement for
@@ -259,7 +257,7 @@ class Evaluator {
259257
// Check for a cycle.
260258
if (checkDependency(AnyRequest(request))) {
261259
return llvm::Error(
262-
llvm::make_unique<CyclicalRequestError<Request>>(request));
260+
llvm::make_unique<CyclicalRequestError<Request>>(request, *this));
263261
}
264262

265263
// Make sure we remove this from the set of active requests once we're
@@ -429,6 +427,13 @@ class Evaluator {
429427
"Only meant for use in the debugger");
430428
};
431429

430+
template <typename Request>
431+
void CyclicalRequestError<Request>::log(llvm::raw_ostream &out) const {
432+
out << "Cycle detected:\n";
433+
evaluator.printDependencies(request, out);
434+
out << "\n";
435+
}
436+
432437
} // end namespace evaluator
433438

434439
#endif // SWIFT_AST_EVALUATOR_H

unittests/AST/ArithmeticEvaluator.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,8 @@ TEST(ArithmeticEvaluator, Simple) {
244244
// Dependency printing.
245245

246246
// Cache some values first, so they show up in the result.
247-
auto cachedResult = evaluator(InternallyCachedEvaluationRule(product));
248-
if (auto err = cachedResult.takeError()) {
249-
llvm::handleAllErrors(std::move(err),
250-
[](const CyclicalRequestError<InternallyCachedEvaluationRule> &E) {
251-
llvm_unreachable("no explicit cycles were requested");
252-
});
253-
}
247+
(void)llvm::cantFail(evaluator(InternallyCachedEvaluationRule(product)),
248+
"no explicit cycles were requested");
254249

255250
std::string productDependencies;
256251
{

0 commit comments

Comments
 (0)