mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
When targeting a platform that predates the introduction of isolated deinit, make a narrow exception that allows main-actor-isolated deinit to work through a special, inlineable entrypoint that is back-deployed. This implementation 1. Calls into the real implementation when available, otherwise 2. Checks if we're on the main thread, destroying immediately when we are, otherwise 3. Creates a new task on the main actor to handle destruction. This implementation is less efficient than the implementation in the runtime, but allows us to back-deploy this functionality as far back as concurrency goes. Fixes rdar://151029118.
37 lines
700 B
Swift
37 lines
700 B
Swift
// RUN: %target-typecheck-verify-swift -swift-version 5 %s -strict-concurrency=complete -target %target-swift-5.1-abi-triple
|
|
|
|
// REQUIRES: concurrency
|
|
// REQUIRES: OS=macosx
|
|
|
|
class NotSendable {}
|
|
|
|
@MainActor class C {
|
|
var x: Int = 0
|
|
|
|
nonisolated deinit {
|
|
print(x)
|
|
}
|
|
}
|
|
|
|
@globalActor
|
|
actor SomeGlobalActor {
|
|
static let shared = SomeGlobalActor()
|
|
}
|
|
|
|
// expected-note@+1{{add '@available' attribute to enclosing class}}
|
|
@SomeGlobalActor class C2 {
|
|
var x: Int = 0
|
|
|
|
isolated deinit { // expected-error{{isolated deinit is only available in macOS 15.4.0 or newer}}
|
|
print(x)
|
|
}
|
|
}
|
|
|
|
@MainActor class C3 {
|
|
var x: Int = 0
|
|
|
|
isolated deinit { // okay, this back-deploys
|
|
print(x)
|
|
}
|
|
}
|