Fix resolution of for-generator vars within iteratee #747
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is one attempt to fix #741. The approach here is to wrap the iterable in a new root node; that is:
We then store any existing for-generator vars as auxiliary slots inside this root node.
I'm not entirely happy with this approach; one quirk here is that we are creating a deeper stack frame, but cloning the parent stack frame. We need to do this so that we can resolve variables that might be on the outer frame.
Going deeper: the reason we need to copy outer frame slot values is because our lexical scope is all based off of
VmObjectLike
; we don't have a mechanism for resolving a variable on the outer frame if there is no VmObject to attach a frame to.However, we don't have this pattern anywhere in the codebase. It's a one-off and feels quite hacky.
Also, creating a new root node adds more interpreter overhead. But the cost there seems palatable; it's unclear to me how much this actually hurts our real world performance.
I can think of two alternatives to this approach: