Skip to content

Commit 39cdc3a

Browse files
authored
Merge pull request #81238 from xedin/nonisolated-nonsending-inference-for-storage-6.2
[6.2][Concurrency] SE-0461: Allow `nonisolated(nonsending)` inference on properties…
2 parents 44c39bb + d606c94 commit 39cdc3a

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4955,10 +4955,11 @@ getIsolationFromAttributes(const Decl *decl, bool shouldDiagnose = true,
49554955
// return caller isolation inheriting.
49564956
if (decl->getASTContext().LangOpts.hasFeature(
49574957
Feature::NonisolatedNonsendingByDefault)) {
4958-
if (auto *func = dyn_cast<AbstractFunctionDecl>(decl);
4959-
func && func->hasAsync() &&
4960-
func->getModuleContext() == decl->getASTContext().MainModule) {
4961-
return ActorIsolation::forCallerIsolationInheriting();
4958+
if (auto *value = dyn_cast<ValueDecl>(decl)) {
4959+
if (value->isAsync() &&
4960+
value->getModuleContext() == decl->getASTContext().MainModule) {
4961+
return ActorIsolation::forCallerIsolationInheriting();
4962+
}
49624963
}
49634964
}
49644965

@@ -5819,11 +5820,9 @@ computeDefaultInferredActorIsolation(ValueDecl *value) {
58195820
return *result;
58205821
}
58215822

5822-
// If we have an async function... by default we inherit isolation.
5823+
// If we have an async function or storage... by default we inherit isolation.
58235824
if (ctx.LangOpts.hasFeature(Feature::NonisolatedNonsendingByDefault)) {
5824-
if (auto *func = dyn_cast<AbstractFunctionDecl>(value);
5825-
func && func->hasAsync() &&
5826-
func->getModuleContext() == ctx.MainModule) {
5825+
if (value->isAsync() && value->getModuleContext() == ctx.MainModule) {
58275826
return {
58285827
{ActorIsolation::forCallerIsolationInheriting(), {}}, nullptr, {}};
58295828
}
@@ -6236,11 +6235,8 @@ static InferredActorIsolation computeActorIsolation(Evaluator &evaluator,
62366235
if (selfTypeIsolation.isolation) {
62376236
auto isolation = selfTypeIsolation.isolation;
62386237

6239-
if (auto *func = dyn_cast<AbstractFunctionDecl>(value);
6240-
ctx.LangOpts.hasFeature(
6241-
Feature::NonisolatedNonsendingByDefault) &&
6242-
func && func->hasAsync() &&
6243-
func->getModuleContext() == ctx.MainModule &&
6238+
if (ctx.LangOpts.hasFeature(Feature::NonisolatedNonsendingByDefault) &&
6239+
value->isAsync() && value->getModuleContext() == ctx.MainModule &&
62446240
isolation.isNonisolated()) {
62456241
isolation = ActorIsolation::forCallerIsolationInheriting();
62466242
}

test/SILGen/nonisolated_inherits_isolation.swift

Lines changed: 18 additions & 0 deletions
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)