Files
swift-mirror/lib/AST/Evaluator.cpp
Doug Gregor 4b9e3ea84b [Evaluator] Detect cycles via the active-requests stack rather than the cache.
Turn the `activeRequests` stack into a `SetVector` and use it to detect
cycles. This approach works for uncached requests, and lets us simplify
the external-caching protocol quite a bit because we no longer record
“in-flight” states. Simplify the cache as well.

Thanks to Graydon for the suggestion.
2018-06-01 08:56:18 -07:00

45 lines
1.3 KiB
C++

//===--- Evaluator.cpp - Request Evaluator Implementation -----------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file implements the Evaluator class that evaluates and caches
// requests.
//
//===----------------------------------------------------------------------===//
#include "swift/AST/Evaluator.h"
#include "swift/Basic/Range.h"
using namespace swift;
AnyRequest::HolderBase::~HolderBase() { }
Evaluator::Evaluator(DiagnosticEngine &diags) : diags(diags) { }
bool Evaluator::checkDependency(const AnyRequest &request) {
if (activeRequests.insert(request))
return false;
diagnoseCycle(request);
return true;
}
void Evaluator::diagnoseCycle(const AnyRequest &request) {
request.diagnoseCycle(diags);
for (const auto &step : reversed(activeRequests)) {
if (step == request) return;
step.noteCycleStep(diags);
}
llvm_unreachable("Diagnosed a cycle but it wasn't represented in the stack");
}