about summary refs log tree commit diff
path: root/third_party
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-22T15·48+0100
committerVincent Ambo <tazjin@google.com>2020-05-22T15·57+0100
commitb3c9166b23aebbbfcbe65ea59e7ea18d876d45db (patch)
tree48b9e56e7bf8608e320fdc1420597f4c026bbb10 /third_party
parente24466c7951a96b35bea947e6e6854f277eda9d7 (diff)
refactor(3p/nix/libexpr): state->allocBindings -> Bindings::NewGC r/805
EvalState::allocBindings had little to do with Bindings, other than
returning them, and didn't belong in that class.
Diffstat (limited to 'third_party')
-rw-r--r--third_party/nix/src/libexpr/attr-set.cc7
-rw-r--r--third_party/nix/src/libexpr/attr-set.hh4
-rw-r--r--third_party/nix/src/libexpr/common-eval-args.cc2
-rw-r--r--third_party/nix/src/libexpr/eval.cc4
-rw-r--r--third_party/nix/src/libexpr/eval.hh2
-rw-r--r--third_party/nix/src/libexpr/get-drvs.cc2
-rw-r--r--third_party/nix/src/nix-env/user-env.cc2
-rw-r--r--third_party/nix/src/nix/edit.cc2
-rw-r--r--third_party/nix/src/nix/search.cc2
-rw-r--r--third_party/nix/src/nix/upgrade-nix.cc2
10 files changed, 14 insertions, 15 deletions
diff --git a/third_party/nix/src/libexpr/attr-set.cc b/third_party/nix/src/libexpr/attr-set.cc
index 71777c95dc7b..e961156487a9 100644
--- a/third_party/nix/src/libexpr/attr-set.cc
+++ b/third_party/nix/src/libexpr/attr-set.cc
@@ -49,10 +49,7 @@ void Bindings::merge(Bindings* other) {
   attributes_.swap(other->attributes_);
 }
 
