From e9520ffd067a6a7ecefd0ef3d1b29c055e205e65 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Wed, 27 Nov 2024 02:09:08 +0100 Subject: [PATCH] libexpr: add hidden pos origin for builtin code currently only used to hide the nix code of derivation from stack traces and debug frames, but perhaps we'll find it useful for other things too. Change-Id: Ie5667873d8858d25dd4113bdf454e800b59082d7 --- lix/libexpr/eval.cc | 12 ++++-------- lix/libexpr/eval.hh | 2 -- lix/libexpr/primops.cc | 2 +- lix/libutil/position.cc | 6 +++++- lix/libutil/position.hh | 5 ++++- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lix/libexpr/eval.cc b/lix/libexpr/eval.cc index cab7f6c46..42649c98d 100644 --- a/lix/libexpr/eval.cc +++ b/lix/libexpr/eval.cc @@ -268,7 +268,6 @@ EvalState::EvalState( std::shared_ptr buildStore) : s(symbols) , repair(NoRepair) - , derivationInternal(CanonPath("/builtin/derivation.nix")) , store(store) , buildStore(buildStore ? buildStore : store) , regexCache(makeRegexCache()) @@ -1331,13 +1330,10 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v) state.forceValue(*vCurrent, (posCurrent ? posCurrent : this->pos)); } catch (Error & e) { - if (posCurrent) { - auto pos2r = state.positions[posCurrent]; - auto origin = std::get_if(&pos2r.origin); - if (!(origin && *origin == state.derivationInternal)) - e.addTrace(state.positions[posCurrent], "while evaluating the attribute '%1%'", - showAttrPath(state, env, attrPath)); - } + auto pos2r = state.positions[posCurrent]; + if (pos2r && !std::get_if(&pos2r.origin)) + e.addTrace(pos2r, "while evaluating the attribute '%1%'", + showAttrPath(state, env, attrPath)); throw; } diff --git a/lix/libexpr/eval.hh b/lix/libexpr/eval.hh index 06e8aee4e..c5beebdbe 100644 --- a/lix/libexpr/eval.hh +++ b/lix/libexpr/eval.hh @@ -284,8 +284,6 @@ public: */ std::optional allowedPaths; - const SourcePath derivationInternal; - /** * Store used to materialise .drv files. */ diff --git a/lix/libexpr/primops.cc b/lix/libexpr/primops.cc index 3934c9ba9..2dce86536 100644 --- a/lix/libexpr/primops.cc +++ b/lix/libexpr/primops.cc @@ -2852,7 +2852,7 @@ void EvalState::createBaseEnv() char code[] = #include "primops/derivation.nix.gen.hh" ; - eval(*parse(code, sizeof(code), derivationInternal, {CanonPath::root}, staticBaseEnv), *vDerivation); + eval(*parse(code, sizeof(code), Pos::Hidden{}, {CanonPath::root}, staticBaseEnv), *vDerivation); } diff --git a/lix/libutil/position.cc b/lix/libutil/position.cc index bbeb2e579..cf2ff4b45 100644 --- a/lix/libutil/position.cc +++ b/lix/libutil/position.cc @@ -68,6 +68,9 @@ std::optional Pos::getSource() const } catch (Error &) { return std::nullopt; } + }, + [](Hidden) -> std::optional { + return std::nullopt; } }, origin); } @@ -79,7 +82,8 @@ void Pos::print(std::ostream & out, bool showOrigin) const [&](const std::monostate &) { out << "«none»"; }, [&](const Pos::Stdin &) { out << "«stdin»"; }, [&](const Pos::String & s) { out << "«string»"; }, - [&](const SourcePath & path) { out << path; } + [&](const SourcePath & path) { out << path; }, + [&](Hidden) { out << "«internal»"; }, }, origin); out << ":"; } diff --git a/lix/libutil/position.hh b/lix/libutil/position.hh index 9820ed177..3f89a0f5a 100644 --- a/lix/libutil/position.hh +++ b/lix/libutil/position.hh @@ -38,8 +38,11 @@ struct Pos bool operator<(const String & rhs) const { return *source < *rhs.source; } }; + struct Hidden { + auto operator<=>(const Hidden &) const = default; + }; - typedef std::variant Origin; + typedef std::variant