From 0ff8c2b06f418700fa1439d2452d648a7fd21c7d Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Tue, 25 Mar 2025 20:14:45 +0100 Subject: [PATCH] libexpr: make undefined var errors non-debuggable in the parser this only affects undefined names outside of with scopes. sending those errors to the debugger when enabled seems rather less useful; unlike in the case of with scopes there's nothing meaningful to inspect. avoiding the debugger also lets us avoid marking the entire parser `NeverAsync`. cf #761 Change-Id: I3599b826ff5b101acf9a3ba70dcdf9e8e02067f0 --- lix/libexpr/eval-error.cc | 6 ++++++ lix/libexpr/eval-error.hh | 7 ++++++- lix/libexpr/nixexpr.cc | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lix/libexpr/eval-error.cc b/lix/libexpr/eval-error.cc index cf2cdc424..62165ff4b 100644 --- a/lix/libexpr/eval-error.cc +++ b/lix/libexpr/eval-error.cc @@ -85,6 +85,12 @@ void EvalErrorBuilder::debugThrow() && throw *error; } +template +void EvalErrorBuilder::throw_() && +{ + throw *error; +} + template class EvalErrorBuilder; template class EvalErrorBuilder; template class EvalErrorBuilder; diff --git a/lix/libexpr/eval-error.hh b/lix/libexpr/eval-error.hh index 2ae775753..8e1a7c25e 100644 --- a/lix/libexpr/eval-error.hh +++ b/lix/libexpr/eval-error.hh @@ -89,9 +89,14 @@ public: addTrace(PosIdx pos, std::string_view formatString, const Args &... formatArgs) &&; /** - * Throw the underlying exception. + * Throw the underlying exception, invoking the debug state callback. */ [[gnu::noinline, gnu::noreturn]] void debugThrow() &&; + + /** + * Throw the underlying exception, bypassing the debug state callback. + */ + [[gnu::noinline, gnu::noreturn]] void throw_() &&; }; } diff --git a/lix/libexpr/nixexpr.cc b/lix/libexpr/nixexpr.cc index db1014050..bdc858558 100644 --- a/lix/libexpr/nixexpr.cc +++ b/lix/libexpr/nixexpr.cc @@ -362,7 +362,7 @@ void ExprVar::bindVars(Evaluator & es, const std::shared_ptr & es.errors.make( "undefined variable '%1%'", es.symbols[name] - ).atPos(pos).debugThrow(); + ).atPos(pos).throw_(); for (auto * e = env.get(); e && !fromWith; e = e->up) fromWith = e->isWith; this->level = withLevel;