Skip to content

Commit 6c27021

Browse files
authored
Merge pull request #71093 from DougGregor/isolation-distributed-actors
Implement support for #isolation for distributed actors
2 parents 0e8ffef + f79a108 commit 6c27021

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3460,6 +3460,13 @@ namespace {
34603460
actorExpr = new (ctx) DeclRefExpr(
34613461
const_cast<VarDecl *>(var), DeclNameLoc(loc),
34623462
/*Implicit=*/true);
3463+
3464+
// For a distributed actor, we need to retrieve the local
3465+
// actor.
3466+
if (isolation.isDistributedActor()) {
3467+
actorExpr = UnresolvedDotExpr::createImplicit(
3468+
ctx, actorExpr, ctx.getIdentifier("asLocalActor"));
3469+
}
34633470
break;
34643471
}
34653472
case ActorIsolation::GlobalActor: {
@@ -3480,6 +3487,7 @@ namespace {
34803487
break;
34813488
}
34823489

3490+
34833491
// Convert the actor argument to the appropriate type.
34843492
(void)TypeChecker::typeCheckExpression(
34853493
actorExpr, const_cast<DeclContext *>(getDeclContext()),
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// RUN: %target-swift-frontend -typecheck %s -enable-experimental-feature OptionalIsolatedParameters -verify
2+
3+
// RUN: %target-swift-frontend -dump-ast %s -enable-experimental-feature OptionalIsolatedParameters | %FileCheck %s
4+
5+
// REQUIRES: concurrency
6+
// REQUIRES: asserts
7+
// REQUIRES: distributed
8+
9+
import Distributed
10+
11+
@available(SwiftStdlib 5.7, *)
12+
extension DistributedActor {
13+
// CHECK-LABEL: actorIsolationToSelf()
14+
func actorIsolationToSelf() {
15+
// CHECK: macro_expansion_expr
16+
// CHECK: rewritten=current_context_isolation_expr
17+
// CHECK-NEXT: inject_into_optional
18+
// CHECK: member_ref_expr{{.*}}asLocalActor
19+
// CHECK: declref_expr implicit type="Self"
20+
_ = #isolation
21+
}
22+
}
23+
24+
// CHECK-LABEL: actorIsolationToParam(_:)
25+
@available(SwiftStdlib 5.7, *)
26+
func actorIsolationToParam(_ isolatedParam: isolated any DistributedActor) {
27+
// CHECK: macro_expansion_expr
28+
// CHECK: rewritten=current_context_isolation_expr
29+
// CHECK: member_ref_expr{{.*}}asLocalActor
30+
_ = #isolation
31+
}
32+
33+
func acceptClosure(_ body: () -> Void) { }
34+
35+
// CHECK-LABEL: closureIsolatedToOuterParam(
36+
@available(SwiftStdlib 5.7, *)
37+
func closureIsolatedToOuterParam(_ isolatedParam: isolated any DistributedActor) {
38+
// CHECK: closure_expr
39+
// CHECK: macro_expansion_expr
40+
// CHECK: rewritten=current_context_isolation_expr
41+
// CHECK: inject_into_optional
42+
// CHECK: member_ref_expr{{.*}}asLocalActor
43+
acceptClosure {
44+
_ = #isolation
45+
print(isolatedParam)
46+
}
47+
}

0 commit comments

Comments
 (0)