From 27d0f6747d7e70be4b9ade28ce77444e6135cadb Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Mon, 16 May 2022 15:17:35 +0200 Subject: [PATCH] resolve redundant priority passing, wrap NixInt in eval-cache variant --- src/libcmd/installables.cc | 4 ++-- src/libcmd/installables.hh | 2 +- src/libexpr/eval-cache.cc | 6 +++--- src/libexpr/eval-cache.hh | 3 ++- src/nix/profile.cc | 4 ++-- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 3f6dfd592..635ce19b6 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -609,7 +609,7 @@ InstallableFlake::InstallableFlake( throw UsageError("'--arg' and '--argstr' are incompatible with flakes"); } -std::tuple> InstallableFlake::toDerivation() +std::tuple InstallableFlake::toDerivation() { auto attr = getCursor(*state); @@ -650,7 +650,7 @@ std::tupleflake.lockedRef, std::move(drvInfo), priority}; + return {attrPath, getLockedFlake()->flake.lockedRef, std::move(drvInfo)}; } std::vector InstallableFlake::toDerivations() diff --git a/src/libcmd/installables.hh b/src/libcmd/installables.hh index d7b61f1b8..5d715210e 100644 --- a/src/libcmd/installables.hh +++ b/src/libcmd/installables.hh @@ -177,7 +177,7 @@ struct InstallableFlake : InstallableValue Value * getFlakeOutputs(EvalState & state, const flake::LockedFlake & lockedFlake); - std::tuple> toDerivation(); + std::tuple toDerivation(); std::vector toDerivations() override; diff --git a/src/libexpr/eval-cache.cc b/src/libexpr/eval-cache.cc index bf811c8ed..6b3c27fd5 100644 --- a/src/libexpr/eval-cache.cc +++ b/src/libexpr/eval-cache.cc @@ -306,7 +306,7 @@ struct AttrDb case AttrType::Bool: return {{rowId, queryAttribute.getInt(2) != 0}}; case AttrType::Int: - return {{rowId, queryAttribute.getInt(2)}}; + return {{rowId, (int_t) queryAttribute.getInt(2)}}; case AttrType::ListOfStrings: return {{rowId, tokenizeString>(queryAttribute.getStr(2), "\t")}}; case AttrType::Missing: @@ -649,9 +649,9 @@ NixInt AttrCursor::getInt() if (!cachedValue) cachedValue = root->db->getAttr(getKey()); if (cachedValue && !std::get_if(&cachedValue->second)) { - if (auto i = std::get_if(&cachedValue->second)) { + if (auto i = std::get_if(&cachedValue->second)) { debug("using cached Integer attribute '%s'", getAttrPathStr()); - return *i; + return (*i).x; } else throw TypeError("'%s' is not an Integer", getAttrPathStr()); } diff --git a/src/libexpr/eval-cache.hh b/src/libexpr/eval-cache.hh index ec255c60d..68b5952eb 100644 --- a/src/libexpr/eval-cache.hh +++ b/src/libexpr/eval-cache.hh @@ -52,6 +52,7 @@ struct placeholder_t {}; struct missing_t {}; struct misc_t {}; struct failed_t {}; +struct int_t { NixInt x; int_t(NixInt x) : x(x) {}; }; typedef uint64_t AttrId; typedef std::pair AttrKey; typedef std::pair string_t; @@ -64,7 +65,7 @@ typedef std::variant< misc_t, failed_t, bool, - NixInt, + int_t, std::vector > AttrValue; diff --git a/src/nix/profile.cc b/src/nix/profile.cc index ca5041873..1aae347df 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -300,7 +300,7 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile if (auto installable2 = std::dynamic_pointer_cast(installable)) { // FIXME: make build() return this? - auto [attrPath, resolvedRef, drv, priority] = installable2->toDerivation(); + auto [attrPath, resolvedRef, drv] = installable2->toDerivation(); element.source = ProfileElementSource { installable2->flakeRef, resolvedRef, @@ -475,7 +475,7 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf Strings{}, lockFlags); - auto [attrPath, resolvedRef, drv, priority] = installable->toDerivation(); + auto [attrPath, resolvedRef, drv] = installable->toDerivation(); if (element.source->resolvedRef == resolvedRef) continue;