Skip to content

[5.9][Macros] Requestify MacroExpansionExpr expansion #65480

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

rintaro
Copy link
Member

@rintaro rintaro commented Apr 27, 2023

Cherry-pick #65453, #65519 (and depending #65263) into release/5.9

Explanation: Previously, macro expression expansion results used to be stored in the AST only if the expanded text succeeds to typecheck. Because of that, "Expand Macro" refactoring did't work when the macro expands to an erroneous source code. By requestifying the expansion and make it return the expanded buffer ID (as the same as MacroExpansionDecl), expanded buffer ID is cached in the request evaluator, so that the refactoring works regardless.
Also this includes a workaround not to expand macros inside macro arguments position that can cause extraneous, potentially harmful macro expansions and diagnostics
Scope: Macro expression expansion
Risk: Low
Testing: Added a refactoring test case
Issue: rdar://108530760, rdar://108622244
Reviewer: Alex Hoppen (@ahoppen), Doug Gregor (@DougGregor), Ben Barham (@bnbarham)

rintaro added 3 commits April 27, 2023 15:40
NullterminatedStringRef is meant to be safe for reading 'data()' as a
valid C-string.

rdar://108215490
(cherry picked from commit 43eabf1)
Saves one memory copy. No need to create a temporary
NullTerminatedStringRef.

(cherry picked from commit a0eb32e)
The request returns the expanded buffer ID even if it failed to
typecheck the expanded buffer.
This makes refactoring 'Expand Macro' work regardless of the
typechecking results.

rdar://108530760
(cherry picked from commit 35db928)
@rintaro rintaro requested a review from a team as a code owner April 27, 2023 22:43
@rintaro
Copy link
Member Author

rintaro commented Apr 27, 2023

@swift-ci Please test

rintaro added 2 commits May 1, 2023 09:41
Macro expressions nested in macro arguments should be type checked, but
should not be expanded.

rdar://108622244
(cherry picked from commit 5c2faf3)
@rintaro
Copy link
Member Author

rintaro commented May 1, 2023

@swift-ci Please test

@rintaro
Copy link
Member Author

rintaro commented May 1, 2023

@swift-ci Please test macOS

@rintaro rintaro merged commit ad7b1d9 into swiftlang:release/5.9 May 2, 2023
@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