Skip to content

Commit 31ff9b4

Browse files
authored
Merge pull request #81219 from xedin/nonisolated-nonsending-inference-for-storage
[Concurrency] Allow `nonisolated(nonsending)` inference on properties…
2 parents 34be8f9 + 8a9bbd5 commit 31ff9b4

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

lib/Sema/TypeCheckConcurrency.cpp

+9-13
Original file line numberDiff line numberDiff line change
@@ -4933,10 +4933,11 @@ getIsolationFromAttributes(const Decl *decl, bool shouldDiagnose = true,
49334933
// return caller isolation inheriting.
49344934
if (decl->getASTContext().LangOpts.hasFeature(
49354935
Feature::NonisolatedNonsendingByDefault)) {
4936-
if (auto *func = dyn_cast<AbstractFunctionDecl>(decl);
4937-
func && func->hasAsync() &&
4938-
func->getModuleContext() == decl->getASTContext().MainModule) {
4939-
return ActorIsolation::forCallerIsolationInheriting();
4936+
if (auto *value = dyn_cast<ValueDecl>(decl)) {
4937+
if (value->isAsync() &&
4938+
value->getModuleContext() == decl->getASTContext().MainModule) {
4939+
return ActorIsolation::forCallerIsolationInheriting();
4940+
}
49404941
}
49414942
}
49424943

@@ -5795,11 +5796,9 @@ computeDefaultInferredActorIsolation(ValueDecl *value) {
57955796
return *result;
57965797
}
57975798

5798-
// If we have an async function... by default we inherit isolation.
5799+
// If we have an async function or storage... by default we inherit isolation.
57995800
if (ctx.LangOpts.hasFeature(Feature::NonisolatedNonsendingByDefault)) {
5800-
if (auto *func = dyn_cast<AbstractFunctionDecl>(value);
5801-
func && func->hasAsync() &&
5802-
func->getModuleContext() == ctx.MainModule) {
5801+
if (value->isAsync() && value->getModuleContext() == ctx.MainModule) {
58035802
return {
58045803
{ActorIsolation::forCallerIsolationInheriting(), {}}, nullptr, {}};
58055804
}
@@ -6212,11 +6211,8 @@ static InferredActorIsolation computeActorIsolation(Evaluator &evaluator,
62126211
if (selfTypeIsolation.isolation) {
62136212
auto isolation = selfTypeIsolation.isolation;
62146213

6215-
if (auto *func = dyn_cast<AbstractFunctionDecl>(value);
6216-
ctx.LangOpts.hasFeature(
6217-
Feature::NonisolatedNonsendingByDefault) &&
6218-
func && func->hasAsync() &&
6219-
func->getModuleContext() == ctx.MainModule &&
6214+
if (ctx.LangOpts.hasFeature(Feature::NonisolatedNonsendingByDefault) &&
6215+
value->isAsync() && value->getModuleContext() == ctx.MainModule &&
62206216
isolation.isNonisolated()) {
62216217
isolation = ActorIsolation::forCallerIsolationInheriting();
62226218
}

test/SILGen/nonisolated_inherits_isolation.swift

+18
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,21 @@ class MainActorKlass {
151151
await unspecifiedAsyncUse(n)
152152
}
153153
}
154+
155+
struct TestVarUse {
156+
var test: Int {
157+
// CHECK-LABEL: sil hidden [ossa] @$s30nonisolated_inherits_isolation10TestVarUseV4testSivg : $@convention(method) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, TestVarUse) -> Int
158+
get async {
159+
42
160+
}
161+
}
162+
}
163+
164+
// CHECK-LABEL: sil hidden [ossa] @$s30nonisolated_inherits_isolation12testUseOfVar1tyAA04TestgE0V_tYaF : $@convention(thin) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, TestVarUse) -> ()
165+
// CHECK: bb0([[ISOLATION:%.*]] : @guaranteed $Optional<any Actor>, [[BASE:%.*]] : $TestVarUse)
166+
// CHECK: [[GETTER:%.*]] = function_ref @$s30nonisolated_inherits_isolation10TestVarUseV4testSivg : $@convention(method) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, TestVarUse) -> Int
167+
// CHECK: {{.*}} = apply [[GETTER]]([[ISOLATION]], [[BASE]])
168+
// CHECK: } // end sil function '$s30nonisolated_inherits_isolation12testUseOfVar1tyAA04TestgE0V_tYaF'
169+
func testUseOfVar(t: TestVarUse) async {
170+
_ = await t.test
171+
}

0 commit comments

Comments
 (0)