Skip to content

[Macros] Resolve macro names using unqualified lookup that ignores expansions #64855

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

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Apr 3, 2023

The macro name resolution in the source lookup cache was only looking at macros in the current module, meaning that any names introduced by peer or declaration macros declared in one module but used in another would not be found by name lookup.

Switch the source lookup cache over to using the same forEachPotentialResolvedMacro API that is used by lookup within types, so we have consistent name-lookup-level macro resolution in both places.

... except that would be horribly cyclic, of course, so introduce name lookup flags to ignore top-level declarations introduced by macro expansions. This is semantically correct because macro expansions are not allowed to introduce new macros anyway, because that would have been a terrible idea.

Fixes rdar://107321469. Peer and declaration macros at module scope should work a whole lot better now.


Cherry pick of #64854.

…pansions

The macro name resolution in the source lookup cache was only looking at
macros in the current module, meaning that any names introduced by peer
or declaration macros declared in one module but used in another would
not be found by name lookup.

Switch the source lookup cache over to using the same
`forEachPotentialResolvedMacro` API that is used by lookup within
types, so we have consistent name-lookup-level macro resolution in both
places.

... except that would be horribly cyclic, of course, so introduce name
lookup flags to ignore top-level declarations introduced by macro
expansions. This is semantically correct because macro expansions are
not allowed to introduce new macros anyway, because that would have
been a terrible idea.

Fixes rdar://107321469. Peer and declaration macros at module scope
should work a whole lot better now.
@DougGregor DougGregor requested a review from a team as a code owner April 3, 2023 06:23
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor DougGregor merged commit a1a1b05 into swiftlang:release/5.9 Apr 3, 2023
@DougGregor DougGregor deleted the top-level-macro-lookup-5.9 branch April 3, 2023 17:11
@AnthonyLatsis AnthonyLatsis added the 🍒 release cherry pick Flag: Release branch cherry picks label May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants