remove lazy-pos forceValue

almost all uses of this are interactive, except for deepSeq. deepSeq is
going to be expensive and rare enough to not care much about, and
Value::determinePos should usually be cheap enough to not be too much of
a burden in any case.
This commit is contained in:
pennae 2023-12-11 15:48:24 +01:00
parent f9aee2f2c4
commit 69ed4aee61
9 changed files with 10 additions and 21 deletions

View file

@ -52,7 +52,7 @@ Value * InstallableFlake::getFlakeOutputs(EvalState & state, const flake::Locked
auto aOutputs = vFlake->attrs->get(state.symbols.create("outputs")); auto aOutputs = vFlake->attrs->get(state.symbols.create("outputs"));
assert(aOutputs); assert(aOutputs);
state.forceValue(*aOutputs->value, [&]() { return aOutputs->value->determinePos(noPos); }); state.forceValue(*aOutputs->value, aOutputs->value->determinePos(noPos));
return aOutputs->value; return aOutputs->value;
} }

View file

@ -888,7 +888,7 @@ void NixRepl::evalString(std::string s, Value & v)
{ {
Expr * e = parseString(s); Expr * e = parseString(s);
e->eval(*state, *env, v); e->eval(*state, *env, v);
state->forceValue(v, [&]() { return v.determinePos(noPos); }); state->forceValue(v, v.determinePos(noPos));
} }
@ -907,7 +907,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
str.flush(); str.flush();
checkInterrupt(); checkInterrupt();
state->forceValue(v, [&]() { return v.determinePos(noPos); }); state->forceValue(v, v.determinePos(noPos));
switch (v.type()) { switch (v.type()) {

View file

@ -81,15 +81,7 @@ Env & EvalState::allocEnv(size_t size)
} }
[[gnu::always_inline]]
void EvalState::forceValue(Value & v, const PosIdx pos) void EvalState::forceValue(Value & v, const PosIdx pos)
{
forceValue(v, [&]() { return pos; });
}
template<typename Callable>
void EvalState::forceValue(Value & v, Callable getPos)
{ {
if (v.isThunk()) { if (v.isThunk()) {
Env * env = v.thunk.env; Env * env = v.thunk.env;
@ -110,7 +102,7 @@ void EvalState::forceValue(Value & v, Callable getPos)
// only one black hole can *throw* in any given eval stack so we need not // only one black hole can *throw* in any given eval stack so we need not
// check whether the position is set already. // check whether the position is set already.
if (v.isBlackhole()) if (v.isBlackhole())
e.err.errPos = positions[getPos()]; e.err.errPos = positions[pos];
throw; throw;
} }
} }

View file

@ -2044,7 +2044,7 @@ void EvalState::forceValueDeep(Value & v)
recurse = [&](Value & v) { recurse = [&](Value & v) {
if (!seen.insert(&v).second) return; if (!seen.insert(&v).second) return;
forceValue(v, [&]() { return v.determinePos(noPos); }); forceValue(v, v.determinePos(noPos));
if (v.type() == nAttrs) { if (v.type() == nAttrs) {
for (auto & i : *v.attrs) for (auto & i : *v.attrs)

View file

@ -473,9 +473,6 @@ public:
*/ */
inline void forceValue(Value & v, const PosIdx pos); inline void forceValue(Value & v, const PosIdx pos);
template <typename Callable>
inline void forceValue(Value & v, Callable getPos);
/** /**
* Force a value, then recursively force list elements and * Force a value, then recursively force list elements and
* attributes. * attributes.

View file

@ -198,7 +198,7 @@ StringSet DrvInfo::queryMetaNames()
bool DrvInfo::checkMeta(Value & v) bool DrvInfo::checkMeta(Value & v)
{ {
state->forceValue(v, [&]() { return v.determinePos(noPos); }); state->forceValue(v, v.determinePos(noPos));
if (v.type() == nList) { if (v.type() == nList) {
for (auto elem : v.listItems()) for (auto elem : v.listItems())
if (!checkMeta(*elem)) return false; if (!checkMeta(*elem)) return false;
@ -304,7 +304,7 @@ static bool getDerivation(EvalState & state, Value & v,
bool ignoreAssertionFailures) bool ignoreAssertionFailures)
{ {
try { try {
state.forceValue(v, [&]() { return v.determinePos(noPos); }); state.forceValue(v, v.determinePos(noPos));
if (!state.isDerivation(v)) return true; if (!state.isDerivation(v)) return true;
/* Remove spurious duplicates (e.g., a set like `rec { x = /* Remove spurious duplicates (e.g., a set like `rec { x =

View file

@ -350,7 +350,7 @@ static void main_nix_build(int argc, char * * argv)
takesNixShellAttr(vRoot) ? *autoArgsWithInNixShell : *autoArgs, takesNixShellAttr(vRoot) ? *autoArgsWithInNixShell : *autoArgs,
vRoot vRoot
).first); ).first);
state->forceValue(v, [&]() { return v.determinePos(noPos); }); state->forceValue(v, v.determinePos(noPos));
getDerivations( getDerivations(
*state, *state,
v, v,

View file

@ -128,7 +128,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
/* Evaluate it. */ /* Evaluate it. */
debug("evaluating user environment builder"); debug("evaluating user environment builder");
state.forceValue(topLevel, [&]() { return topLevel.determinePos(noPos); }); state.forceValue(topLevel, topLevel.determinePos(noPos));
NixStringContext context; NixStringContext context;
Attr & aDrvPath(*topLevel.attrs->find(state.sDrvPath)); Attr & aDrvPath(*topLevel.attrs->find(state.sDrvPath));
auto topLevelDrv = state.coerceToStorePath(aDrvPath.pos, *aDrvPath.value, context, ""); auto topLevelDrv = state.coerceToStorePath(aDrvPath.pos, *aDrvPath.value, context, "");

View file

@ -40,7 +40,7 @@ void processExpr(EvalState & state, const Strings & attrPaths,
for (auto & i : attrPaths) { for (auto & i : attrPaths) {
Value & v(*findAlongAttrPath(state, i, autoArgs, vRoot).first); Value & v(*findAlongAttrPath(state, i, autoArgs, vRoot).first);
state.forceValue(v, [&]() { return v.determinePos(noPos); }); state.forceValue(v, v.determinePos(noPos));
NixStringContext context; NixStringContext context;
if (evalOnly) { if (evalOnly) {