From 512afd8b7a68f8226443a8df378f5208464435ef Mon Sep 17 00:00:00 2001 From: regnat Date: Thu, 3 Jun 2021 15:29:43 +0200 Subject: [PATCH] Use the cache in the outer shell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure that we don’t discard it before entering the evaluator proper --- src/libcmd/installables.cc | 10 ++++------ src/libexpr/attr-path.cc | 11 +++++++---- src/libexpr/eval.hh | 2 ++ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index fe52912cf..cdd965b9a 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -428,12 +428,10 @@ Value * InstallableFlake::getFlakeOutputs(EvalState & state, const flake::Locked callFlake(state, lockedFlake, *vFlake); - auto aOutputs = vFlake->attrs->get(state.symbols.create("outputs")); - assert(aOutputs); - - state.forceValue(*aOutputs->value); - - return aOutputs->value; + auto vRes = state.allocValue(); + auto gotField = state.getAttrField(*vFlake, {state.symbols.create("outputs")}, noPos, *vRes); + assert(gotField); + return vRes; } ref openEvalCache( diff --git a/src/libexpr/attr-path.cc b/src/libexpr/attr-path.cc index 9dd557205..9c3c1fc4b 100644 --- a/src/libexpr/attr-path.cc +++ b/src/libexpr/attr-path.cc @@ -73,11 +73,14 @@ std::pair findAlongAttrPath(EvalState & state, const string & attr if (attr.empty()) throw Error("empty attribute name in selection path '%1%'", attrPath); - Bindings::iterator a = v->attrs->find(state.symbols.create(attr)); - if (a == v->attrs->end()) + auto v2 = state.allocValue(); + auto gotField = state.getAttrField(*v, {state.symbols.create(attr)}, pos, *v2); + if (!gotField) throw AttrPathNotFound("attribute '%1%' in selection path '%2%' not found", attr, attrPath); - v = &*a->value; - pos = *a->pos; + v = v2; + /* Bindings::iterator a = v->attrs->find(state.symbols.create(attr)); */ + /* v = &*a->value; */ + /* pos = *a->pos; */ } else { diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 36a3b5b74..a86585035 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -353,6 +353,8 @@ private: friend void prim_getAttr(EvalState & state, const Pos & pos, Value * * args, Value & v); friend void prim_match(EvalState & state, const Pos & pos, Value * * args, Value & v); +public: + bool getAttrField(Value & attrs, const std::vector & selector, const Pos & pos, Value & dest); };