Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

johnbartholomew
Copy link
Collaborator

@johnbartholomew johnbartholomew commented Mar 9, 2024

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.

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.

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.
@sbarzowski
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants