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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/PrintAsClang/ModuleContentsWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ class ModuleWriter {
(inserted || !it->second.second))
ClangValueTypePrinter::forwardDeclType(os, CD, printer);
it->second = {EmissionState::Defined, true};
os << '\n';
printer.print(CD);
return true;
}
Expand All @@ -507,7 +506,6 @@ class ModuleWriter {
forwardDeclareType(TD);
});

os << '\n';
printer.print(FD);
return true;
}
Expand Down Expand Up @@ -550,7 +548,6 @@ class ModuleWriter {
return false;

seenTypes[PD] = { EmissionState::Defined, true };
os << '\n';
printer.print(PD);
return true;
}
Expand All @@ -576,7 +573,6 @@ class ModuleWriter {
if (!forwardDeclareMemberTypes(ED->getAllMembers(), ED))
return false;

os << '\n';
printer.print(ED);
return true;
}
Expand Down Expand Up @@ -840,6 +836,7 @@ class ModuleWriter {
while (!declsToWrite.empty()) {
const Decl *D = declsToWrite.back();
bool success = true;
auto posBefore = os.tell();

if (auto ED = dyn_cast<EnumDecl>(D)) {
success = writeEnum(ED);
Expand Down Expand Up @@ -870,7 +867,10 @@ class ModuleWriter {

if (success) {
assert(declsToWrite.back() == D);
os << "\n";
// If we actually wrote something to the file, add a newline after it.
// (As opposed to, for instance, an extension we decided to skip.)
if (posBefore != os.tell())
os << "\n";
declsToWrite.pop_back();
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/PrintAsClang/PrintAsClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ bool swift::printAsClangHeader(raw_ostream &os, ModuleDecl *M,
clangHeaderSearchInfo, exposedModuleHeaderNames);
});
writePostImportPrologue(os, *M);
emitObjCConditional(os, [&] { os << objcModuleContents.str(); });
emitObjCConditional(os, [&] { os << "\n" << objcModuleContents.str(); });
writeObjCEpilogue(os);
emitCxxConditional(os, [&] {
// FIXME: Expose Swift with @expose by default.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ public struct Strct {
// CHECK-NEXT: } // namespace swift
// CHECK-EMPTY:
// CHECK-NEXT: namespace UseCxxTy SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("UseCxxTy") {
// CHECK-EMPTY:
// CHECK-NEXT: SWIFT_INLINE_THUNK ns::NonTrivialTemplate<ns::TrivialinNS> retNonTrivial2() noexcept SWIFT_SYMBOL({{.*}}) SWIFT_WARN_UNUSED_RESULT {
// CHECK-NEXT: alignas(alignof(ns::NonTrivialTemplate<ns::TrivialinNS>)) char storage[sizeof(ns::NonTrivialTemplate<ns::TrivialinNS>)];
// CHECK-NEXT: auto * _Nonnull storageObjectPtr = reinterpret_cast<ns::NonTrivialTemplate<ns::TrivialinNS> *>(storage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,10 @@ public final class ExposedClass {
// CHECK-NEXT: _impl::$s6Expose8exposed1yyF();
// CHECK-NEXT: }
// CHECK-EMPTY:
// CHECK-EMPTY:
// CHECK-NEXT: SWIFT_INLINE_THUNK void exposed3() noexcept SWIFT_SYMBOL("{{.*}}") {
// CHECK-NEXT: _impl::$s6Expose8exposed3yyF();
// CHECK-NEXT: }
// CHECK-EMPTY:
// CHECK-EMPTY:
// CHECK-NEXT: SWIFT_INLINE_THUNK void exposed4() noexcept SWIFT_SYMBOL("{{.*}}") {
// CHECK-NEXT: _impl::$s6Expose15exposed4RenamedyyF();
// CHECK-NEXT: }
Expand Down
1 change: 1 addition & 0 deletions test/PrintAsCxx/empty.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
// CHECK-NEXT: #if __has_feature(objc_modules)

// CHECK-LABEL: #if defined(__OBJC__)
// CHECK-EMPTY:
// CHECK-NEXT: #endif
// CHECK-NEXT: #if __has_attribute(external_source_symbol)
// CHECK-NEXT: # pragma clang attribute pop
Expand Down
30 changes: 0 additions & 30 deletions test/PrintAsObjC/Inputs/comments-expected-output.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ SWIFT_CLASS("_TtC8comments4A000")
@interface A000
@end


/// Aaa. A010. Bbb.
SWIFT_CLASS("_TtC8comments21A010_AttachToEntities")
@interface A010_AttachToEntities
Expand All @@ -17,37 +16,32 @@ SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly) NSInteger v2;)
+ (NSInteger)v2 SWIFT_WARN_UNUSED_RESULT;
@end


/// Aaa. A013.
SWIFT_PROTOCOL("_TtP8comments21A013_AttachToEntities_")
@protocol A013_AttachToEntities
@end


SWIFT_CLASS("_TtC8comments10ATXHeaders")
@interface ATXHeaders
/// <h1>LEVEL ONE</h1>
/// <h2>LEVEL TWO</h2>
- (void)f0;
@end


SWIFT_CLASS("_TtC8comments10Attributes")
@interface Attributes
/// Here is an attribute:
/// Attribute text
- (void)f0;
@end


SWIFT_CLASS("_TtC8comments13AutomaticLink")
@interface AutomaticLink
/// And now for a URL.
/// <a href="http://developer.apple.com/swift/">http://developer.apple.com/swift/</a>
- (void)f0;
@end


SWIFT_CLASS("_TtC8comments10BlockQuote")
@interface BlockQuote
/// Aaa.
Expand All @@ -62,7 +56,6 @@ SWIFT_CLASS("_TtC8comments10BlockQuote")
- (void)f0;
@end


SWIFT_CLASS("_TtC8comments5Brief")
@interface Brief
/// Aaa.
Expand All @@ -81,14 +74,12 @@ SWIFT_CLASS("_TtC8comments5Brief")
- (void)f3;
@end


SWIFT_CLASS("_TtC8comments15ClosingComments")
@interface ClosingComments
/// Some comment. */
- (void)closingComment;
@end


SWIFT_CLASS("_TtC8comments16ClosureContainer")
@interface ClosureContainer
/// Partially applies a binary operator.
Expand Down Expand Up @@ -156,7 +147,6 @@ SWIFT_CLASS("_TtC8comments16ClosureContainer")
- (void)closureParameterOutlineOutlineWithA:(NSInteger)a combine:(SWIFT_NOESCAPE NSInteger (^ _Nonnull)(NSInteger, NSInteger))combine;
@end


SWIFT_CLASS("_TtC8comments9CodeBlock")
@interface CodeBlock
/// This is how you use this code.
Expand All @@ -169,15 +159,13 @@ SWIFT_CLASS("_TtC8comments9CodeBlock")
- (void)f0;
@end


SWIFT_CLASS("_TtC8comments8Emphasis")
@interface Emphasis
/// Aaa <em>bbb</em> ccc.
/// Aaa <em>bbb</em> ccc.
- (void)f0;
@end


SWIFT_CLASS("_TtC8comments13EmptyComments")
@interface EmptyComments
///
Expand All @@ -192,7 +180,6 @@ SWIFT_CLASS("_TtC8comments13EmptyComments")
- (void)f4;
@end


SWIFT_CLASS("_TtC8comments9Footnotes")
@interface Footnotes
/// Has some footnotes.
Expand All @@ -202,7 +189,6 @@ SWIFT_CLASS("_TtC8comments9Footnotes")
- (void)f0;
@end


SWIFT_CLASS("_TtC8comments19HasThrowingFunction")
@interface HasThrowingFunction
/// Might throw something.
Expand All @@ -214,7 +200,6 @@ SWIFT_CLASS("_TtC8comments19HasThrowingFunction")
- (void)f1:(NSInteger)x;
@end


SWIFT_CLASS("_TtC8comments15HorizontalRules")
@interface HorizontalRules
/// Briefly.
Expand All @@ -223,14 +208,12 @@ SWIFT_CLASS("_TtC8comments15HorizontalRules")
- (void)f0;
@end


SWIFT_CLASS("_TtC8comments16ImplicitNameLink")
@interface ImplicitNameLink
/// <a href="https://www.apple.com/">Apple</a>
- (void)f0;
@end


SWIFT_CLASS("_TtC8comments20IndentedBlockComment")
@interface IndentedBlockComment
/// Brief.
Expand All @@ -257,21 +240,18 @@ SWIFT_CLASS("_TtC8comments20IndentedBlockComment")
- (void)f2;
@end


SWIFT_CLASS("_TtC8comments10InlineCode")
@interface InlineCode
/// Aaa <code>bbb</code> ccc.
- (void)f0;
@end


SWIFT_CLASS("_TtC8comments10InlineLink")
@interface InlineLink
/// Aaa <a href="/path/to/something">bbb</a> ccc.
- (void)f0;
@end


SWIFT_CLASS("_TtC8comments14MultiLineBrief")
@interface MultiLineBrief
/// Brief first line.
Expand All @@ -280,7 +260,6 @@ SWIFT_CLASS("_TtC8comments14MultiLineBrief")
- (void)f0;
@end


SWIFT_CLASS("_TtC8comments11OrderedList")
@interface OrderedList
/// <ol>
Expand All @@ -295,7 +274,6 @@ SWIFT_CLASS("_TtC8comments11OrderedList")
- (void)f0;
@end


/// \param x A number
///
SWIFT_CLASS("_TtC8comments15ParamAndReturns")
Expand Down Expand Up @@ -340,7 +318,6 @@ SWIFT_CLASS("_TtC8comments15ParamAndReturns")
- (void)f4;
@end


SWIFT_CLASS("_TtC8comments16ParameterOutline")
@interface ParameterOutline
/// \param x A number
Expand All @@ -352,7 +329,6 @@ SWIFT_CLASS("_TtC8comments16ParameterOutline")
- (void)f0:(NSInteger)x y:(NSInteger)y z:(NSInteger)z;
@end


SWIFT_CLASS("_TtC8comments22ParameterOutlineMiddle")
@interface ParameterOutlineMiddle
/// <ul>
Expand All @@ -372,12 +348,10 @@ SWIFT_CLASS("_TtC8comments22ParameterOutlineMiddle")
- (void)f0:(NSInteger)x y:(NSInteger)y z:(NSInteger)z;
@end


SWIFT_CLASS("_TtC8comments13ReferenceLink")
@interface ReferenceLink
@end


SWIFT_CLASS("_TtC8comments7Returns")
@interface Returns
///
Expand All @@ -386,15 +360,13 @@ SWIFT_CLASS("_TtC8comments7Returns")
- (NSInteger)f0 SWIFT_WARN_UNUSED_RESULT;
@end


SWIFT_CLASS("_TtC8comments18SeparateParameters")
@interface SeparateParameters
/// \param x A number
///
- (void)f0:(NSInteger)x y:(NSInteger)y;
@end


SWIFT_CLASS("_TtC8comments13SetextHeaders")
@interface SetextHeaders
/// <h1>LEVEL ONE</h1>
Expand All @@ -406,15 +378,13 @@ SWIFT_CLASS("_TtC8comments13SetextHeaders")
- (void)f0;
@end


SWIFT_CLASS("_TtC8comments14StrongEmphasis")
@interface StrongEmphasis
/// Aaa <em>bbb</em> ccc.
/// Aaa <em>bbb</em> ccc.
- (void)f0;
@end


SWIFT_CLASS("_TtC8comments13UnorderedList")
@interface UnorderedList
/// <ul>
Expand Down
Loading