diff --git a/include/swift/AST/PrintOptions.h b/include/swift/AST/PrintOptions.h index 66a9cf93b4899..b7a809b0b90c6 100644 --- a/include/swift/AST/PrintOptions.h +++ b/include/swift/AST/PrintOptions.h @@ -350,6 +350,9 @@ struct PrintOptions { /// prevent printing from doing "extra" work. bool PrintCurrentMembersOnly = false; + /// Whether to suppress printing of custom attributes that are expanded macros. + bool SuppressExpandedMacros = true; + /// List of attribute kinds that should not be printed. std::vector ExcludeAttrList = {DAK_Transparent, DAK_Effects, DAK_FixedLayout, @@ -658,6 +661,7 @@ struct PrintOptions { result.EnumRawValues = EnumRawValueMode::PrintObjCOnly; result.MapCrossImportOverlaysToDeclaringModule = true; result.PrintCurrentMembersOnly = false; + result.SuppressExpandedMacros = true; return result; } diff --git a/lib/AST/Attr.cpp b/lib/AST/Attr.cpp index b0333b3a39344..27b0045256f08 100644 --- a/lib/AST/Attr.cpp +++ b/lib/AST/Attr.cpp @@ -790,6 +790,15 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options, if (Options.excludeAttrKind(DA->getKind())) continue; + // If we're supposed to suppress expanded macros, check whether this is + // a macro. + if (Options.SuppressExpandedMacros) { + if (auto customAttr = dyn_cast(DA)) { + if (D->getResolvedMacro(const_cast(customAttr))) + continue; + } + } + // If this attribute is only allowed because this is a Clang decl, don't // print it. if (D && D->hasClangNode() diff --git a/test/Macros/macro_expand_conformances.swift b/test/Macros/macro_expand_conformances.swift index 8e9951b01dbae..f1eca1873b97b 100644 --- a/test/Macros/macro_expand_conformances.swift +++ b/test/Macros/macro_expand_conformances.swift @@ -26,6 +26,7 @@ public struct PublicEquatable { public init() { } } +// INTERFACE-NOT: @Equatable // INTERFACE: public struct PublicEquatable // INTERFACE: extension ModuleWithEquatable.PublicEquatable : Swift.Equatable diff --git a/test/ModuleInterface/Observable.swift b/test/ModuleInterface/Observable.swift new file mode 100644 index 0000000000000..77dbcfc3130e6 --- /dev/null +++ b/test/ModuleInterface/Observable.swift @@ -0,0 +1,24 @@ +// RUN: %empty-directory(%t) +// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -module-name Library -plugin-path %swift-host-lib-dir/plugins -disable-availability-checking +// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library -disable-availability-checking +// RUN: %FileCheck %s < %t/Library.swiftinterface + +// REQUIRES: swift_swift_parser + +import _Observation + +// CHECK-NOT: @Observable +// CHECK-NOT: @ObservationIgnored +// CHECK-NOT: @ObservationTracked + +@Observable +public class SomeClass { + public var field = 3 + @ObservationIgnored public var ignored = 4 +} + +public func requiresObservable(_: T) { } + +@inlinable func useObservable(sc: SomeClass) { + requiresObservable(sc) +}