Skip to content

Conversation

@hborla
Copy link
Member

@hborla hborla commented Aug 7, 2024

Overriding NSObject.init() within a @MainActor-isolated type is difficult-to-impossible, especially if you need to call an initializer from an intermediate superclass that is also @MainActor-isolated. Opt-out tools like MainActor.assumeIsolated cannot be applied to things like stored property initialization and super.init(), making the issue extremely difficult to work around.

This carve-out won't admit a runtime data-race safety hole, because dynamic isolation checks will be inserted in the @objc thunks under DynamicActorIsolation, and direct calls will enforce @MainActor as usual.

Resolves: #75732, rdar://133349184

override checking for `NSObject.init()`

Overriding `NSObject.init()` within a `@MainActor`-isolated type
is difficult-to-impossible, especially if you need to call an initializer
from an intermediate superclass that is also `@MainActor`-isolated.
This won't admit a runtime data-race safety hole, because dynamic
isolation checks will be inserted in the @objc thunks under
`DynamicActorIsolation`, and direct calls will enforce `@MainActor`
as usual.
@hborla
Copy link
Member Author

hborla commented Aug 7, 2024

@swift-ci please smoke test

@hborla hborla merged commit 454dfb9 into swiftlang:main Aug 7, 2024
@hborla hborla deleted the override-nsobject-init branch August 7, 2024 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Swift 6 regression overriding initializers due to Swift Concurrency

2 participants