Skip to content

[Concurrency] Don't error on isolated property wrapper initializers inside MainActor-isolated structs. #73168

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 1 commit into from
Apr 22, 2024
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
2 changes: 1 addition & 1 deletion include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE(MemberImportVisibility, true
EXPERIMENTAL_FEATURE(IsolatedAny2, true)

// Enable usability improvements for global-actor-isolated types.
EXPERIMENTAL_FEATURE(GlobalActorIsolatedTypesUsability, false)
EXPERIMENTAL_FEATURE(GlobalActorIsolatedTypesUsability, true)

// Enable @implementation on extensions of ObjC classes.
EXPERIMENTAL_FEATURE(ObjCImplementation, true)
Expand Down
11 changes: 0 additions & 11 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5117,17 +5117,6 @@ ActorIsolation ActorIsolationRequest::evaluate(
llvm_unreachable("cannot infer erased isolation");

case ActorIsolation::GlobalActor: {
// Stored properties of a struct don't need global-actor isolation.
if (ctx.isSwiftVersionAtLeast(6))
if (auto *var = dyn_cast<VarDecl>(value))
if (!var->isStatic() && var->isOrdinaryStoredProperty())
if (auto *varDC = var->getDeclContext())
if (auto *nominal = varDC->getSelfNominalTypeDecl())
if (isa<StructDecl>(nominal) &&
!isWrappedValueOfPropWrapper(var))
return ActorIsolation::forUnspecified().withPreconcurrency(
inferred.preconcurrency());

auto typeExpr =
TypeExpr::createImplicit(inferred.getGlobalActor(), ctx);
auto attr =
Expand Down
26 changes: 24 additions & 2 deletions test/Concurrency/global_actor_inference_swift6.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

// RUN: %target-swift-frontend -swift-version 6 -emit-module -emit-module-path %t/other_global_actor_inference.swiftmodule -module-name other_global_actor_inference -strict-concurrency=complete %S/Inputs/other_global_actor_inference.swift

// RUN: %target-swift-frontend -swift-version 6 -I %t -disable-availability-checking %s -emit-sil -o /dev/null -verify
// RUN: %target-swift-frontend -swift-version 6 -I %t -disable-availability-checking %s -emit-sil -o /dev/null -verify -enable-upcoming-feature RegionBasedIsolation
// RUN: %target-swift-frontend -swift-version 6 -I %t -disable-availability-checking %s -emit-sil -o /dev/null -verify -enable-experimental-feature GlobalActorIsolatedTypesUsability
// RUN: %target-swift-frontend -swift-version 6 -I %t -disable-availability-checking %s -emit-sil -o /dev/null -verify -enable-experimental-feature GlobalActorIsolatedTypesUsability

// REQUIRES: concurrency

Expand Down Expand Up @@ -132,3 +132,25 @@ struct Carbon {
return atomicWeight // expected-error {{main actor-isolated property 'atomicWeight' can not be referenced from a non-isolated context}}
}
}

@MainActor
protocol InferMainActor {}

@propertyWrapper
@preconcurrency @MainActor
struct Wrapper<T> {
var wrappedValue: T {
fatalError()
}

init() {}
}

@MainActor
class C {
nonisolated init() {}
}

struct S: InferMainActor {
@Wrapper var value: C // okay, 'S' is isolated to 'MainActor'
}