mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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.
45 lines
1.3 KiB
C++
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");
|
|
}
|
|
|