-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lambdalifting: ignore AST literals for var capture (#697)
## Summary `nkNimNodeLit` are no longer scanned during var capture detection, ensuring that literals do not alter capture analysis of a routine holding typed literal AST with symbols from the outer routine. ## Details Capture detection is done in two modules `lambdalifting` and `sempass2` in the `detectCapturedVars` and `detectCapture` procedures, respectively. With this change both procedures do not traverse into `nkNimNodeLit` (treating them as more opaque literal data) for literal analysis. A regression tests has been added a test for this (thanks to Zerbina). --------- Co-authored-by: zerbina <[email protected]>
- Loading branch information
Showing
3 changed files
with
33 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
discard """ | ||
description: "Tests for passing node literals (AST) around" | ||
""" | ||
|
||
import std/macros | ||
|
||
block node_literals_are_opaque_in_static_analysis: | ||
block regression_ignore_node_literals_in_lambdalifting: | ||
proc sym() = | ||
discard | ||
|
||
proc outer() {.compileTime.} = | ||
var x = 0 | ||
|
||
proc sym() {.compileTime.} = | ||
# close over an outer local in order to make `sym` a closure procedure: | ||
x = 0 | ||
|
||
proc inner() {.compileTime.} = | ||
let x = bindSym"sym" # create a symbol choice that includes the closure | ||
# procedure | ||
|
||
# `inner` doesn't close over a local and also doesn't access a closure | ||
# procedure, so it must not be a closure procedure | ||
doAssert inner isnot "closure" | ||
|
||
static: | ||
# call the procedure to make sure it passes the lambda-lifting pass | ||
outer() |