@@ -29,45 +29,68 @@ namespace swift {
29
29
30
30
class Evaluator ;
31
31
32
+ // / Describes how the result for a particular request will be cached.
33
+ enum class CacheKind {
34
+ // / The result for a particular request should never be cached.
35
+ Uncached,
36
+ // / The result for a particular request should be cached within the
37
+ // / evaluator itself.
38
+ Cached,
39
+ // / The result of a particular request will be cached via some separate
40
+ // / mechanism, such as a mutable data structure.
41
+ SeparatelyCached,
42
+ };
43
+
32
44
// / CRTP base class that describes a request operation that takes values
33
45
// / with the given input types (\c Inputs...) and produces an output of
34
46
// / the given type.
35
47
// /
36
48
// / \tparam Derived The final, derived class type for the request.
49
+ // / \tparam Caching Describes how the output value is cached, if at all.
37
50
// / \tparam Output The type of the result produced by evaluating this request.
38
51
// / \tparam Inputs The types of the inputs to this request, i.e., the values
39
52
// / that comprise the request itself. These will determine the uniqueness of
40
53
// / the request.
41
54
// /
42
- // / The Derived class needs to implement several operations. The most important
43
- // / one takes an evaluator and the input values, then computes the final
44
- // / result:
55
+ // / The \c Derived class needs to implement several operations. The most
56
+ // / important one takes an evaluator and the input values, then computes the
57
+ // / final result:
45
58
// / \code
46
59
// / Output operator()(Evaluator &evaluator, Inputs...) const;
47
60
// / \endcode
48
61
// /
49
- // / The Derived class will also need to implement an operation to break a
62
+ // / The \c Derived class will also need to implement an operation to break a
50
63
// / cycle if one is found, i.e.,
51
64
// / \code
52
65
// / OutputType breakCycle() const;
53
66
// / \endcode
54
67
// /
55
- // / Cycle diagnostics can be handled in one of two ways. Either the Derived
68
+ // / Cycle diagnostics can be handled in one of two ways. Either the \c Derived
56
69
// / class can implement the two cycle-diagnosing operations directly:
57
70
// / \code
58
71
// / void diagnoseCycle(DiagnosticEngine &diags) const;
59
72
// / void noteCycleStep(DiagnosticEngine &diags) const;
60
73
// / \endcode
61
74
// /
62
- // / Or the Derived class can provide a "diagnostic location" operation and
75
+ // / Or the \c Derived class can provide a "diagnostic location" operation and
63
76
// / diagnostic values for the main cycle diagnostic and a "note" describing a
64
77
// / step within the chain of diagnostics:
65
78
// / \code
66
79
// / T getCycleDiagnosticLoc(Inputs...) const;
67
80
// / static constexpr Diag<Inputs...> cycleDiagnostic = ...;
68
81
// / static constexpr Diag<Inputs...> cycleStepDiagnostic = ...;
69
82
// / \endcode
70
- template <typename Derived, typename Output, typename ...Inputs>
83
+ // /
84
+ // / Value caching is determined by the \c Caching parameter. When
85
+ // / \c Caching == CacheKind::SeparatelyCached, the \c Derived class is
86
+ // / responsible for implementing the two operations responsible to managing
87
+ // / the cache:
88
+ // / \code
89
+ // / Optional<Output> getCachedResult() const;
90
+ // / void cacheResult(Output value) const;
91
+ // / \endcode
92
+ template <typename Derived, CacheKind Caching, typename Output,
93
+ typename ...Inputs>
71
94
class SimpleRequest {
72
95
std::tuple<Inputs...> storage;
73
96
@@ -99,6 +122,9 @@ class SimpleRequest {
99
122
const std::tuple<Inputs...> &getStorage () const { return storage; }
100
123
101
124
public:
125
+ static const bool isEverCached = (Caching != CacheKind::Uncached);
126
+ static const bool hasExternalCache = (Caching == CacheKind::SeparatelyCached);
127
+
102
128
using OutputType = Output;
103
129
104
130
explicit SimpleRequest (const Inputs& ...inputs)
0 commit comments