How to determine if a lambda closes over state in a macro? #19349
Unanswered
armanbilge
asked this question in
Metaprogramming
Replies: 1 comment
-
The closure environment is not yet computed when we expand macros. This is something we compute in a later phase. It might be hard or inconsistent if we compute the closure environment before or during the expansion of a macro. Macros can change the captured sets of closures outside their scope. It might be simpler to provide a method that lists all local variables that are used but not defined in a specific tree. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to determine at compile-time if a lambda (closure) closes over state. Is there way to do this with a macro?
I know how to do this in a compiler plugin h/t Scala Native.
https://github.com/scala-native/scala-native/blob/e90d39ead9c79b72d2df1d14ede3b8a8ffac0d94/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenExpr.scala#L2677-L2682
However, the definition of
Closure
in the compiler AST differs from theQuotes
AST, specifically the lack ofenv
.https://github.com/lampepfl/dotty/blob/938d405f05e3b47eb18183a6d6330b6324505cdf/compiler/src/dotty/tools/dotc/ast/Trees.scala#L594
https://github.com/lampepfl/dotty/blob/938d405f05e3b47eb18183a6d6330b6324505cdf/library/src/scala/quoted/Quotes.scala#L1390
Beta Was this translation helpful? Give feedback.
All reactions