Skip to content

Commit dec3a9a

Browse files
committed
Propagate actor isolation through dynamic replacement.
Infer actor insolation through dynamic replacement, because we need the same rules for the original and the replacements. Fixes rdar://83153816.
1 parent 52df427 commit dec3a9a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3344,6 +3344,13 @@ ActorIsolation ActorIsolationRequest::evaluate(
33443344
return inferredIsolation(isolation);
33453345
}
33463346

3347+
// If this is a dynamic replacement for another function, use the
3348+
// actor isolation of the function it replaces.
3349+
if (auto replacedDecl = value->getDynamicallyReplacedDecl()) {
3350+
if (auto isolation = getActorIsolation(replacedDecl))
3351+
return inferredIsolation(isolation);
3352+
}
3353+
33473354
if (shouldInferAttributeInContext(value->getDeclContext())) {
33483355
// If the declaration witnesses a protocol requirement that is isolated,
33493356
// use that.

test/Concurrency/global_actor_inference.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
// RUN: %target-typecheck-verify-swift -disable-availability-checking
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/dynamically_replaceable.swiftmodule -module-name dynamically_replaceable -warn-concurrency %S/Inputs/dynamically_replaceable.swift
3+
// RUN: %target-typecheck-verify-swift -I %t -disable-availability-checking
24
// REQUIRES: concurrency
5+
import dynamically_replaceable
36

47
actor SomeActor { }
58

@@ -552,3 +555,11 @@ func useFooInADefer() -> String {
552555

553556
return "hello"
554557
}
558+
559+
// ----------------------------------------------------------------------
560+
// Dynamic replacement
561+
// ----------------------------------------------------------------------
562+
@_dynamicReplacement(for: dynamicOnMainActor)
563+
func replacesDynamicOnMainActor() {
564+
onlyOnMainActor()
565+
}

0 commit comments

Comments
 (0)