Skip to content

AST: Print the custom attributes attached to AttributedTypeRepr #63701

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
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
9 changes: 9 additions & 0 deletions lib/AST/TypeRepr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,15 @@ void AttributedTypeRepr::printAttrs(ASTPrinter &Printer,
Printer.printSimpleAttr("@autoclosure") << " ";
if (hasAttr(TAK_escaping))
Printer.printSimpleAttr("@escaping") << " ";

for (auto customAttr : Attrs.getCustomAttrs()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure whether it might make sense to try to specifically find the global actor attribute here and print it individually, rather than all of the custom attributes all at once. In the future when there are multiple kinds of attributes we might want to print each possible custom attribute kind in a stable order.

Printer.callPrintStructurePre(PrintStructureKind::BuiltinAttribute);
Printer << "@";
customAttr->getTypeRepr()->print(Printer, Options);
Printer.printStructurePost(PrintStructureKind::BuiltinAttribute);
Printer << " ";
}

if (hasAttr(TAK_Sendable))
Printer.printSimpleAttr("@Sendable") << " ";
if (hasAttr(TAK_noDerivative))
Expand Down
14 changes: 10 additions & 4 deletions test/ModuleInterface/concurrency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public func takesSendable(
_ block: @Sendable @escaping () async throws -> Void
) { }

@available(SwiftStdlib 5.5, *)
public func takesMainActor(
_ block: @MainActor @escaping () -> Void
) { }

// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency -I %t

#else
Expand All @@ -31,12 +36,13 @@ func callFn() async {
}
#endif

// RUN: %FileCheck %s <%t/Library.swiftinterface
// RUN: %FileCheck %s < %t/Library.swiftinterface
// CHECK: // swift-module-flags:{{.*}} -enable-experimental-concurrency
// CHECK: public func fn() async
// CHECK: public func reasyncFn(_: () async -> ()) reasync
// CHECK: public func takesSendable(_ block: @escaping @Sendable () async throws ->
// CHECK: public func takesMainActor(_ block: @escaping @{{_Concurrency.MainActor|MainActor}} () ->

// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -enable-experimental-concurrency -DLIBRARY -module-name Library -module-interface-preserve-types-as-written
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -enable-experimental-concurrency
// RUN: %FileCheck %s <%t/Library.swiftinterface
// RUN: %target-swift-emit-module-interface(%t/LibraryPreserveTypesAsWritten.swiftinterface) %s -enable-experimental-concurrency -DLIBRARY -module-name LibraryPreserveTypesAsWritten -module-interface-preserve-types-as-written
// RUN: %target-swift-typecheck-module-from-interface(%t/LibraryPreserveTypesAsWritten.swiftinterface) -enable-experimental-concurrency
// RUN: %FileCheck %s < %t/LibraryPreserveTypesAsWritten.swiftinterface