about summary refs log tree commit diff
path: root/third_party/nix/src/libexpr/get-drvs.cc
diff options
context:
space:
mode:
authorKane York <kanepyork@gmail.com>2020-08-13T23·40-0700
committerkanepyork <rikingcoding@gmail.com>2020-08-17T02·23+0000
commit1fc9ba4885f5a16e263bcc5e58bef68e3aa32cea (patch)
tree8c53707e223b9516002e3bf80f0e731f8c0f3212 /third_party/nix/src/libexpr/get-drvs.cc
parent38f2ea34f466d8264f7a060627eece5b3cbc40ba (diff)
refactor(tvix): always pass Bindings by ptr, use shared/unique_ptr r/1658
Value now carries a shared_ptr<Bindings>, and all Bindings constructors return a unique_ptr<Bindings>.

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 <grfn@gws.fyi>
Reviewed-by: tazjin <mail@tazj.in>
Diffstat (limited to 'third_party/nix/src/libexpr/get-drvs.cc')
-rw-r--r--third_party/nix/src/libexpr/get-drvs.cc18
1 files changed, 10 insertions, 8 deletions
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 <regex>
 #include <utility>
 
+#include <absl/container/flat_hash_set.h>
 #include <absl/strings/numbers.h>
 #include <glog/logging.h>
 
@@ -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<Bindings> attrs)
     : state(&state), attrs(attrs), attrPath(std::move(attrPath)) {}
 
 DrvInfo::DrvInfo(EvalState& state, const ref<Store>& 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<Bindings> old = meta;
+  meta = std::shared_ptr<Bindings>(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<Bindings*>;
+using Done = absl::flat_hash_set<std::shared_ptr<Bindings>>;
 
 /* 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,