From 523bd9dce89c29cda3b50f78911d534556775f5f Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Fri, 24 Jan 2025 18:20:44 +0100 Subject: [PATCH] libexpr: asyncify EvalPaths::realiseContext Change-Id: Ic2cf2ded1ef2a75f11112b18431df4ccfd04180f --- lix/libexpr/eval.hh | 2 +- lix/libexpr/primops.cc | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lix/libexpr/eval.hh b/lix/libexpr/eval.hh index 44082018a..c1f224e45 100644 --- a/lix/libexpr/eval.hh +++ b/lix/libexpr/eval.hh @@ -487,7 +487,7 @@ public: * Realise the given context, and return a mapping from the placeholders * used to construct the associated value to their final store path */ - [[nodiscard]] StringMap realiseContext(const NixStringContext & context); + [[nodiscard]] kj::Promise> realiseContext(const NixStringContext & context); }; struct EvalStatistics diff --git a/lix/libexpr/primops.cc b/lix/libexpr/primops.cc index cfbf86ced..f9e363e34 100644 --- a/lix/libexpr/primops.cc +++ b/lix/libexpr/primops.cc @@ -39,8 +39,8 @@ namespace nix { * Miscellaneous *************************************************************/ -StringMap EvalPaths::realiseContext(const NixStringContext & context) -{ +kj::Promise> EvalPaths::realiseContext(const NixStringContext & context) +try { std::vector drvs; StringMap res; @@ -71,7 +71,7 @@ StringMap EvalPaths::realiseContext(const NixStringContext & context) }, c.raw); } - if (drvs.empty()) return {}; + if (drvs.empty()) co_return StringMap{}; if (!evalSettings.enableImportFromDerivation) errors.make( @@ -114,7 +114,9 @@ StringMap EvalPaths::realiseContext(const NixStringContext & context) } } - return res; + co_return res; +} catch (...) { + co_return result::current_exception(); } static auto realisePath(EvalState & state, const PosIdx pos, Value & v, auto checkFn) @@ -124,7 +126,7 @@ static auto realisePath(EvalState & state, const PosIdx pos, Value & v, auto che auto path = state.coerceToPath(noPos, v, context, "while realising the context of a path"); try { - StringMap rewrites = state.ctx.paths.realiseContext(context); + StringMap rewrites = state.aio.blockOn(state.ctx.paths.realiseContext(context)); return checkFn(SourcePath(CanonPath( state.ctx.paths.toRealPath(rewriteStrings(path.canonical().abs(), rewrites), context) @@ -321,7 +323,7 @@ void prim_exec(EvalState & state, const PosIdx pos, Value * * args, Value & v) false, false).toOwned()); } try { - auto _ = state.ctx.paths.realiseContext(context); // FIXME: Handle CA derivations + auto _ = state.aio.blockOn(state.ctx.paths.realiseContext(context)); // FIXME: Handle CA derivations } catch (InvalidPathError & e) { e.addTrace(state.ctx.positions[pos], "while realising the context for builtins.exec"); throw; @@ -1305,7 +1307,7 @@ static void prim_findFile(EvalState & state, const PosIdx pos, Value * * args, V false, false).toOwned(); try { - auto rewrites = state.ctx.paths.realiseContext(context); + auto rewrites = state.aio.blockOn(state.ctx.paths.realiseContext(context)); path = rewriteStrings(path, rewrites); } catch (InvalidPathError & e) { state.ctx.errors.make( @@ -1495,7 +1497,7 @@ static void addPath( try { // FIXME: handle CA derivation outputs (where path needs to // be rewritten to the actual output). - auto rewrites = state.ctx.paths.realiseContext(context); + auto rewrites = state.aio.blockOn(state.ctx.paths.realiseContext(context)); path = state.ctx.paths.toRealPath(rewriteStrings(path, rewrites), context); StorePathSet refs;