about summary refs log tree commit diff
path: root/third_party/nix/src/libexpr/nixexpr.hh
diff options
context:
space:
mode:
authorKane York <kanepyork@gmail.com>2020-08-10T05·42-0700
committerkanepyork <rikingcoding@gmail.com>2020-08-10T22·16+0000
commit906f5c1d2d442b1d34621b97950c38c659b729a6 (patch)
tree48b663ee52e56f8471539afece70de67a0144622 /third_party/nix/src/libexpr/nixexpr.hh
parent42bdaacca62ad5760e5d46315f1e6dc2bcc3fd96 (diff)
fix(3p/nix): inherit Expr from gc, make parser state traceable r/1633
The parser contained vectors, and the primary parser state, that
were not participating in GC tracing.

Change-Id: Ie198592cd7acffd390e3e2ae9595138b56416838
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1706
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
Reviewed-by: glittershark <grfn@gws.fyi>
Diffstat (limited to 'third_party/nix/src/libexpr/nixexpr.hh')
-rw-r--r--third_party/nix/src/libexpr/nixexpr.hh34
1 files changed, 22 insertions, 12 deletions
diff --git a/third_party/nix/src/libexpr/nixexpr.hh b/third_party/nix/src/libexpr/nixexpr.hh
index 7b89fb0c927e..6edfb2a18779 100644
--- a/third_party/nix/src/libexpr/nixexpr.hh
+++ b/third_party/nix/src/libexpr/nixexpr.hh
@@ -74,13 +74,18 @@ struct StaticEnv;
 /* An attribute path is a sequence of attribute names. */
 using AttrName = std::variant<Symbol, Expr*>;
 
-typedef std::vector<AttrName> AttrPath;
+typedef std::vector<AttrName, traceable_allocator<AttrName>> AttrPath;
+
+using AttrNameVector =
+    std::vector<nix::AttrName, traceable_allocator<nix::AttrName>>;
+
+using VectorExprs = std::vector<nix::Expr*, traceable_allocator<nix::Expr*>>;
 
 std::string showAttrPath(const AttrPath& attrPath);
 
 /* Abstract syntax of Nix expressions. */
 
-struct Expr {
+struct Expr : public gc {
   virtual ~Expr(){};
   virtual void show(std::ostream& str) const;
   virtual void bindVars(const StaticEnv& env);
@@ -186,7 +191,7 @@ struct ExprOpHasAttr : Expr {
 struct ExprAttrs : Expr {
   bool recursive;
 
-  struct AttrDef {
+  struct AttrDef : public gc {
     bool inherited;
     Expr* e;
     Pos pos;
@@ -196,17 +201,22 @@ struct ExprAttrs : Expr {
     AttrDef(){};
   };
 
-  typedef absl::flat_hash_map<Symbol, AttrDef> AttrDefs;
+  typedef absl::flat_hash_map<
+      Symbol, AttrDef, absl::container_internal::hash_default_hash<Symbol>,
+      absl::container_internal::hash_default_eq<Symbol>,
+      traceable_allocator<std::pair<const Symbol, AttrDef>>>
+      AttrDefs;
   AttrDefs attrs;
 
-  struct DynamicAttrDef {
+  struct DynamicAttrDef : public gc {
     Expr *nameExpr, *valueExpr;
     Pos pos;
     DynamicAttrDef(Expr* nameExpr, Expr* valueExpr, const Pos& pos)
         : nameExpr(nameExpr), valueExpr(valueExpr), pos(pos){};
   };
 
-  typedef std::vector<DynamicAttrDef> DynamicAttrDefs;
+  typedef std::vector<DynamicAttrDef, traceable_allocator<DynamicAttrDef>>
+      DynamicAttrDefs;
   DynamicAttrDefs dynamicAttrs;
 
   ExprAttrs() : recursive(false){};
@@ -214,20 +224,20 @@ struct ExprAttrs : Expr {
 };
 
 struct ExprList : Expr {
-  std::vector<Expr*> elems;
+  VectorExprs elems;
   ExprList(){};
   COMMON_METHODS
 };
 
-struct Formal {
+struct Formal : public gc {
   Symbol name;
   Expr* def;  // def = default, not definition
   Formal(const Symbol& name, Expr* def) : name(name), def(def){};
 };
 
 // Describes structured function arguments (e.g. `{ a }: ...`)
-struct Formals {
-  typedef std::list<Formal> Formals_;
+struct Formals : public gc {
+  typedef std::list<Formal, traceable_allocator<Formal>> Formals_;
   Formals_ formals;
   std::set<Symbol> argNames;  // used during parsing
   bool ellipsis;
@@ -325,8 +335,8 @@ MakeBinOp(ExprOpConcatLists, "++");
 struct ExprConcatStrings : Expr {
   Pos pos;
   bool forceString;
-  std::vector<Expr*>* es;
-  ExprConcatStrings(const Pos& pos, bool forceString, std::vector<Expr*>* es)
+  nix::VectorExprs* es;
+  ExprConcatStrings(const Pos& pos, bool forceString, nix::VectorExprs* es)
       : pos(pos), forceString(forceString), es(es){};
   COMMON_METHODS
 };