mirror of
https://github.com/NixOS/nix.git
synced 2025-11-25 19:51:00 +01:00
* Playing with strictness.
This commit is contained in:
parent
3d14ed9270
commit
c1179badd5
2 changed files with 18 additions and 2 deletions
|
|
@ -25,6 +25,7 @@ EvalState::EvalState()
|
||||||
addPrimOps();
|
addPrimOps();
|
||||||
|
|
||||||
cacheTerms = getEnv("NIX_TERM_CACHE", "1") == "1";
|
cacheTerms = getEnv("NIX_TERM_CACHE", "1") == "1";
|
||||||
|
strictMode = getEnv("NIX_STRICT", "0") == "1";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -71,6 +72,19 @@ LocalNoInline(void addErrorPrefix(Error & e, const char * s, const string & s2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Expr speculativeEval(EvalState & state, Expr e)
|
||||||
|
{
|
||||||
|
if (!state.strictMode) return e;
|
||||||
|
try {
|
||||||
|
return evalExpr(state, e);
|
||||||
|
} catch (EvalError & err) {
|
||||||
|
/* ignore, pass the original arg and depend on
|
||||||
|
laziness */
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Substitute an argument set into the body of a function. */
|
/* Substitute an argument set into the body of a function. */
|
||||||
static Expr substArgs(EvalState & state,
|
static Expr substArgs(EvalState & state,
|
||||||
Expr body, ATermList formals, Expr arg)
|
Expr body, ATermList formals, Expr arg)
|
||||||
|
|
@ -82,7 +96,7 @@ static Expr substArgs(EvalState & state,
|
||||||
ATermMap args;
|
ATermMap args;
|
||||||
queryAllAttrs(arg, args);
|
queryAllAttrs(arg, args);
|
||||||
for (ATermMap::const_iterator i = args.begin(); i != args.end(); ++i)
|
for (ATermMap::const_iterator i = args.begin(); i != args.end(); ++i)
|
||||||
subs.set(i->key, i->value);
|
subs.set(i->key, speculativeEval(state, i->value));
|
||||||
|
|
||||||
/* Get the formal arguments. */
|
/* Get the formal arguments. */
|
||||||
ATermVector defsUsed;
|
ATermVector defsUsed;
|
||||||
|
|
@ -469,6 +483,7 @@ LocalNoInline(Expr evalCall(EvalState & state, Expr fun, Expr arg))
|
||||||
|
|
||||||
else if (matchFunction1(fun, name, body, pos)) {
|
else if (matchFunction1(fun, name, body, pos)) {
|
||||||
try {
|
try {
|
||||||
|
arg = speculativeEval(state, arg);
|
||||||
ATermMap subs(1);
|
ATermMap subs(1);
|
||||||
subs.set(name, arg);
|
subs.set(name, arg);
|
||||||
return evalExpr(state, substitute(Substitution(0, &subs), body));
|
return evalExpr(state, substitute(Substitution(0, &subs), body));
|
||||||
|
|
@ -725,7 +740,7 @@ Expr evalExpr(EvalState & state, Expr e)
|
||||||
{
|
{
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
|
|
||||||
#if 0
|
#if 1
|
||||||
startNest(nest, lvlVomit,
|
startNest(nest, lvlVomit,
|
||||||
format("evaluating expression: %1%") % e);
|
format("evaluating expression: %1%") % e);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ struct EvalState
|
||||||
unsigned int nrCached;
|
unsigned int nrCached;
|
||||||
|
|
||||||
bool cacheTerms;
|
bool cacheTerms;
|
||||||
|
bool strictMode;
|
||||||
|
|
||||||
EvalState();
|
EvalState();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue