libexpr: extract some global constants from EvalState
these do not rely on the GC being initialized. there's no reason for them to not be statics, shared between all eval states in a process. Change-Id: Ib9675f3945d3a0a7097d6c85096adcbd6f441d83
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
Bindings Bindings::EMPTY{0};
|
||||
|
||||
|
||||
/* Allocate a new array of attributes for an attribute set with a specific
|
||||
@@ -15,7 +16,7 @@ namespace nix {
|
||||
Bindings * EvalState::allocBindings(size_t capacity)
|
||||
{
|
||||
if (capacity == 0)
|
||||
return &emptyBindings;
|
||||
return &Bindings::EMPTY;
|
||||
if (capacity > std::numeric_limits<Bindings::size_t>::max())
|
||||
throw Error("attribute set of size %d is too big", capacity);
|
||||
nrAttrsets++;
|
||||
|
||||
@@ -51,6 +51,8 @@ public:
|
||||
typedef uint32_t size_t;
|
||||
PosIdx pos;
|
||||
|
||||
static Bindings EMPTY;
|
||||
|
||||
private:
|
||||
size_t size_, capacity_;
|
||||
Attr attrs[0];
|
||||
|
||||
+1
-4
@@ -255,7 +255,6 @@ EvalState::EvalState(
|
||||
.overrides = symbols.create("__overrides"),
|
||||
}
|
||||
, repair(NoRepair)
|
||||
, emptyBindings(0)
|
||||
, derivationInternal(rootPath(CanonPath("/builtin/derivation.nix")))
|
||||
, store(store)
|
||||
, buildStore(buildStore ? buildStore : store)
|
||||
@@ -276,8 +275,6 @@ EvalState::EvalState(
|
||||
|
||||
static_assert(sizeof(Env) <= 16, "environment must be <= 16 bytes");
|
||||
|
||||
vEmptyList.mkList(0);
|
||||
|
||||
/* Initialise the Nix expression search path. */
|
||||
if (!evalSettings.pureEval) {
|
||||
for (auto & i : _searchPath.elements)
|
||||
@@ -1200,7 +1197,7 @@ void ExprList::eval(EvalState & state, Env & env, Value & v)
|
||||
Value * ExprList::maybeThunk(EvalState & state, Env & env)
|
||||
{
|
||||
if (elems.empty()) {
|
||||
return &state.vEmptyList;
|
||||
return &Value::EMPTY_LIST;
|
||||
}
|
||||
return Expr::maybeThunk(state, env);
|
||||
}
|
||||
|
||||
@@ -187,13 +187,6 @@ public:
|
||||
*/
|
||||
std::optional<PathSet> allowedPaths;
|
||||
|
||||
Bindings emptyBindings;
|
||||
|
||||
/**
|
||||
* Empty list constant.
|
||||
*/
|
||||
Value vEmptyList;
|
||||
|
||||
const SourcePath derivationInternal;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1898,14 +1898,14 @@ static void prim_functionArgs(EvalState & state, const PosIdx pos, Value * * arg
|
||||
{
|
||||
state.forceValue(*args[0], pos);
|
||||
if (args[0]->isPrimOpApp() || args[0]->isPrimOp()) {
|
||||
v.mkAttrs(&state.emptyBindings);
|
||||
v.mkAttrs(&Bindings::EMPTY);
|
||||
return;
|
||||
}
|
||||
if (!args[0]->isLambda())
|
||||
state.error<TypeError>("'functionArgs' requires a function").atPos(pos).debugThrow();
|
||||
|
||||
if (!args[0]->lambda.fun->hasFormals()) {
|
||||
v.mkAttrs(&state.emptyBindings);
|
||||
v.mkAttrs(&Bindings::EMPTY);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
namespace nix
|
||||
{
|
||||
|
||||
Value Value::EMPTY_LIST{Value::list_t{}, {}};
|
||||
|
||||
static void copyContextToValue(Value & v, const NixStringContext & context)
|
||||
{
|
||||
if (!context.empty()) {
|
||||
|
||||
@@ -197,6 +197,11 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Empty list constant.
|
||||
*/
|
||||
static Value EMPTY_LIST;
|
||||
|
||||
// Discount `using NewValueAs::*;`
|
||||
// NOLINTNEXTLINE(bugprone-macro-parentheses)
|
||||
#define USING_VALUETYPE(name) using name = NewValueAs::name
|
||||
|
||||
Reference in New Issue
Block a user