Skip to content

[5.9] Automatically format expanded macros #1596

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

@bnbarham bnbarham commented Apr 28, 2023

  • 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.
  • 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: Swift-repo tests for formatted macros
  • Original PR: Automatically format expanded macros #1591

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`.

Add new `trimmed(matching:)` and `trimmedDescription(matching:)` methods
to allow eg. only trimming whitespace rather than all trivia. Use this
when trimming macro expansions so that any added comments are kept.

Resolves rdar://107731047.

(cherry picked from commit e40c82c)
@bnbarham
Copy link
Contributor Author

@swift-ci please test

@bnbarham bnbarham merged commit d311e73 into swiftlang:release/5.9 Apr 28, 2023
@bnbarham bnbarham deleted the cherry-format-macro-expansions branch April 28, 2023 20:48
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.

3 participants