Skip to content

[5.9][Macros] Automatically format expanded macros #65491

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

bnbarham
Copy link
Contributor

  • Explanation: Macro formatting patch. Primarily this is aimed to reduce the previous burden on expansions having to add required trivia and to be at least somewhat formatted. We now basic format all macro expansions, which both adds required trivia and adds some basic newlines and indentation. Macros can opt-out by implementing formatMode and setting to .disabled. This also fixes up the expansion buffers to not include the newlines that eg. an inline macro refactoring would expect.
  • Scope: All macro expansions
  • Risk: Low; we may end up with some oddly-formatted macros, but implementors can always disable it if they want
  • Testing: Added tests for macro formatting (on and off)
  • Original PR: [Macros] Automatically format expanded macros #65450

Rather than requiring macro implementations to add required whitespace
and indentation, basic format all macro expansions. Right now this uses
the default four space indentation, we can consider having that inferred
later. Macros can opt-out of automatic formatting by implementing
`formatMode` and setting it to `.disabled`.

Also moves the extra newlines before/after expansions to a new "Inline
Macro" refactoring.

Resolves rdar://107731047.

(cherry picked from commit fe2104c)
@bnbarham bnbarham requested a review from a team as a code owner April 28, 2023 04:34
@bnbarham
Copy link
Contributor Author

swiftlang/swift-syntax#1596

@swift-ci please test

@bnbarham bnbarham merged commit 19ef366 into swiftlang:release/5.9 Apr 28, 2023
@bnbarham bnbarham deleted the cherry-format-macro-expansions branch April 28, 2023 20:49
@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 swift 5.9
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants