forked from google/starlark-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
starlark: capture free variables by reference (google#172)
This change causes closures for nested functions to capture their enclosing functions' variables by reference. Even though an inner function cannot update outer variables, it must observe updates to them made by the outer function. A special case of this is a nested recursive function f: def outer(): def f(): ...f()... The def f statement constructs a closure which captures f, and then binds the closure value to f. If the closure captures by value (as before this change), the def statement will fail because f is undefined (see issue google#170). Now, the closure captures a reference to f, so it is safe to execute before f has been assigned. This is implemented as follows. During resolving, captured local variables such as f are marked as as "cells". The compiler assumes and guarantees that such locals are values of a special internal type called 'cell', and it emits explicit instructions to load from and store into the cell. At runtime, cells are created on entry to the function; parameters may be "spilled" into cells as needed. Each cell variable gets its own allocation to avoid spurious liveness. A function's tuple of free variables contains only cells. Fixes google#170
- Loading branch information
Showing
9 changed files
with
171 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.