Skip to content

Fix trivia transfer bugs for freestanding expression macros #2048

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 1 commit into from
Aug 15, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Aug 9, 2023

There were two bugs in the way we transferred trivia from the original macro expansion expression to the expanded expression.

  1. We were attaching the stripped leading trivia to the end of the node
  2. We weren’t resetting the lineContainedComment and lineContainedNonWhitespaceNonComment variables when seeing a newline in a comment-only line

rdar://113639097

@ahoppen
Copy link
Member Author

ahoppen commented Aug 11, 2023

@swift-ci Please test

@ahoppen ahoppen requested a review from bnbarham August 11, 2023 16:36
@ahoppen ahoppen force-pushed the ahoppen/incrorrect-trivia-wrapping branch from 9f0e185 to 486b5c2 Compare August 11, 2023 19:57
@ahoppen
Copy link
Member Author

ahoppen commented Aug 11, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Aug 11, 2023

@bnbarham I removed the entire comment-handling logic altogether because it wasn’t really working as I intended and it didn’t match what the “Inline Macro” refactoring does. Could you take another look at this PR?

@ahoppen
Copy link
Member Author

ahoppen commented Aug 11, 2023

@swift-ci Please test Windows

@bnbarham
Copy link
Contributor

So IIUC we leave the trivia and pass it through now?

/// freestanding macro that separate it from the previous declarations.
/// We need to do this because we are replacing the entire macro expansion
/// declaration / expression with the expanded source but the “Inline Macro”
/// refactoring only replaces the node’s content, and doesn’t touch its trivia.
func wrappingInNonCommentTrivia(from node: some SyntaxProtocol) -> String {
Copy link
Contributor

@bnbarham bnbarham Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still called wrappingInNonCommentTrivia. I don't think it's necessary to mention inline macro here. There's no reason we couldn't change it as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching these things, as always

@ahoppen ahoppen force-pushed the ahoppen/incrorrect-trivia-wrapping branch from 486b5c2 to 6b6b157 Compare August 11, 2023 20:44
There were two bugs in the way we transferred trivia from the original macro expansion expression to the expanded expression.

1. We were attaching the stripped leading trivia to the end of the node
2. We weren’t resetting the `lineContainedComment` and `lineContainedNonWhitespaceNonComment` variables when seeing a newline in a comment-only line

(1) is easy to fix.
For (2), I just remove the entire comment-handling logic because it didn’t match what “Inline Macro” was doing anyway.

rdar://113639097
@ahoppen ahoppen force-pushed the ahoppen/incrorrect-trivia-wrapping branch from 6b6b157 to 5824002 Compare August 14, 2023 19:10
@ahoppen
Copy link
Member Author

ahoppen commented Aug 14, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Aug 14, 2023

@swift-ci Please test Windows

1 similar comment
@kimdv
Copy link
Contributor

kimdv commented Aug 15, 2023

@swift-ci Please test Windows

@ahoppen ahoppen merged commit 5d2875d into swiftlang:main Aug 15, 2023
@ahoppen ahoppen deleted the ahoppen/incrorrect-trivia-wrapping branch August 15, 2023 16:07
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