google / jsonnet

Jsonnet - The data templating language
http://jsonnet.org
Apache License 2.0
6.87k stars 436 forks source link

Rewrite manifestJson to execute "stacklessly" inside evaluate() #1142

Open johnbartholomew opened 4 months ago

johnbartholomew commented 4 months ago

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:

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.

sbarzowski commented 1 month ago

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