mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
When `__attribute__((swift_attr(“@Sendable”)))` is applied to a clang parameter Swift now attempts to make the type `Sendable` in a more comprehensive way than before: * If it is a function type, it adds `@Sendable` to it. * If it is a protocol composition type, it adds `& Sendable` to it. * If it is a class, protocol, or generic class, it inserts it into a protocol composition and adds `& Sendable`. * If it is a typealias, it *may* desugar it to a modified version of the underlying type. * In various other cases, it recurses into the children of the type. This allows Objective-C methods and functions to require that their arguments have a Sendable type without specifying a particular type they must belong to. Fixes rdar://87727549.
144 lines
7.4 KiB
Swift
144 lines
7.4 KiB
Swift
// RUN: %empty-directory(%t)
|
|
|
|
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -print-module -print-implicit-attrs -source-filename %s -module-to-print=ObjCConcurrency -function-definitions=false -enable-experimental-concurrency > %t/ObjCConcurrency.printed.txt
|
|
// RUN: %FileCheck -input-file %t/ObjCConcurrency.printed.txt %s
|
|
|
|
// REQUIRES: objc_interop
|
|
// REQUIRES: concurrency
|
|
import _Concurrency
|
|
|
|
// CHECK-LABEL: class SlowServer : NSObject, ServiceProvider {
|
|
|
|
// CHECK: @available(*, renamed: "doSomethingSlow(_:)")
|
|
// CHECK-NEXT: func doSomethingSlow(_ operation: String, completionHandler handler: @escaping @Sendable (Int) -> Void)
|
|
// CHECK-NEXT: @discardableResult
|
|
// CHECK-NEXT: func doSomethingSlow(_ operation: String) async -> Int
|
|
|
|
// CHECK: @available(*, renamed: "doSomethingDangerous(_:)")
|
|
// CHECK-NEXT: func doSomethingDangerous(_ operation: String, completionHandler handler: (@Sendable (String?, Error?) -> Void)? = nil)
|
|
// CHECK-NEXT: @discardableResult
|
|
// CHECK-NEXT: func doSomethingDangerous(_ operation: String) async throws -> String
|
|
|
|
// CHECK: @available(*, renamed: "doSomethingReckless(_:)")
|
|
// CHECK-NEXT: func doSomethingReckless(_ operation: String, completionHandler handler: ((String?, Error?) -> Void)? = nil)
|
|
// CHECK-NEXT: @discardableResult
|
|
// CHECK-NEXT: func doSomethingReckless(_ operation: String) async throws -> String
|
|
|
|
// CHECK: @available(*, renamed: "checkAvailability()")
|
|
// CHECK-NEXT: func checkAvailability(completionHandler: @escaping @Sendable (Bool) -> Void)
|
|
// CHECK-NEXT: @discardableResult
|
|
// CHECK-NEXT: func checkAvailability() async -> Bool
|
|
|
|
// CHECK: @available(*, renamed: "anotherExample()")
|
|
// CHECK-NEXT: func anotherExample(completionBlock block: @escaping @Sendable (String) -> Void)
|
|
// CHECK-NEXT: @discardableResult
|
|
// CHECK-NEXT: func anotherExample() async -> String
|
|
|
|
// CHECK: @available(*, renamed: "finalExample()")
|
|
// CHECK-NEXT: func finalExampleWithReply(to block: @escaping @Sendable (String) -> Void)
|
|
// CHECK-NEXT: @discardableResult
|
|
// CHECK-NEXT: func finalExample() async -> String
|
|
|
|
// CHECK: @available(*, renamed: "replyingOperation(_:)")
|
|
// CHECK-NEXT: func replyingOperation(_ operation: String, replyTo block: @escaping @Sendable (String) -> Void)
|
|
// CHECK-NEXT: @discardableResult
|
|
// CHECK-NEXT: func replyingOperation(_ operation: String) async -> String
|
|
|
|
// CHECK: @available(*, renamed: "findAnswer()")
|
|
// CHECK-NEXT: func findAnswer(completionHandler handler: @escaping @Sendable (String?, Error?) -> Void)
|
|
// CHECK-NEXT: @discardableResult
|
|
// CHECK-NEXT: func findAnswer() async throws -> String
|
|
|
|
// CHECK: @available(*, renamed: "findAnswerFailingly()")
|
|
// CHECK-NEXT: func findAnswerFailingly(completionHandler handler: @escaping @Sendable (String?, Error?) -> Void) throws
|
|
// CHECK-NEXT: @discardableResult
|
|
// CHECK-NEXT: func findAnswerFailingly() async throws -> String
|
|
|
|
// CHECK: @available(*, renamed: "findQAndA()")
|
|
// CHECK-NEXT: func findQAndA(completionHandler handler: @escaping @Sendable (String?, String?, Error?) -> Void)
|
|
// CHECK-NEXT: @discardableResult
|
|
// CHECK-NEXT: func findQAndA() async throws -> (String?, String)
|
|
|
|
// CHECK: @available(*, renamed: "findQuestionableAnswers()")
|
|
// CHECK-NEXT: func findQuestionableAnswers(completionHandler handler: @escaping CompletionHandler)
|
|
// CHECK-NEXT: @discardableResult
|
|
// CHECK-NEXT: func findQuestionableAnswers() async throws -> (String, String?)
|
|
|
|
// CHECK: @available(*, renamed: "findAnswerableQuestions()")
|
|
// CHECK-NEXT: func findAnswerableQuestions(completionHandler handler: @escaping @Sendable (String?, String?, Error?) -> Void)
|
|
// CHECK-NEXT: @discardableResult
|
|
// CHECK-NEXT: func findAnswerableQuestions() async throws -> (String, String?)
|
|
|
|
// CHECK: @available(*, renamed: "findUnanswerableQuestions()")
|
|
// CHECK-NEXT: func findUnanswerableQuestions(completionHandler handler: @escaping NonsendableCompletionHandler)
|
|
// CHECK-NEXT: @discardableResult
|
|
// CHECK-NEXT: func findUnanswerableQuestions() async throws -> (String, String?)
|
|
|
|
// CHECK: @available(*, renamed: "doSomethingFun(_:)")
|
|
// CHECK-NEXT: func doSomethingFun(_ operation: String, then completionHandler: @escaping @Sendable () -> Void)
|
|
// CHECK-NEXT: func doSomethingFun(_ operation: String) async
|
|
|
|
// CHECK: @available(*, renamed: "doSomethingConflicted(_:)")
|
|
// CHECK-NEXT: func doSomethingConflicted(_ operation: String, completionHandler handler: @escaping @Sendable (Int) -> Void)
|
|
// CHECK-NEXT: @discardableResult
|
|
// CHECK-NEXT: func doSomethingConflicted(_ operation: String) async -> Int
|
|
// CHECK-NEXT: @discardableResult
|
|
// CHECK-NEXT: func doSomethingConflicted(_ operation: String) -> Int
|
|
|
|
// CHECK: func dance(_ step: String) async -> String
|
|
// CHECK: func __leap(_ height: Int) async -> String
|
|
|
|
// CHECK: @available(*, renamed: "runOnMainThread()")
|
|
// CHECK-NEXT: func runOnMainThread(completionHandler completion: (@MainActor (String) -> Void)? = nil)
|
|
// CHECK-NEXT: @discardableResult
|
|
// CHECK-NEXT: func runOnMainThread() async -> String
|
|
|
|
// CHECK: @available(*, renamed: "asyncImportSame(_:)")
|
|
// CHECK-NEXT: func asyncImportSame(_ operation: String, completionHandler handler: @escaping @Sendable (Int) -> Void)
|
|
// CHECK-NEXT: @discardableResult
|
|
// CHECK-NEXT: func asyncImportSame(_ operation: String) async -> Int
|
|
// CHECK-NEXT: func asyncImportSame(_ operation: String, replyTo handler: @escaping (Int) -> Void)
|
|
// CHECK-NOT: func asyncImportSame(_ operation: String) async -> Int
|
|
|
|
// CHECK: {{^[}]$}}
|
|
|
|
// CHECK-LABEL: protocol RefrigeratorDelegate
|
|
// CHECK-NEXT: func someoneDidOpenRefrigerator(_ fridge: Any)
|
|
// CHECK-NEXT: func refrigerator(_ fridge: Any, didGetFilledWithItems items: [Any])
|
|
// CHECK-NEXT: {{^}} @objc func refrigerator(_ fridge: Any, didGetFilledWithIntegers items: UnsafeMutablePointer<Int>, count: Int)
|
|
// CHECK-NEXT: {{^}} @objc func refrigerator(_ fridge: Any, willAddItem item: Any)
|
|
// CHECK-NEXT: @discardableResult
|
|
// CHECK-NEXT: {{^}} @objc func refrigerator(_ fridge: Any, didRemoveItem item: Any) -> Bool
|
|
// CHECK-NEXT: {{^[}]$}}
|
|
|
|
// CHECK-LABEL: protocol ProtocolWithSwiftAttributes {
|
|
// CHECK-NEXT: nonisolated func independentMethod()
|
|
// CHECK-NEXT: nonisolated func nonisolatedMethod()
|
|
// CHECK-NEXT: {{^}} @MainActor @objc func mainActorMethod()
|
|
// CHECK-NEXT: {{^}} @MainActor @objc func uiActorMethod()
|
|
// CHECK-NEXT: {{^}} @objc optional func missingAtAttributeMethod()
|
|
// CHECK-NEXT: {{^[}]$}}
|
|
|
|
// CHECK: {{^}}nonisolated var MAGIC_NUMBER: Int32 { get }
|
|
|
|
// CHECK: func doSomethingConcurrently(_ block: @Sendable () -> Void)
|
|
|
|
// CHECK: @MainActor @objc protocol TripleMainActor {
|
|
|
|
// CHECK-LABEL: class NXSender :
|
|
// CHECK-NEXT: func sendAny(_ obj: Sendable)
|
|
// CHECK-NEXT: func sendOptionalAny(_ obj: Sendable?)
|
|
// CHECK-NEXT: func sendSendable(_ sendable: SendableClass & Sendable)
|
|
// CHECK-NEXT: func sendSendableSubclasses(_ sendableSubclass: NonSendableClass & Sendable)
|
|
// CHECK-NEXT: func sendProto(_ obj: LabellyProtocol & Sendable)
|
|
// CHECK-NEXT: func sendProtos(_ obj: LabellyProtocol & ObjCClub & Sendable)
|
|
// CHECK-NEXT: func sendAnyArray(_ array: [Sendable])
|
|
// CHECK-NEXT: func sendGeneric(_ generic: GenericObject<SendableClass> & Sendable)
|
|
// CHECK-NEXT: func sendPtr(_ val: UnsafeMutableRawPointer)
|
|
// CHECK-NEXT: func sendStringArray(_ obj: [String])
|
|
// CHECK-NEXT: func sendAnyTypedef(_ obj: Sendable)
|
|
// CHECK-NEXT: func sendAnyTypedefs(_ objs: [Sendable])
|
|
// CHECK-NEXT: func sendBlockTypedef(_ block: @escaping @Sendable (Any) -> Void)
|
|
// CHECK-NEXT: func sendBlockTypedefs(_ blocks: [@Sendable @convention(block) (Any) -> Void])
|
|
// CHECK-NEXT: func sendUnbound(_ array: [Sendable])
|