jsonnet icon indicating copy to clipboard operation
jsonnet copied to clipboard

Rewrite manifestJson to execute "stacklessly" inside evaluate()

Open johnbartholomew opened this issue 11 months ago • 1 comments

This gets rid of the mutual recursion between manifestJson and evaluate, turning the manifestJson processing into a part of the interpreter's main loop. It should remove one avenue for native stack overflows during execution. Of course, the runtime still tracks its own internal call stack depth and can safely abort.

The Interpreter needed to be able to convert things to JSON anyway, as this is the behaviour of string coercion (for string concatenation), and also the behaviour when using the error operator/statement.

Some general notes:

  • This pokes deeply into the interpreter machinery, which is complex and highly stateful, so there is a high chance of errors in the implementation.
  • It's probably less efficient than the previous implementation.
  • Interpreter::evaluate was already a really long function; this makes it even longer.
  • The Frame struct gets even bigger.

TL;DR: This is not ready yet, and might never be ready. But hey, it's been fun to make. Consider it just a sketch or prototype for now.

Edit - Note that there is still potentially deep recursion in some other pieces of the interpreter code. For example, code dealing with HeapExtendedObject (e.g., objectFieldsAux, objectInvariants, countLeaves, findObject) needs to recurse through the object inheritance tree. Not sure that's a problem though.

johnbartholomew avatar Mar 09 '24 14:03 johnbartholomew

I think it's a good idea and the code looks reasonable. What is missing?

sbarzowski avatar Jun 23 '24 12:06 sbarzowski