Skip to content

Commit a991179

Browse files
committed
Concurrency: Local functions should inherit isolation from context
Instead of looking at captures, which wasn't sound with recursive local functions; we would look at the captures of the function currently being type checked, which are not available yet.
1 parent c66de77 commit a991179

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5174,9 +5174,7 @@ ActorIsolation ActorIsolationRequest::evaluate(
51745174
llvm_unreachable("context cannot have erased isolation");
51755175

51765176
case ActorIsolation::ActorInstance:
5177-
if (auto param = func->getCaptureInfo().getIsolatedParamCapture())
5178-
return inferredIsolation(enclosingIsolation);
5179-
break;
5177+
return inferredIsolation(enclosingIsolation);
51805178

51815179
case ActorIsolation::GlobalActor:
51825180
return inferredIsolation(enclosingIsolation);

test/Concurrency/actor_isolation.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ func checkLocalFunctions() async {
755755
print(k)
756756
}
757757

758+
func callee(_: () -> ()) {}
759+
758760
@available(SwiftStdlib 5.1, *)
759761
actor LocalFunctionIsolatedActor {
760762
func a() -> Bool { // expected-note{{calls to instance method 'a()' from outside of its actor context are implicitly asynchronous}}
@@ -774,6 +776,30 @@ actor LocalFunctionIsolatedActor {
774776
}
775777
return c()
776778
}
779+
780+
func hasRecursiveLocalFunction() {
781+
func recursiveLocalFunction(n: Int) {
782+
_ = a()
783+
callee { _ = a() }
784+
if n > 0 { recursiveLocalFunction(n: n - 1) }
785+
}
786+
787+
recursiveLocalFunction(n: 10)
788+
}
789+
790+
func hasRecursiveLocalFunctions() {
791+
recursiveLocalFunction()
792+
793+
func recursiveLocalFunction() {
794+
anotherRecursiveLocalFunction()
795+
}
796+
797+
func anotherRecursiveLocalFunction() {
798+
callee { _ = a() }
799+
_ = a()
800+
}
801+
}
802+
777803
}
778804

779805
// ----------------------------------------------------------------------

0 commit comments

Comments
 (0)