Remove SimpleRequest::breakCycle

This patch removes the need for Request objects to provide a default
cycle-breaking value, instead opting to return llvm::Expected so clients
must handle a cycle failure explicitly.

Currently, all clients do the 'default' behavior, but this opens the
possibility for future requests to handle failures explicitly.
This commit is contained in:
Harlan Haskins
2018-08-01 13:46:21 -07:00
committed by Harlan Haskins
parent be0e1643d6
commit 5a6985f39e
15 changed files with 261 additions and 188 deletions

View File

@@ -54,15 +54,9 @@ enum class CacheKind {
///
/// The \c Derived class needs to implement several operations. The most
/// important one takes an evaluator and the input values, then computes the
/// final result:
/// final result, optionally bubbling up errors from recursive evaulations:
/// \code
/// Output evaluate(Evaluator &evaluator, Inputs...) const;
/// \endcode
///
/// The \c Derived class will also need to implement an operation to break a
/// cycle if one is found, i.e.,
/// \code
/// OutputType breakCycle() const;
/// llvm::Expected<Output> evaluate(Evaluator &evaluator, Inputs...) const;
/// \endcode
///
/// Cycle diagnostics can be handled in one of two ways. Either the \c Derived
@@ -103,8 +97,8 @@ class SimpleRequest {
}
template<size_t ...Indices>
Output callDerived(Evaluator &evaluator,
llvm::index_sequence<Indices...>) const {
llvm::Expected<Output>
callDerived(Evaluator &evaluator, llvm::index_sequence<Indices...>) const {
static_assert(sizeof...(Indices) > 0, "Subclass must define evaluate()");
return asDerived().evaluate(evaluator, std::get<Indices>(storage)...);
}
@@ -131,8 +125,8 @@ public:
: storage(inputs...) { }
/// Request evaluation function that will be registered with the evaluator.
static OutputType evaluateRequest(const Derived &request,
Evaluator &evaluator) {
static llvm::Expected<OutputType>
evaluateRequest(const Derived &request, Evaluator &evaluator) {
return request.callDerived(evaluator,
llvm::index_sequence_for<Inputs...>());
}