Skip to content

Commit 91a4624

Browse files
authored
Merge pull request #63884 from bjhomer/disable-property-wrapper-based-isolation
Disable actor inference from property wrapper usage
2 parents ca66414 + 03ae003 commit 91a4624

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

Diff for: include/swift/Basic/Features.def

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ UPCOMING_FEATURE(ForwardTrailingClosures, 286, 6)
114114
UPCOMING_FEATURE(BareSlashRegexLiterals, 354, 6)
115115
UPCOMING_FEATURE(ExistentialAny, 335, 6)
116116
UPCOMING_FEATURE(ImportObjcForwardDeclarations, 384, 6)
117+
UPCOMING_FEATURE(DisableActorInferenceFromPropertyWrapperUsage, 401, 6)
117118

118119
EXPERIMENTAL_FEATURE(StaticAssert, false)
119120
EXPERIMENTAL_FEATURE(NamedOpaqueTypes, false)

Diff for: lib/AST/ASTPrinter.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -3346,6 +3346,11 @@ static bool usesFeatureBuiltinMacros(Decl *decl) {
33463346
return false;
33473347
}
33483348

3349+
3350+
static bool usesFeatureDisableActorInferenceFromPropertyWrapperUsage(Decl *decl) {
3351+
return false;
3352+
}
3353+
33493354
static bool usesFeatureImportSymbolicCXXDecls(Decl *decl) { return false; }
33503355

33513356
static bool usesFeatureGenerateBindingsForThrowingFunctionsInCXX(Decl *decl) {

Diff for: lib/Sema/TypeCheckConcurrency.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -3653,6 +3653,13 @@ getIsolationFromWrappers(NominalTypeDecl *nominal) {
36533653
if (!nominal->getParentSourceFile())
36543654
return llvm::None;
36553655

3656+
ASTContext &ctx = nominal->getASTContext();
3657+
if (ctx.LangOpts.hasFeature(Feature::DisableActorInferenceFromPropertyWrapperUsage)) {
3658+
// In Swift 6, we no longer infer isolation of a nominal type
3659+
// based on the property wrappers used in its stored properties
3660+
return llvm::None;
3661+
}
3662+
36563663
llvm::Optional<ActorIsolation> foundIsolation;
36573664
for (auto member : nominal->getMembers()) {
36583665
auto var = dyn_cast<VarDecl>(member);
@@ -4266,8 +4273,8 @@ ActorIsolation ActorIsolationRequest::evaluate(
42664273
if (auto inferred = inferredIsolation(*conformanceIsolation))
42674274
return inferred;
42684275

4269-
// If the declaration is a nominal type and any property wrappers on
4270-
// its stored properties require isolation, use that.
4276+
// Before Swift 6: If the declaration is a nominal type and any property
4277+
// wrappers on its stored properties require isolation, use that.
42714278
if (auto wrapperIsolation = getIsolationFromWrappers(nominal)) {
42724279
if (auto inferred = inferredIsolation(*wrapperIsolation))
42734280
return inferred;

Diff for: test/Concurrency/global_actor_inference_swift6.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct HasMainActorWrappedProp {
7878

7979
var plainStorage: Int
8080

81-
var computedProp: Int { 0 } // expected-note {{property declared here}}
81+
var computedProp: Int { 0 }
8282

8383
nonisolated func testErrors() {
8484
_ = thing // expected-error {{main actor-isolated property 'thing' can not be referenced from a non-isolated context}}
@@ -89,7 +89,7 @@ struct HasMainActorWrappedProp {
8989

9090
_ = plainStorage
9191

92-
_ = computedProp // expected-error {{main actor-isolated property 'computedProp' can not be referenced from a non-isolated context}}
92+
_ = computedProp
9393
}
9494
}
9595

0 commit comments

Comments
 (0)