Skip to content

Commit 1e5dc82

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 b2d0f25 commit 1e5dc82

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
@@ -346,6 +346,9 @@ struct PrintOptions {
346346
/// prevent printing from doing "extra" work.
347347
bool PrintCurrentMembersOnly = false;
348348

349+
/// Whether to suppress printing of custom attributes that are expanded macros.
350+
bool SuppressExpandedMacros = true;
351+
349352
/// List of attribute kinds that should not be printed.
350353
std::vector<AnyAttrKind> ExcludeAttrList = {DAK_Transparent, DAK_Effects,
351354
DAK_FixedLayout,
@@ -653,6 +656,7 @@ struct PrintOptions {
653656
result.EnumRawValues = EnumRawValueMode::PrintObjCOnly;
654657
result.MapCrossImportOverlaysToDeclaringModule = true;
655658
result.PrintCurrentMembersOnly = false;
659+
result.SuppressExpandedMacros = true;
656660
return result;
657661
}
658662

lib/AST/Attr.cpp

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

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