Skip to content

Commit

Permalink
libnixt: hack eval cache instead of parse cache (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc authored Apr 8, 2024
1 parent 8eab44b commit 4981a97
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions libnixt/include/nixt/HackCache.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// Access ParseCache in \p nix::EvalState
/// Access EvalCache in \p nix::EvalState

#pragma once

Expand All @@ -7,11 +7,11 @@
namespace nixt {

#if HAVE_BOEHMGC
using FileParseCache = std::map<
nix::SourcePath, nix::Expr *, std::less<nix::SourcePath>,
traceable_allocator<std::pair<const nix::SourcePath, nix::Expr *>>>;
using FileEvalCache =
std::map<nix::SourcePath, nix::Value, std::less<nix::SourcePath>,
traceable_allocator<std::pair<const nix::SourcePath, nix::Value>>>;
#else
using FileParseCache = std::map<nix::SourcePath, nix::Expr *>;
using FileEvalCache = std::map<nix::SourcePath, nix::Expr *>;
#endif

namespace detail {
Expand All @@ -35,16 +35,16 @@ typename RB<Tag, p>::F RB<Tag, p>::FO;

// Impl

struct ParseCacheF {
using type = FileParseCache nix::EvalState::*;
struct EvalCacheF {
using type = FileEvalCache nix::EvalState::*;
};

template struct RB<ParseCacheF, &nix::EvalState::fileParseCache>;
template struct RB<EvalCacheF, &nix::EvalState::fileEvalCache>;

} // namespace detail

inline FileParseCache &getFileParseCache(nix::EvalState &S) {
return S.*detail::R<detail::ParseCacheF>::P;
inline FileEvalCache &getFileEvalCache(nix::EvalState &S) {
return S.*detail::R<detail::EvalCacheF>::P;
}

} // namespace nixt
4 changes: 2 additions & 2 deletions nixd/nix-node-eval/src/EvalProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ void EvalProvider::onRegisterBC(const rpc::RegisterBCParams &Params) {
State->eval(AST, V);

// Inject pre-parsed AST into EvalState cache
auto Cache = nixt::getFileParseCache(*State);
Cache[CachePath] = AST;
auto &Cache = nixt::getFileEvalCache(*State);
Cache[CachePath] = V;
}

void EvalProvider::onExprValue(const ExprValueParams &Params,
Expand Down

0 comments on commit 4981a97

Please sign in to comment.