Skip to content

Commit ba76c3c

Browse files
committed
[Concurrency] Never skip global actor attributes in the ASTPrinter.
Custom attributes like global actors carry crucial semantic information and should never be suppressed in the ASTPrinter. In particular, `printQuickHelpDeclaration()` sets `PrintImplicitAttrs` to false, but it's important for quick help / cursor info to include global actors.
1 parent 466a021 commit ba76c3c

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/AST/Attr.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -953,8 +953,12 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
953953
AttributeVector modifiers;
954954

955955
for (auto DA : llvm::reverse(FlattenedAttrs)) {
956-
// Always print result builder attribute.
957-
if (!Options.PrintImplicitAttrs && DA->isImplicit())
956+
// Don't skip implicit custom attributes. Custom attributes like global
957+
// actor isolation have critical semantic meaning and should never be
958+
// suppressed. Other custom attrs that can be suppressed, like macros,
959+
// are handled below.
960+
if (DA->getKind() != DeclAttrKind::Custom &&
961+
!Options.PrintImplicitAttrs && DA->isImplicit())
958962
continue;
959963
if (!Options.PrintUserInaccessibleAttrs &&
960964
DeclAttribute::isUserInaccessible(DA->getKind()))
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@MainActor
2+
protocol P {}
3+
4+
class InferMainActor: P {
5+
func test() {}
6+
}
7+
8+
// RUN: %sourcekitd-test -req=cursor -pos=4:7 %s -- %s -module-name ConcurrencyTest | %FileCheck %s --check-prefix=CHECK-CLASS
9+
// CHECK-CLASS: source.lang.swift.decl.class
10+
// CHECK-CLASS-NEXT: InferMainActor
11+
// CHECK-CLASS: <Declaration>@<Type usr="s:ScM">MainActor</Type> class InferMainActor : <Type usr="s:15ConcurrencyTest1PP">P</Type></Declaration>
12+
// CHECK-CLASS: <decl.class><syntaxtype.attribute.builtin><syntaxtype.attribute.name>@<ref.class usr="s:ScM">MainActor</ref.class></syntaxtype.attribute.name></syntaxtype.attribute.builtin> <syntaxtype.keyword>class</syntaxtype.keyword> <decl.name>InferMainActor</decl.name> : <ref.protocol usr="s:15ConcurrencyTest1PP">P</ref.protocol></decl.class>
13+
14+
// RUN: %sourcekitd-test -req=cursor -pos=5:8 %s -- %s -module-name ConcurrencyTest | %FileCheck %s --check-prefix=CHECK-FUNC
15+
// CHECK-FUNC: source.lang.swift.decl.function.method.instance
16+
// CHECK-FUNC-NEXT: test()
17+
// CHECK-FUNC: <Declaration>@<Type usr="s:ScM">MainActor</Type> func test()</Declaration>
18+
// CHECK-FUNC: <decl.function.method.instance><syntaxtype.attribute.builtin><syntaxtype.attribute.name>@<ref.class usr="s:ScM">MainActor</ref.class></syntaxtype.attribute.name></syntaxtype.attribute.builtin> <syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>test</decl.name>()</decl.function.method.instance>

0 commit comments

Comments
 (0)