Skip to content

Commit a43779c

Browse files
committed
[Concurrency] Handle #isolation in isolated argument checking.
1 parent f2b0885 commit a43779c

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

lib/AST/Decl.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11238,9 +11238,6 @@ ActorIsolation::forActorInstanceParameter(Expr *actor,
1123811238
unsigned parameterIndex) {
1123911239
auto &ctx = actor->getType()->getASTContext();
1124011240

11241-
if (auto *isolation = dyn_cast<CurrentContextIsolationExpr>(actor))
11242-
actor = isolation->getActor();
11243-
1124411241
// An isolated value of `nil` is statically nonisolated.
1124511242
// FIXME: Also allow 'Optional.none'
1124611243
if (dyn_cast<NilLiteralExpr>(actor))

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3281,6 +3281,17 @@ namespace {
32813281
continue;
32823282

32833283
auto *arg = args->getExpr(paramIdx);
3284+
3285+
// FIXME: CurrentContextIsolationExpr does not have its actor set
3286+
// at this point.
3287+
if (auto *macro = dyn_cast<MacroExpansionExpr>(arg)) {
3288+
auto *expansion = macro->getRewritten();
3289+
if (auto *isolation = dyn_cast<CurrentContextIsolationExpr>(expansion)) {
3290+
recordCurrentContextIsolation(isolation);
3291+
arg = isolation->getActor();
3292+
}
3293+
}
3294+
32843295
argForIsolatedParam = arg;
32853296
if (getIsolatedActor(arg))
32863297
continue;

test/Concurrency/isolated_parameters.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,18 +442,22 @@ func sync(isolatedTo actor: isolated (any Actor)?) {}
442442
func preciseIsolated(a: isolated MyActor) async {
443443
sync(isolatedTo: a)
444444
sync(isolatedTo: nil) // okay from anywhere
445+
sync(isolatedTo: #isolation)
445446

446447
Task { @MainActor in
447448
sync(isolatedTo: MainActor.shared)
448449
sync(isolatedTo: nil) // okay from anywhere
450+
sync(isolatedTo: #isolation)
449451
}
450452

451453
Task { @MyGlobal in
452454
sync(isolatedTo: MyGlobal.shared)
453455
sync(isolatedTo: nil) // okay from anywhere
456+
sync(isolatedTo: #isolation)
454457
}
455458

456459
Task.detached {
457460
sync(isolatedTo: nil) // okay from anywhere
461+
sync(isolatedTo: #isolation)
458462
}
459463
}

0 commit comments

Comments
 (0)