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

Store function call state in a stack #294

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

richardmarshall
Copy link
Collaborator

@richardmarshall richardmarshall commented Apr 3, 2024

As functions are called store the current execution state for the function in a stack. This includes the local variables and re.group.{N} variables.

This stack is used to detect recursion and prevent an interpreter panic.

In the future this information could be used for including a VCL stack trace in error output or for accessing calling function state in the debugger.

Note: The current code structure makes accessing the re.group variables directly from the stack pointer a challenge. To keep things simple I retained the save / restore model we currently have for those. If there is consensus on the idea of using a stack frame model we can decide if it makes sense to restructure things to make access through the stack pointer possible.

Resolves #293, #297

As functions are called store the current execution state for the
function in a stack. This includes the local variables and re.group.{N}
variables.

This stack is used to detect recursion and prevent an interpreter panic.

In the future this information could be used for including a VCL stack
trace in error output or for accessing calling function state in the
debugger.
Copy link
Owner

@ysugimoto ysugimoto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good approach, LGTM

Regex: make(map[string]*value.String),
Subroutine: sub,
}
i.Stack = append(i.Stack, sf)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tentatively we can define the max call stack frames and raise an error if exceeded, probably around 100 would be enough but up to you.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that seems reasonable. I did a test and generated a silly call chain of 200 functions in a fiddle and it didn't cause an error. Seems like the limiting factor isn't the call depth but the overall workspace memory usage which would eventually be exhausted.

@ysugimoto
Copy link
Owner

ysugimoto commented Jul 23, 2024

@richardmarshall Sorry I forgot to merge this PR and treid to resolve conflicts but some testing errors are found due to the head branch changes.

I'm so happy if you could adjust to main branch but of course I could do after merging this PR, thanks

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.

[BUG] VCL function recursion causes panic
2 participants