Skip to content

Commit 49bbddc

Browse files
committed
[Module printing] Don't print attached macros in generated interfaces
Macros are expanded as part of interface generation, so they shouldn't also be printed into the Swift interface. Fixes rdar://109378191.
1 parent a63c8d5 commit 49bbddc

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

include/swift/AST/PrintOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ struct PrintOptions {
350350
/// prevent printing from doing "extra" work.
351351
bool PrintCurrentMembersOnly = false;
352352

353+
/// Whether to suppress printing of custom attributes that are expanded macros.
354+
bool SuppressExpandedMacros = true;
355+
353356
/// List of attribute kinds that should not be printed.
354357
std::vector<AnyAttrKind> ExcludeAttrList = {DAK_Transparent, DAK_Effects,
355358
DAK_FixedLayout,
@@ -658,6 +661,7 @@ struct PrintOptions {
658661
result.EnumRawValues = EnumRawValueMode::PrintObjCOnly;
659662
result.MapCrossImportOverlaysToDeclaringModule = true;
660663
result.PrintCurrentMembersOnly = false;
664+
result.SuppressExpandedMacros = true;
661665
return result;
662666
}
663667

lib/AST/Attr.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,15 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
790790
if (Options.excludeAttrKind(DA->getKind()))
791791
continue;
792792

793+
// If we're supposed to suppress expanded macros, check whether this is
794+
// a macro.
795+
if (Options.SuppressExpandedMacros) {
796+
if (auto customAttr = dyn_cast<CustomAttr>(DA)) {
797+
if (D->getResolvedMacro(const_cast<CustomAttr *>(customAttr)))
798+
continue;
799+
}
800+
}
801+
793802
// If this attribute is only allowed because this is a Clang decl, don't
794803
// print it.
795804
if (D && D->hasClangNode()

test/Macros/macro_expand_conformances.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public struct PublicEquatable {
2626
public init() { }
2727
}
2828

29+
// INTERFACE-NOT: @Equatable
2930
// INTERFACE: public struct PublicEquatable
3031
// INTERFACE: extension ModuleWithEquatable.PublicEquatable : Swift.Equatable
3132

0 commit comments

Comments
 (0)