Skip to content

Commit

Permalink
EvalState::callFunction(): Make FunctionCallTrace use less stack space
Browse files Browse the repository at this point in the history
The FunctionCallTrace object consumes a few hundred bytes of stack
space, even when tracing is disabled. This was causing stack overflows:

  $ nix-instantiate '<nixpkgs> -A texlive.combined.scheme-full --dry-run
  error: stack overflow (possible infinite recursion)

This is with the default stack size of 8 MiB.

Putting the object on the heap reduces stack usage to < 5 MiB.
  • Loading branch information
edolstra committed Dec 10, 2019
1 parent 61cc9f3 commit 98ef116
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/libexpr/eval.cc
Expand Up @@ -1091,10 +1091,9 @@ void EvalState::callPrimOp(Value & fun, Value & arg, Value & v, const Pos & pos)

void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & pos)
{
std::optional<FunctionCallTrace> trace;
if (evalSettings.traceFunctionCalls) {
trace.emplace(pos);
}
std::unique_ptr<FunctionCallTrace> trace;
if (evalSettings.traceFunctionCalls)
trace = std::make_unique<FunctionCallTrace>(pos);

forceValue(fun, pos);

Expand Down

0 comments on commit 98ef116

Please sign in to comment.