From a091a8100a8587185e579d4cff04381e8e074f12 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Sun, 9 Nov 2025 22:09:18 +0300 Subject: [PATCH] libexpr: Clear PosTable contents in EvalState::resetFileCache Otherwise PosTable grows indefinitely for each reload. Since the total input size is limited to 4GB (uint32_t for byte offset PosIdx) it can get exhausted pretty. This ensures that we don't waste memory on reloads as well. --- src/libexpr/eval.cc | 1 + src/libutil/include/nix/util/pos-table.hh | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 7036df957..5ddbac634 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -1113,6 +1113,7 @@ void EvalState::resetFileCache() importResolutionCache->clear(); fileEvalCache->clear(); inputCache->clear(); + positions.clear(); } void EvalState::eval(Expr * e, Value & v) diff --git a/src/libutil/include/nix/util/pos-table.hh b/src/libutil/include/nix/util/pos-table.hh index d944b1353..c5f93a3d5 100644 --- a/src/libutil/include/nix/util/pos-table.hh +++ b/src/libutil/include/nix/util/pos-table.hh @@ -111,6 +111,16 @@ public: return o->origin; return std::monostate{}; } + + /** + * Remove all origins from the table. + */ + void clear() + { + auto lines = linesCache.lock(); + lines->clear(); + origins.clear(); + } }; } // namespace nix