Skip to content

Commit eaf22c2

Browse files
committed
[Request-evaluator] Add cacheOutput() operation to populate the cache.
Allow one to cache the output for a particular request when it is known a priori, such as when the known result is deserialized.
1 parent 7228864 commit eaf22c2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

include/swift/AST/Evaluator.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,24 @@ class Evaluator {
285285
(*this)(requests)...);
286286
}
287287

288+
/// Cache a precomputed value for the given request, so that it will not
289+
/// be computed.
290+
template<typename Request,
291+
typename std::enable_if<Request::hasExternalCache>::type* = nullptr>
292+
void cacheOutput(const Request &request,
293+
typename Request::OutputType &&output) {
294+
request.cacheResult(std::move(output));
295+
}
296+
297+
/// Cache a precomputed value for the given request, so that it will not
298+
/// be computed.
299+
template<typename Request,
300+
typename std::enable_if<!Request::hasExternalCache>::type* = nullptr>
301+
void cacheOutput(const Request &request,
302+
typename Request::OutputType &&output) {
303+
cache.insert({getCanonicalRequest(request), std::move(output)});
304+
}
305+
288306
/// Clear the cache stored within this evaluator.
289307
///
290308
/// Note that this does not clear the caches of requests that use external

0 commit comments

Comments
 (0)