Skip to content

[Concurrency] Never skip global actor attributes in the ASTPrinter. #72037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/AST/Attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,12 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
AttributeVector modifiers;

for (auto DA : llvm::reverse(FlattenedAttrs)) {
// Always print result builder attribute.
if (!Options.PrintImplicitAttrs && DA->isImplicit())
// Don't skip implicit custom attributes. Custom attributes like global
// actor isolation have critical semantic meaning and should never be
// suppressed. Other custom attrs that can be suppressed, like macros,
// are handled below.
if (DA->getKind() != DeclAttrKind::Custom &&
!Options.PrintImplicitAttrs && DA->isImplicit())
continue;
if (!Options.PrintUserInaccessibleAttrs &&
DeclAttribute::isUserInaccessible(DA->getKind()))
Expand Down
18 changes: 18 additions & 0 deletions test/SourceKit/CursorInfo/concurrency.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@MainActor
protocol P {}

class InferMainActor: P {
func test() {}
}

// RUN: %sourcekitd-test -req=cursor -pos=4:7 %s -- %s -module-name ConcurrencyTest | %FileCheck %s --check-prefix=CHECK-CLASS
// CHECK-CLASS: source.lang.swift.decl.class
// CHECK-CLASS-NEXT: InferMainActor
// CHECK-CLASS: <Declaration>@<Type usr="s:ScM">MainActor</Type> class InferMainActor : <Type usr="s:15ConcurrencyTest1PP">P</Type></Declaration>
// 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>

// RUN: %sourcekitd-test -req=cursor -pos=5:8 %s -- %s -module-name ConcurrencyTest | %FileCheck %s --check-prefix=CHECK-FUNC
// CHECK-FUNC: source.lang.swift.decl.function.method.instance
// CHECK-FUNC-NEXT: test()
// CHECK-FUNC: <Declaration>@<Type usr="s:ScM">MainActor</Type> func test()</Declaration>
// 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>