From 72a456210e75989996c8fe3f9d972b1669e01436 Mon Sep 17 00:00:00 2001 From: skye Date: Sun, 1 Mar 2026 15:52:01 -0500 Subject: [PATCH] libexpr: Migrate makePositionThunks to return Value tuple part of #1136 and a step towards #744 Change-Id: Ib2ccea4c098bbb66eaa47645b6fa59e56a6a6964 --- lix/libexpr/eval.cc | 4 +++- lix/libexpr/primops.cc | 12 +++++++----- lix/libexpr/primops.hh | 3 +-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lix/libexpr/eval.cc b/lix/libexpr/eval.cc index 966c9887f..05248325f 100644 --- a/lix/libexpr/eval.cc +++ b/lix/libexpr/eval.cc @@ -857,7 +857,9 @@ void EvalState::mkPos(Value & v, PosIdx p) if (auto path = std::get_if(&origin)) { auto attrs = ctx.buildBindings(3); attrs.alloc(ctx.symbols.sym_file) = {NewValueAs::string, path->to_string()}; - makePositionThunks(*this, p, attrs.alloc(ctx.symbols.sym_line), attrs.alloc(ctx.symbols.sym_column)); + Value & line = attrs.alloc(ctx.symbols.sym_line); + Value & col = attrs.alloc(ctx.symbols.sym_column); + std::tie(line, col) = makePositionThunks(*this, p); v = {NewValueAs::attrs, attrs}; } else v.mkNull(); diff --git a/lix/libexpr/primops.cc b/lix/libexpr/primops.cc index 398aa9955..4e4546962 100644 --- a/lix/libexpr/primops.cc +++ b/lix/libexpr/primops.cc @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -1931,17 +1932,18 @@ static struct LazyPosAcessors { Value lineOfPos = {NewValueAs::primop, primop_lineOfPos}, columnOfPos = {NewValueAs::primop, primop_columnOfPos}; - void operator()(EvalState & state, const PosIdx pos, Value & line, Value & column) + std::tuple operator()(EvalState & state, const PosIdx pos) { Value posV{NewValueAs::integer, NixInt{pos.id}}; - line = {NewValueAs::app, state.ctx.mem, lineOfPos, posV}; - column = {NewValueAs::app, state.ctx.mem, columnOfPos, posV}; + Value line = {NewValueAs::app, state.ctx.mem, lineOfPos, posV}; + Value column = {NewValueAs::app, state.ctx.mem, columnOfPos, posV}; + return std::make_tuple(line, column); } } makeLazyPosAccessors; -void makePositionThunks(EvalState & state, const PosIdx pos, Value & line, Value & column) +std::tuple makePositionThunks(EvalState & state, const PosIdx pos) { - makeLazyPosAccessors(state, pos, line, column); + return makeLazyPosAccessors(state, pos); } /* Dynamic version of the `?' operator. */ diff --git a/lix/libexpr/primops.hh b/lix/libexpr/primops.hh index dcc611f38..852f7d9a6 100644 --- a/lix/libexpr/primops.hh +++ b/lix/libexpr/primops.hh @@ -55,6 +55,5 @@ void prim_importNative(EvalState & state, Value * * args, Value & v); */ void prim_exec(EvalState & state, Value * * args, Value & v); -void makePositionThunks(EvalState & state, const PosIdx pos, Value & line, Value & column); - +std::tuple makePositionThunks(EvalState & state, const PosIdx pos); }