Skip to content

🌸[6.1] Correct newline emission in generated headers #78905

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

beccadax
Copy link
Contributor

  • Explanation: PrintAsClang was printing excessive blank lines between declarations, including blank lines that might shift around depending on when empty extensions were visited during printing. This could cause different compilation runs to emit headers that had the same declarations in the same order, but were not byte-for-byte identical, raising false alarms in build system consistency checks. This PR prints a blank line after visiting a top-level decl only when content was actually added to header, and removes excessive blank lines more generally.
  • Scope: Generated headers for Objective-C and C++
  • Issues: rdar://143533893
  • Original PRs: Correct newline emission in generated headers #78898
  • Risk: Low. This changes only the printing of newlines, and constructs that are terminated by a newline (e.g. #if) are always printed with at least one newline attached.
  • Testing: Unit tests included.
  • Reviewers: @tshortli and @nkcsgexi

Eliminates extraneous newlines between top-level Objective-C declarations in `-emit-objc-header` headers. Specifically, there should now always be exactly one—no more, no less—empty line between `@end` and whatever follows it.

Besides being more aesthetically pleasing, this eliminates ordering-dependent behavior where PrintAsClang would print an extra newline when visiting an empty extension, which meant that the order in which empty and non-empty extensions were visited during printing could result in whitespace differences in the compiler output. Printing the blank line is now conditional on whether `tell()` indicates that characters were actually written to the output.

Fixes rdar://143533893.
@beccadax beccadax added the 🍒 release cherry pick Flag: Release branch cherry picks label Jan 25, 2025
@beccadax beccadax requested a review from a team as a code owner January 25, 2025 02:14
@beccadax
Copy link
Contributor Author

@swift-ci please test

@beccadax beccadax merged commit 915b64b into swiftlang:release/6.1 Jan 27, 2025
5 checks passed
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.

2 participants