You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now that environment traversal has been refactored, we no longer need to hold environments in a Vec. Initially we used this to traverse through and get bindings.
function f1() {
return a
}
function f2() {
let a = 1
return f1()
}
f2()
f1() getting called in f2() will have a new environment with the global scope as its parent - it would not have access to a declared inside of f1, for example. The environment stack of f1 would be: Global -> f1. This means that we can't assume that a new environment will have the previous environment as its parent.
The issue in #989 was that resolving bindings was not being done correctly: it was done by traversing through the stack instead of traversing through parent environments. This created a situation where the environment stack for f1 would look like this: Global -> f2 -> f1, creating the problem of variables in f2 being visible in f1.
If we get rid of the stack and use parent environments to return to the previous environment, there will be a different problem: we won't be able to come back to f2's environment, since the parent stack of f1 would be Global.
I think it's still possible to get rid of the environment stack by manually managing environments in parts of the code that currently push and pop environments (implicitly using function calls in Rust as the stack, I suppose), but we can't replace it with traversing parent environments.
Activity
0x7D2B commentedon Apr 9, 2021
I'm pretty sure we can't do this because it would bring back #989.
Consider the code from #989:
f1()getting called inf2()will have a new environment with the global scope as its parent - it would not have access toadeclared inside off1, for example. The environment stack off1would be:Global->f1. This means that we can't assume that a new environment will have the previous environment as its parent.The issue in #989 was that resolving bindings was not being done correctly: it was done by traversing through the stack instead of traversing through parent environments. This created a situation where the environment stack for
f1would look like this:Global->f2->f1, creating the problem of variables inf2being visible inf1.If we get rid of the stack and use parent environments to return to the previous environment, there will be a different problem: we won't be able to come back to
f2's environment, since the parent stack off1would beGlobal.I think it's still possible to get rid of the environment stack by manually managing environments in parts of the code that currently push and pop environments (implicitly using function calls in Rust as the stack, I suppose), but we can't replace it with traversing parent environments.