-// Allocate a new attribute set, making it visible to the garbage collector.
-Bindings* EvalState::allocBindings(size_t _capacity) {
-  return new (GC) Bindings;
-}
+Bindings* Bindings::NewGC() { return new (GC) Bindings; }
 
 void EvalState::mkAttrs(Value& v, size_t capacity) {
   if (capacity == 0) {
@@ -61,7 +58,7 @@ void EvalState::mkAttrs(Value& v, size_t capacity) {
   }
   clearValue(v);
   v.type = tAttrs;
-  v.attrs = new (GC) Bindings;
+  v.attrs = Bindings::NewGC();
   nrAttrsets++;
   nrAttrsInAttrsets += capacity;
 }
diff --git a/third_party/nix/src/libexpr/attr-set.hh b/third_party/nix/src/libexpr/attr-set.hh
index 832733365389..caddc6bebd61 100644
--- a/third_party/nix/src/libexpr/attr-set.hh
+++ b/third_party/nix/src/libexpr/attr-set.hh
@@ -33,6 +33,10 @@ class Bindings {
  public:
   typedef absl::btree_map<Symbol, Attr>::iterator iterator;
 
+  // Allocate a new attribute set that is visible to the garbage
+  // collector.
+  static Bindings* NewGC();
+
   // Return the number of contained elements.
   size_t size();
 
diff --git a/third_party/nix/src/libexpr/common-eval-args.cc b/third_party/nix/src/libexpr/common-eval-args.cc
index 1b9db51c6153..2059d5374195 100644
--- a/third_party/nix/src/libexpr/common-eval-args.cc
+++ b/third_party/nix/src/libexpr/common-eval-args.cc
@@ -33,7 +33,7 @@ MixEvalArgs::MixEvalArgs() {
 }
 
 Bindings* MixEvalArgs::getAutoArgs(EvalState& state) {
-  Bindings* res = state.allocBindings(autoArgs.size());
+  Bindings* res = Bindings::NewGC();
   for (auto& i : autoArgs) {
     Value* v = state.allocValue();
     if (i.second[0] == 'E') {
diff --git a/third_party/nix/src/libexpr/eval.cc b/third_party/nix/src/libexpr/eval.cc
index 679d3ca99617..c6804ee1143d 100644
--- a/third_party/nix/src/libexpr/eval.cc
+++ b/third_party/nix/src/libexpr/eval.cc
@@ -372,7 +372,7 @@ EvalState::EvalState(const Strings& _searchPath, const ref<Store>& store)
 
   clearValue(vEmptySet);
   vEmptySet.type = tAttrs;
-  vEmptySet.attrs = allocBindings(0);
+  vEmptySet.attrs = Bindings::NewGC();
 
   createBaseEnv();
 }
@@ -857,7 +857,7 @@ void ExprAttrs::eval(EvalState& state, Env& env, Value& v) {
     if (hasOverrides) {
       Value* vOverrides = v.attrs->find(overrides->first)->second.value;
       state.forceAttrs(*vOverrides);
-      Bindings* newBnds = state.allocBindings(/* capacity = */ 0);
+      Bindings* newBnds = Bindings::NewGC();
       for (auto& i : *v.attrs) {  // TODO(tazjin): copy constructor?
         newBnds->push_back(i.second);
       }
diff --git a/third_party/nix/src/libexpr/eval.hh b/third_party/nix/src/libexpr/eval.hh
index bc07f9507087..73e35c9b2ce9 100644
--- a/third_party/nix/src/libexpr/eval.hh
+++ b/third_party/nix/src/libexpr/eval.hh
@@ -258,8 +258,6 @@ class EvalState {
 
   Value* allocAttr(Value& vAttrs, const Symbol& name);
 
-  [[deprecated]] static Bindings* allocBindings(size_t capacity);
-
   void mkList(Value& v, size_t size);
   void mkAttrs(Value& v, size_t capacity);
   void mkThunk_(Value& v, Expr* expr);
diff --git a/third_party/nix/src/libexpr/get-drvs.cc b/third_party/nix/src/libexpr/get-drvs.cc
index 822bff369938..6d4ad33be063 100644
--- a/third_party/nix/src/libexpr/get-drvs.cc
+++ b/third_party/nix/src/libexpr/get-drvs.cc
@@ -293,7 +293,7 @@ bool DrvInfo::queryMetaBool(const std::string& name, bool def) {
 void DrvInfo::setMeta(const std::string& name, Value* v) {
   getMeta();
   Bindings* old = meta;
-  meta = state->allocBindings(1 + (old != nullptr ? old->size() : 0));
+  meta = Bindings::NewGC();
   Symbol sym = state->symbols.Create(name);
   if (old != nullptr) {
     for (auto i : *old) {
diff --git a/third_party/nix/src/nix-env/user-env.cc b/third_party/nix/src/nix-env/user-env.cc
index 1535ca0a5cd0..2ca56ed96620 100644
--- a/third_party/nix/src/nix-env/user-env.cc
+++ b/third_party/nix/src/nix-env/user-env.cc
@@ -19,7 +19,7 @@ DrvInfos queryInstalled(EvalState& state, const Path& userEnv) {
   if (pathExists(manifestFile)) {
     Value v;
     state.evalFile(manifestFile, v);
-    Bindings& bindings(*state.allocBindings(0));
+    Bindings& bindings(*Bindings::NewGC());
     getDerivations(state, v, "", bindings, elems, false);
   }
   return elems;
diff --git a/third_party/nix/src/nix/edit.cc b/third_party/nix/src/nix/edit.cc
index 01c2ec7ef0d8..330a845dc520 100644
--- a/third_party/nix/src/nix/edit.cc
+++ b/third_party/nix/src/nix/edit.cc
@@ -29,7 +29,7 @@ struct CmdEdit : InstallableCommand {
 
     Value* v2;
     try {
-      auto dummyArgs = state->allocBindings(0);
+      auto dummyArgs = Bindings::NewGC();
       v2 = findAlongAttrPath(*state, "meta.position", *dummyArgs, *v);
     } catch (Error&) {
       throw Error("package '%s' has no source location information",
diff --git a/third_party/nix/src/nix/search.cc b/third_party/nix/src/nix/search.cc
index 97c5122d6027..9f03fc6f3202 100644
--- a/third_party/nix/src/nix/search.cc
+++ b/third_party/nix/src/nix/search.cc
@@ -110,7 +110,7 @@ struct CmdSearch : SourceExprCommand, MixJSON {
 
         if (v->type == tLambda && toplevel) {
           Value* v2 = state->allocValue();
-          state->autoCallFunction(*state->allocBindings(1), *v, *v2);
+          state->autoCallFunction(*Bindings::NewGC(), *v, *v2);
           v = v2;
           state->forceValue(*v);
         }
diff --git a/third_party/nix/src/nix/upgrade-nix.cc b/third_party/nix/src/nix/upgrade-nix.cc
index 9b060a7f195a..08c411f4b4c5 100644
--- a/third_party/nix/src/nix/upgrade-nix.cc
+++ b/third_party/nix/src/nix/upgrade-nix.cc
@@ -151,7 +151,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand {
     auto state = std::make_unique<EvalState>(Strings(), store);
     auto v = state->allocValue();
     state->eval(state->parseExprFromString(*res.data, "/no-such-path"), *v);
-    Bindings& bindings(*state->allocBindings(0));
+    Bindings& bindings(*Bindings::NewGC());
     auto v2 = findAlongAttrPath(*state, settings.thisSystem, bindings, *v);
 
     return state->forceString(*v2);