Skip to content

[5.9] [Walker] Don't visit VarDecls encountered in freestanding macro expansions #66224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

DougGregor
Copy link
Member

  • Explanation: VarDecls are always walked via their pattern bindings, so we end up
    with double-visitation if we also visit them in freestanding macro expansions, causing a compiler assertion.
  • Scope: Narrow; only code within macro expansions is affected.
  • Risk: Low due to narrow scope.
  • Issue: rdar://109376102.
  • Original pull request: [Walker] Don't visit VarDecls encountered in freestanding macro expansions #66202

Setting closure and local discriminators depends on an in-order walk
of the AST. For macros, it was walking into both macro expansions and
arguments. However, this doesn't work well with lazy macro expansions,
and could result in some closures/local variables not getting
discriminators set at all.

Make the assignment of discriminators only walk macro arguments, and
then lazily assign discriminators for anything within a macro
expansion or in ill-formed code. This replaces the single global "next
autoclosure discriminator" scheme with a per-DeclContext scheme, that
is more reliable/robust, although it does mean that discriminators
of closures and locals within macro expansions are dependent on
ordering. That shouldn't matter, because these are local values.

Fixes rdar://108682196.
…sions

VarDecls are always walked via their pattern bindings, so we end up
with double-visitation if we also visit them here.

Fixes rdar://109376102.

(cherry picked from commit 638c2cd)
@DougGregor DougGregor requested a review from a team as a code owner May 30, 2023 21:06
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor DougGregor merged commit da77b15 into swiftlang:release/5.9 May 31, 2023
@DougGregor DougGregor deleted the visit-var-decls-in-freestanding-expansions-once-5.9 branch May 31, 2023 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants