From 14db530ac0532a0df29fd6c30e23f736ee7aef92 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sat, 5 Apr 2025 21:57:20 +0200 Subject: [PATCH] libexpr: restrict EvalErrorBuilder to building EvalErrors Change-Id: Iadd0fee4c12c5d0b6ee74dccbf8785c829d20d95 --- lix/libexpr/eval-error.cc | 20 ++++++++++---------- lix/libexpr/eval-error.hh | 8 +++++--- lix/libexpr/eval.hh | 5 +++-- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/lix/libexpr/eval-error.cc b/lix/libexpr/eval-error.cc index c8254a7be..516ea3b90 100644 --- a/lix/libexpr/eval-error.cc +++ b/lix/libexpr/eval-error.cc @@ -5,27 +5,27 @@ namespace nix { -template +template T> EvalErrorBuilder EvalErrorBuilder::withExitStatus(unsigned int exitStatus) && { error->withExitStatus(exitStatus); return std::move(*this); } -template +template T> EvalErrorBuilder EvalErrorBuilder::atPos(PosIdx pos) && { error->err.pos = positions[pos]; return std::move(*this); } -template +template T> EvalErrorBuilder EvalErrorBuilder::atPos(Value & value, PosIdx fallback) && { return std::move(*this).atPos(value.determinePos(fallback)); } -template +template T> EvalErrorBuilder EvalErrorBuilder::withTrace(PosIdx pos, const std::string_view text) && { error->err.traces.push_front( @@ -33,14 +33,14 @@ EvalErrorBuilder EvalErrorBuilder::withTrace(PosIdx pos, const std::string return std::move(*this); } -template +template T> EvalErrorBuilder EvalErrorBuilder::withSuggestions(Suggestions & s) && { error->err.suggestions = s; return std::move(*this); } -template +template T> EvalErrorBuilder EvalErrorBuilder::withFrame(const Env & env, const Expr & expr) && { if (debug) { @@ -55,14 +55,14 @@ EvalErrorBuilder EvalErrorBuilder::withFrame(const Env & env, const Expr & return std::move(*this); } -template +template T> EvalErrorBuilder EvalErrorBuilder::addTrace(PosIdx pos, HintFmt hint) && { error->addTrace(positions[pos], hint); return std::move(*this); } -template +template T> template EvalErrorBuilder EvalErrorBuilder::addTrace(PosIdx pos, std::string_view formatString, const Args &... formatArgs) && @@ -72,7 +72,7 @@ EvalErrorBuilder::addTrace(PosIdx pos, std::string_view formatString, const A return std::move(*this); } -template +template T> void EvalErrorBuilder::debugThrow(NeverAsync) && { if (debug) { @@ -86,7 +86,7 @@ void EvalErrorBuilder::debugThrow(NeverAsync) && throw *error; } -template +template T> void EvalErrorBuilder::throw_() && { throw *error; diff --git a/lix/libexpr/eval-error.hh b/lix/libexpr/eval-error.hh index 2d010293c..e8f2a6a5c 100644 --- a/lix/libexpr/eval-error.hh +++ b/lix/libexpr/eval-error.hh @@ -6,6 +6,7 @@ #include "lix/libutil/types.hh" #include "lix/libexpr/pos-idx.hh" #include "lix/libexpr/pos-table.hh" +#include namespace nix { @@ -15,13 +16,14 @@ struct Env; struct Expr; struct Value; +class EvalError; class EvalState; -template +template T> class EvalErrorBuilder; class EvalError : public Error { - template + template T> friend class EvalErrorBuilder; std::shared_ptr frame; @@ -54,7 +56,7 @@ public: } }; -template +template T> class [[nodiscard]] EvalErrorBuilder final { const PosTable & positions; diff --git a/lix/libexpr/eval.hh b/lix/libexpr/eval.hh index 5b70fcbcb..1634fcd2d 100644 --- a/lix/libexpr/eval.hh +++ b/lix/libexpr/eval.hh @@ -18,6 +18,7 @@ #include "lix/libexpr/repl-exit-status.hh" #include "lix/libutil/backed-string-view.hh" +#include #include #include #include @@ -181,7 +182,7 @@ public: class TraceFrame { friend struct DebugState; - template + template T> friend class EvalErrorBuilder; // holds both the data for this frame *and* a deleter that pulls this frame @@ -356,7 +357,7 @@ struct EvalErrorContext const PosTable & positions; DebugState * debug; - template + template T, typename... Args> [[gnu::noinline]] EvalErrorBuilder make(const Args & ... args) { return EvalErrorBuilder(positions, debug, args...);