Skip to content

Commit

Permalink
Revert "Implement noAllocationValue for Expr's and use it to avoid so…
Browse files Browse the repository at this point in the history
…me allocs"

This reverts commit 4a2c47a.
  • Loading branch information
infinisil committed Dec 5, 2020
1 parent ba195b7 commit cff6f8f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
34 changes: 16 additions & 18 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -826,21 +826,15 @@ void EvalState::mkPos(Value & v, Pos * pos)
mkNull(v);
}

unsigned long nrAvoided = 0;

/* Create a thunk for the delayed computation of the given expression
in the given environment. But if the expression is a variable,
then look it up right away. This significantly reduces the number
of thunks allocated. */
Value * Expr::maybeThunk(EvalState & state, Env & env)
{
Value * v = noAllocationValue(state, env);
if (!v) {
v = state.allocValue();
mkThunk(*v, env, this);
} else {
nrAvoided++;
}
Value * v = state.allocValue();
mkThunk(*v, env, this);
return v;
}

Expand All @@ -849,35 +843,39 @@ void Expr::evalWithStrategy(EvalState & state, Env & env, Value & v, EvalStrateg
abort();
}

Value * Expr::noAllocationValue(EvalState & state, Env & env)
{
return nullptr;
}
unsigned long nrAvoided = 0;

Value * ExprVar::noAllocationValue(EvalState & state, Env & env)
Value * ExprVar::maybeThunk(EvalState & state, Env & env)
{
Value * v = state.lookupVar(&env, *this, true);
/* The value might not be initialised in the environment yet.
In that case, ignore it. */
return state.lookupVar(&env, *this, true);
if (v) { nrAvoided++; return v; }
return Expr::maybeThunk(state, env);
}

Value * ExprString::noAllocationValue(EvalState & state, Env & env)

Value * ExprString::maybeThunk(EvalState & state, Env & env)
{
nrAvoided++;
return &v;
}

Value * ExprInt::noAllocationValue(EvalState & state, Env & env)
Value * ExprInt::maybeThunk(EvalState & state, Env & env)
{
nrAvoided++;
return &v;
}

Value * ExprFloat::noAllocationValue(EvalState & state, Env & env)
Value * ExprFloat::maybeThunk(EvalState & state, Env & env)
{
nrAvoided++;
return &v;
}

Value * ExprPath::noAllocationValue(EvalState & state, Env & env)
Value * ExprPath::maybeThunk(EvalState & state, Env & env)
{
nrAvoided++;
return &v;
}

Expand Down
12 changes: 5 additions & 7 deletions src/libexpr/nixexpr.hh
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ struct Expr


virtual Value * maybeThunk(EvalState & state, Env & env);
// Return a Value if it can be obtained without doing any allocations
virtual Value * noAllocationValue(EvalState & state, Env & env);
virtual void setName(Symbol & name);
virtual Pos getPos() { return noPos; };
};
Expand All @@ -118,7 +116,7 @@ struct ExprInt : Expr
Value v;
ExprInt(NixInt n) : n(n) { mkInt(v, n); };
COMMON_METHODS
Value * noAllocationValue(EvalState & state, Env & env);
Value * maybeThunk(EvalState & state, Env & env);
};

struct ExprFloat : Expr
Expand All @@ -127,7 +125,7 @@ struct ExprFloat : Expr
Value v;
ExprFloat(NixFloat nf) : nf(nf) { mkFloat(v, nf); };
COMMON_METHODS
Value * noAllocationValue(EvalState & state, Env & env);
Value * maybeThunk(EvalState & state, Env & env);
};

struct ExprString : Expr
Expand All @@ -136,7 +134,7 @@ struct ExprString : Expr
Value v;
ExprString(const Symbol & s) : s(s) { mkString(v, s); };
COMMON_METHODS
Value * noAllocationValue(EvalState & state, Env & env);
Value * maybeThunk(EvalState & state, Env & env);
};

/* Temporary class used during parsing of indented strings. */
Expand All @@ -152,7 +150,7 @@ struct ExprPath : Expr
Value v;
ExprPath(const string & s) : s(s) { mkPathNoCopy(v, this->s.c_str()); };
COMMON_METHODS
Value * noAllocationValue(EvalState & state, Env & env);
Value * maybeThunk(EvalState & state, Env & env);
};

struct ExprVar : Expr
Expand All @@ -176,7 +174,7 @@ struct ExprVar : Expr
ExprVar(const Symbol & name) : name(name) { };
ExprVar(const Pos & pos, const Symbol & name) : pos(pos), name(name) { };
COMMON_METHODS
Value * noAllocationValue(EvalState & state, Env & env);
Value * maybeThunk(EvalState & state, Env & env);
Pos getPos() { return pos; };
};

Expand Down

0 comments on commit cff6f8f

Please sign in to comment.