-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
enhancementNew feature or requestNew feature or request
Description
There are various levels of garbage collection and/or optimization that can be achieved when calling a function. Currently if you do any recursive call, even one in tail position, like this:
function fac_help(x, acc) {
__printState__();
if(x <= 1) {
return acc;
} else {
return fac_help(x - 1, x * acc);
}
}
function fac(x) {
return fac_help(x, 1);
}
print(fac(4));The stack will bloat with all the values of x and acc, even worse, this actually bloats the stack more than if you were to not use an accumulator, as it makes a new stack slot for x and acc every time fac_help is called.
We would like to support internal tail call optimization, if a call is in tail position than we update the stack with it's new values and just call the function again with it's variables (for instance x and acc) still pointing to the same place.
Additionally, temporary values should be garbage collected upon returning from a function.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request