odenix 90df0662af Overhaul implementation of for-generators (#844)
Motivation:
* fix known bugs and limitations of for-generators
* improve code health by removing complex workarounds

Changes:
* simplify AstBuilder code related to for-generators
  * track for-generators via `SymbolTable.enterForGenerator()`
  * add `RestoreForBindingsNode` during initial AST construction
    instead of calling `MemberNode.replaceBody()` later on
  * simplify some unnecessarily complex code
* remove workarounds and band-aids such as:
  * `isInIterable`
  * `executeAndSetEagerly`
  * adding dummy slots in `AmendFunctionNode`
* overhaul implementation of for-generators
  * store keys and values of for-generator iterations in regular instead of auxiliary frame slots
    * set them via `TypeNode.executeAndSet()`
    * `ResolveVariableNode` no longer needs to search auxiliary slots
    * `Read(Enclosing)AuxiliarySlot` is no longer needed
  * at the start of each for-generator iteration, create a new `VirtualFrame`
    that is a copy of the current frame (arguments + slots)
    and stores the iteration key and value in additional slots.
  * execute for-generator iteration with the newly created frame
    * `childNode.execute(newFrame)`
    * Pkl objects created during the iteration will materialize this frame
  * store newly created frames in `owner.extraStorage`
    if their for-generator slots may be accessed when a generated member is executed
    * resolving variable names to for-generator variables at parse time would make this analysis more precise
  * when a generated member is executed,
	  * retrieve the corresponding frame stored in `owner.extraStorage`
	  * copy the retrieved frame's for-generator slots into slots of the current frame

Result:
* for-generators are implemented in a correct, reasonably simple, and reasonably efficient way
  * complexity is fully contained within package `generator` and `AstBuilder`
* for-generator keys and values can be accessed from all nested scopes:
  * key and value expressions of generated members
  * condition expressions of nested when-generators
  * iterable expressions of nested for-generators
* for-generator keys and values can be accessed from within objects created by the expressions listed above
* sibling for-generators can use the same key/value variable names
* parent/child for-generators can use the same key/value variable names
* fixes https://github.com/apple/pkl/issues/741
2025-01-28 14:06:42 -08:00
2024-02-01 14:00:22 -08:00
2025-01-23 14:41:59 -08:00
2025-01-23 14:41:59 -08:00
2025-01-23 14:41:59 -08:00
2025-01-23 14:41:59 -08:00
2025-01-23 14:41:59 -08:00
2025-01-23 14:41:59 -08:00
2025-01-23 14:41:59 -08:00
2024-12-23 12:49:56 -08:00
2024-02-01 14:00:22 -08:00
2024-02-01 14:00:22 -08:00
2024-02-01 14:00:22 -08:00
2024-11-05 10:34:31 -08:00
2025-01-15 05:38:51 -08:00
2024-10-14 22:53:26 -07:00
2024-11-05 10:34:31 -08:00
2024-02-01 14:00:22 -08:00
2024-02-01 14:00:22 -08:00
2025-01-07 10:15:07 +00:00
2024-02-01 14:00:22 -08:00
2024-02-01 14:00:22 -08:00

= image:.idea/icon.svg[Pkl,30] Pkl 

:uri-homepage: https://pkl-lang.org
:uri-docs: {uri-homepage}/main/current
:uri-docs-introduction: {uri-docs}/introduction
:uri-docs-release-notes: {uri-docs}/release-notes
:uri-docs-language: {uri-docs}/language
:uri-docs-tools: {uri-docs}/tools
:uri-github-issue: https://github.com/apple/pkl/issues
:uri-github-discussions: https://github.com/apple/pkl/discussions
:uri-pkl-examples: https://pkl-lang.org/main/current/examples.html
:uri-installation: https://pkl-lang.org/main/current/pkl-cli/index.html#installation
:uri-lang-reference: https://pkl-lang.org/main/current/language-reference/index.html
:uri-ci-artifacts: https://s01.oss.sonatype.org/content/groups/public/org/pkl-lang/
:uri-ci-pipeline: https://app.circleci.com/pipelines/github/apple/pkl

A configuration as code language with rich validation and tooling.

== Quick Links

* {uri-installation}[Installation]
* {uri-lang-reference}[Language Reference]

== Documentation

* {uri-homepage}[Home Page]
** {uri-docs-introduction}[Introduction]
** {uri-docs-language}[Language]
** {uri-docs-tools}[Tools]
** {uri-pkl-examples}[Examples]
** {uri-docs-release-notes}[Release Notes]

== Community

We'd love to hear from you!

* Create an {uri-github-issue}[issue]
* Ask a question on {uri-github-discussions}[GitHub Discussions]

== Development image:https://circleci.com/gh/apple/pkl.svg?style=svg["Apple", link="https://app.circleci.com/pipelines/github/apple/pkl"]
* link:CONTRIBUTING.adoc[] for tips on pull requests and filing issues
* link:DEVELOPMENT.adoc[] for build instructions
* {uri-ci-artifacts}[Sonatype Repository] for the artifacts/binaries built by our {uri-ci-pipeline}[CI pipelines] (and those of our other tools and packages repositories).

== Pkl GitHub Repositories

[%autowidth]
|===
|Name |Description

|`apple/pkl`
|A configuration as code language with rich validation and tooling.

|https://github.com/apple/pkl-evolution[`apple/pkl-evolution`]
|Suggested Pkl Improvements, Changes, or Enhancements (SPICEs)

|https://github.com/apple/pkl-go[`apple/pkl-go`]
|Pkl bindings for the Go programming language

|https://github.com/apple/pkl-go-examples[`apple/pkl-go-examples`]
|Examples for using Pkl within Go applications

|https://github.com/apple/pkl-intellij[`apple/pkl-intellij`]
|JetBrains editor plugins providing Pkl language support

|https://github.com/apple/pkl-jvm-examples[`apple/pkl-jvm-examples`]
|Examples for using Pkl within JVM applications

|https://github.com/apple/pkl-k8s[`apple/pkl-k8s`]
|Templates for using Pkl with Kubernetes

|https://github.com/apple/pkl-k8s-examples[`apple/pkl-k8s-examples`]
|Examples for using Pkl with Kubernetes

|https://github.com/apple/pkl-lang.org[`apple/pkl-lang.org`]
|The pkl-lang.org website

|https://github.com/apple/pkl-lsp[`apple/pkl-lsp`]
| Language server for Pkl, implementing the server-side of the Language Server Protocol

|https://github.com/apple/pkl-neovim[`apple/pkl-neovim`]
|Pkl language support for Neovim

|https://github.com/apple/pkl-package-docs[`apple/pkl-package-docs`]
|Documentation for Pkl packages

|https://github.com/apple/pkl-pantry[`apple/pkl-pantry`]
|Shared Pkl packages

|https://github.com/apple/pkl-project-commons[`apple/pkl-project-commons`]
|Utility libraries for Pkl

|https://github.com/apple/pkl-spring[`apple/pkl-spring`]
|Spring Boot extension for configuring Boot apps with Pkl

|https://github.com/apple/pkl-swift[`apple/pkl-swift`]
|Pkl bindings for the Swift programming language

|https://github.com/apple/pkl-swift-examples[`apple/pkl-swift-examples`]
|Examples for using Pkl within Swift applications

|https://github.com/apple/pkl-vscode[`apple/pkl-vscode`]
|Pkl language support for VS Code

|https://github.com/apple/pkl.tmbundle[`apple/pkl.tmbundle`]
|TextMate bundle for Pkl

|https://github.com/apple/rules_pkl[`apple/rules_pkl`]
| Bazel build rules for Pkl

|https://github.com/apple/tree-sitter-pkl[`apple/tree-sitter-pkl`]
|Tree-sitter parser for Pkl
|===
Description
No description provided
Readme 29 MiB
Latest
2025-12-15 20:18:34 +01:00
Languages
Java 63.9%
Kotlin 30.3%
Pkl 5%
JavaScript 0.6%
CSS 0.2%