Skip to content

[Macros] Improve breaking of cyclic references for member-attribute macros #65410

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

Merged
merged 3 commits into from
Apr 25, 2023

Conversation

DougGregor
Copy link
Member

Implement a more effective cyclic-reference breaking strategy for macros in ill-formed code, reinstating the test case that was recently disabled as part of #65393. There are two pieces to this strategy:

  • Rework the key of ResolveMacroRequest so we don't have false collisions for member-attribute macros
  • Make sure that expanding member-attribute macros does nothing for function parameters

While here, improve the diagnostics we get when macro resolution or expansion introduces a cyclic reference, because we're likely to see more of these.

We are likely to debugging more cyclic references involving macros in
the future, so improve the diagnostics to specify what operation we're
performing (e.g., macro resolution vs. expansion of a particular kind
of macro) and the macro name, when possible, so failures are easier to
diagnose. No functionality change for well-formed code.
…acro is attached

The macro-resolution request for an attached macro was expressed in
terms of the custom attribute and the declaration context enclosing the
attribute. While the declaration context is the correct one for
resolving the types and arguments of the custom attribute, the
declaration provides a better anchor for cases where the same
attribute applies to multiple declarations, e.g., with
member-attribute macros, leading to false cyclic references.
…mber attributes

The last step in breaking the cycle through visible declaration lookup,
e.g., with invalid code. Prior to this, we would get a false cyclic
reference through the parameters of a function when they try to find
property wrappers on the parameters.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor DougGregor merged commit 067e4ec into swiftlang:main Apr 25, 2023
@DougGregor DougGregor deleted the macro-cycle-break-part-deux branch April 25, 2023 13:37
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.

1 participant