-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[Sema] Fix #84644: Implicit initializers now inherit default actor isolation. #84815
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
base: main
Are you sure you want to change the base?
Conversation
Hello @xedin if you get a chance, could you help trigger CI? Thank you! |
Sure, I will take a look in a bit and trigger CI if everything looks good. Thank you! |
// RUN: %target-typecheck-verify-swift -enable-upcoming-feature GlobalActorIsMainActor -enable-upcoming-feature RegionBasedIsolation | ||
// expected-no-diagnostics | ||
|
||
@MainActor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the main-actor mode is on by default, this annotation is not needed.
@@ -0,0 +1,7 @@ | |||
// RUN: %target-typecheck-verify-swift -enable-upcoming-feature GlobalActorIsMainActor -enable-upcoming-feature RegionBasedIsolation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have GlobalActorIsMainActor
, it's actually spelled as -default-isolation MainActor
, also I don't think you need RegionBasedIsolation
here either.
@MainActor | ||
class Thing {} | ||
|
||
class SubThing: Thing {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to check SILGen output to make sure that initializers are isolated correctly, both initializers should be marked as MainActor in the output. I think you can move this to test/Concurrency/assume_mainactor.swift
and add the checks there (it already checks for deinit).
ImplicitConstructorKind::DefaultDistributedActor : | ||
ImplicitConstructorKind::Default; | ||
if (auto ctor = createImplicitConstructor(decl, ctorKind, ctx)) { | ||
if (auto isolation = decl->getDefaultActorIsolation()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there is a getDefaultActorIsolation
method also I don't think we want a "default" here we want to match isolation of the type, that's the isolation we need to get.
Resolves #84644
Problem:
When a class and its subclass have no explicit initializers, the compiler would emit:
This occurs under Swift 6.2 with default
@MainActor
isolation enabled. The synthesized default initializer for the superclass was not inheriting the class’s default actor isolation, causing a mismatch when a subclass implicitly overrides it.Solution:
Ensure that synthesized default initializers inherit the class’s default actor isolation:
This guarantees compatibility between synthesized initializer of superclass and any of its subclass, even if neither declares an explicit init().
Regression Test:
Added test/concurrency/default_actor_isolation_initializer.swift:
The test confirms that classes without explicit initializers now compile correctly when default actor isolation is applied.
Impact:
@MainActor
classes with implicit initializers.