mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
[PR #747] [CLOSED] Fix resolution of for-generator vars within iteratee #707
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/apple/pkl/pull/747
Author: @bioball
Created: 10/29/2024
Status: ❌ Closed
Base:
main← Head:for-generator-scope-fix📝 Commits (1)
252249fFix resolution of for-generator vars within iteratee📊 Changes
11 files changed (+378 additions, -15 deletions)
View changed files
📝
pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java(+22 -2)📝
pkl-core/src/main/java/org/pkl/core/ast/expression/generator/GeneratorForNode.java(+4 -6)➕
pkl-core/src/main/java/org/pkl/core/ast/expression/generator/GeneratorIterableNode.java(+80 -0)➕
pkl-core/src/main/java/org/pkl/core/ast/expression/generator/GeneratorIteratingNode.java(+63 -0)📝
pkl-core/src/main/java/org/pkl/core/ast/expression/generator/GeneratorMemberNode.java(+4 -0)📝
pkl-core/src/main/java/org/pkl/core/ast/expression/generator/GeneratorSpreadNode.java(+4 -7)➕
pkl-core/src/main/java/org/pkl/core/ast/frame/WriteNthFrameSlotNode.java(+65 -0)➕
pkl-core/src/test/files/LanguageSnippetTests/input/generators/forGeneratorNestedReference.pkl(+31 -0)➕
pkl-core/src/test/files/LanguageSnippetTests/input/generators/spreadSyntaxInForGenerator.pkl(+57 -0)➕
pkl-core/src/test/files/LanguageSnippetTests/output/generators/forGeneratorNestedReference.pcf(+20 -0)➕
pkl-core/src/test/files/LanguageSnippetTests/output/generators/spreadSyntaxInForGenerator.pcf(+28 -0)📄 Description
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:
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.