From 1fc9ba4885f5a16e263bcc5e58bef68e3aa32cea Mon Sep 17 00:00:00 2001 From: Kane York Date: Thu, 13 Aug 2020 16:40:27 -0700 Subject: refactor(tvix): always pass Bindings by ptr, use shared/unique_ptr Value now carries a shared_ptr, and all Bindings constructors return a unique_ptr. The test that wanted to compare two Bindings by putting them into Values has been modified to use the new Equal() method on Bindings (extracted from EvalState). Change-Id: I8dfb60e65fdabb717e3b3e5d56d5b3fc82f70883 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1744 Tested-by: BuildkiteCI Reviewed-by: glittershark Reviewed-by: tazjin --- third_party/nix/src/libexpr/get-drvs.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'third_party/nix/src/libexpr/get-drvs.cc') diff --git a/third_party/nix/src/libexpr/get-drvs.cc b/third_party/nix/src/libexpr/get-drvs.cc index 02ddae1f886c..d81fb5dfadc8 100644 --- a/third_party/nix/src/libexpr/get-drvs.cc +++ b/third_party/nix/src/libexpr/get-drvs.cc @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -13,7 +14,8 @@ namespace nix { -DrvInfo::DrvInfo(EvalState& state, std::string attrPath, Bindings* attrs) +DrvInfo::DrvInfo(EvalState& state, std::string attrPath, + std::shared_ptr attrs) : state(&state), attrs(attrs), attrPath(std::move(attrPath)) {} DrvInfo::DrvInfo(EvalState& state, const ref& store, @@ -161,7 +163,7 @@ std::string DrvInfo::queryOutputName() const { Bindings* DrvInfo::getMeta() { if (meta != nullptr) { - return meta; + return meta.get(); } if (attrs == nullptr) { return nullptr; @@ -172,7 +174,7 @@ Bindings* DrvInfo::getMeta() { } state->forceAttrs(*a->second.value, *a->second.pos); meta = a->second.value->attrs; - return meta; + return meta.get(); } StringSet DrvInfo::queryMetaNames() { @@ -292,8 +294,8 @@ bool DrvInfo::queryMetaBool(const std::string& name, bool def) { } void DrvInfo::setMeta(const std::string& name, Value* v) { - Bindings* old = getMeta(); - meta = Bindings::NewGC(old->size() + 1); + std::shared_ptr old = meta; + meta = std::shared_ptr(Bindings::New(old->size() + 1).release()); Symbol sym = state->symbols.Create(name); if (old != nullptr) { for (auto i : *old) { @@ -308,7 +310,7 @@ void DrvInfo::setMeta(const std::string& name, Value* v) { } /* Cache for already considered attrsets. */ -using Done = std::set; +using Done = absl::flat_hash_set>; /* Evaluate value `v'. If it evaluates to a set of type `derivation', then put information about it in `drvs' (unless it's already in `done'). @@ -364,7 +366,7 @@ static std::string addToPath(const std::string& s1, const std::string& s2) { static std::regex attrRegex("[A-Za-z_][A-Za-z0-9-_+]*"); static void getDerivations(EvalState& state, Value& vIn, - const std::string& pathPrefix, Bindings& autoArgs, + const std::string& pathPrefix, Bindings* autoArgs, DrvInfos& drvs, Done& done, bool ignoreAssertionFailures) { Value v; @@ -434,7 +436,7 @@ static void getDerivations(EvalState& state, Value& vIn, } void getDerivations(EvalState& state, Value& v, const std::string& pathPrefix, - Bindings& autoArgs, DrvInfos& drvs, + Bindings* autoArgs, DrvInfos& drvs, bool ignoreAssertionFailures) { Done done; getDerivations(state, v, pathPrefix, autoArgs, drvs, done, -- cgit 1.4.1