Skip to content

Commit 7d0510a

Browse files
authored
Merge pull request #66131 from DougGregor/interfaces-without-macros
2 parents 9698128 + 548ff3a commit 7d0510a

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
@@ -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

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)