Skip to content

Disable actor inference from property wrapper usage #63884

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
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
1 change: 1 addition & 0 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ UPCOMING_FEATURE(ForwardTrailingClosures, 286, 6)
UPCOMING_FEATURE(BareSlashRegexLiterals, 354, 6)
UPCOMING_FEATURE(ExistentialAny, 335, 6)
UPCOMING_FEATURE(ImportObjcForwardDeclarations, 384, 6)
UPCOMING_FEATURE(DisableActorInferenceFromPropertyWrapperUsage, 401, 6)

EXPERIMENTAL_FEATURE(StaticAssert, false)
EXPERIMENTAL_FEATURE(NamedOpaqueTypes, false)
Expand Down
5 changes: 5 additions & 0 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3346,6 +3346,11 @@ static bool usesFeatureBuiltinMacros(Decl *decl) {
return false;
}


static bool usesFeatureDisableActorInferenceFromPropertyWrapperUsage(Decl *decl) {
return false;
}

static bool usesFeatureImportSymbolicCXXDecls(Decl *decl) { return false; }

static bool usesFeatureGenerateBindingsForThrowingFunctionsInCXX(Decl *decl) {
Expand Down
11 changes: 9 additions & 2 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3653,6 +3653,13 @@ getIsolationFromWrappers(NominalTypeDecl *nominal) {
if (!nominal->getParentSourceFile())
return llvm::None;

ASTContext &ctx = nominal->getASTContext();
if (ctx.LangOpts.hasFeature(Feature::DisableActorInferenceFromPropertyWrapperUsage)) {
// In Swift 6, we no longer infer isolation of a nominal type
// based on the property wrappers used in its stored properties
return llvm::None;
}

llvm::Optional<ActorIsolation> foundIsolation;
for (auto member : nominal->getMembers()) {
auto var = dyn_cast<VarDecl>(member);
Expand Down Expand Up @@ -4266,8 +4273,8 @@ ActorIsolation ActorIsolationRequest::evaluate(
if (auto inferred = inferredIsolation(*conformanceIsolation))
return inferred;

// If the declaration is a nominal type and any property wrappers on
// its stored properties require isolation, use that.
// Before Swift 6: If the declaration is a nominal type and any property
// wrappers on its stored properties require isolation, use that.
if (auto wrapperIsolation = getIsolationFromWrappers(nominal)) {
if (auto inferred = inferredIsolation(*wrapperIsolation))
return inferred;
Expand Down
4 changes: 2 additions & 2 deletions test/Concurrency/global_actor_inference_swift6.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct HasMainActorWrappedProp {

var plainStorage: Int

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

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

_ = plainStorage

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

Expand Down