Skip to content

Commit 0763971

Browse files
authored
Merge pull request #66150 from DougGregor/interfaces-without-macros-5.9
2 parents 802a24b + b8c8d8d commit 0763971

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-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

test/ModuleInterface/Observable.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -module-name Library -plugin-path %swift-host-lib-dir/plugins -disable-availability-checking
3+
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library -disable-availability-checking
4+
// RUN: %FileCheck %s < %t/Library.swiftinterface
5+
6+
// REQUIRES: swift_swift_parser
7+
8+
import _Observation
9+
10+
// CHECK-NOT: @Observable
11+
// CHECK-NOT: @ObservationIgnored
12+
// CHECK-NOT: @ObservationTracked
13+
14+
@Observable
15+
public class SomeClass {
16+
public var field = 3
17+
@ObservationIgnored public var ignored = 4
18+
}
19+
20+
public func requiresObservable<T: Observable>(_: T) { }
21+
22+
@inlinable func useObservable(sc: SomeClass) {
23+
requiresObservable(sc)
24+
}

0 commit comments

Comments
 (0)