Skip to content

Commit aaf6dba

Browse files
committed
[Concurrency] Don't error on isolated property wrapper initializers inside
MainActor-isolated structs. (cherry picked from commit a6d9c15)
1 parent f36098a commit aaf6dba

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ EXPERIMENTAL_FEATURE(CImplementation, true)
379379
EXPERIMENTAL_FEATURE(DebugDescriptionMacro, true)
380380

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

384384
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
385385
#undef EXPERIMENTAL_FEATURE

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5115,17 +5115,6 @@ ActorIsolation ActorIsolationRequest::evaluate(
51155115
llvm_unreachable("cannot infer erased isolation");
51165116

51175117
case ActorIsolation::GlobalActor: {
5118-
// Stored properties of a struct don't need global-actor isolation.
5119-
if (ctx.isSwiftVersionAtLeast(6))
5120-
if (auto *var = dyn_cast<VarDecl>(value))
5121-
if (!var->isStatic() && var->isOrdinaryStoredProperty())
5122-
if (auto *varDC = var->getDeclContext())
5123-
if (auto *nominal = varDC->getSelfNominalTypeDecl())
5124-
if (isa<StructDecl>(nominal) &&
5125-
!isWrappedValueOfPropWrapper(var))
5126-
return ActorIsolation::forUnspecified().withPreconcurrency(
5127-
inferred.preconcurrency());
5128-
51295118
auto typeExpr =
51305119
TypeExpr::createImplicit(inferred.getGlobalActor(), ctx);
51315120
auto attr =

test/Concurrency/global_actor_inference_swift6.swift

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
// 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
44

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

88
// REQUIRES: concurrency
99

@@ -132,3 +132,25 @@ struct Carbon {
132132
return atomicWeight // expected-error {{main actor-isolated property 'atomicWeight' can not be referenced from a non-isolated context}}
133133
}
134134
}
135+
136+
@MainActor
137+
protocol InferMainActor {}
138+
139+
@propertyWrapper
140+
@preconcurrency @MainActor
141+
struct Wrapper<T> {
142+
var wrappedValue: T {
143+
fatalError()
144+
}
145+
146+
init() {}
147+
}
148+
149+
@MainActor
150+
class C {
151+
nonisolated init() {}
152+
}
153+
154+
struct S: InferMainActor {
155+
@Wrapper var value: C // okay, 'S' is isolated to 'MainActor'
156+
}

0 commit comments

Comments
 (0)