Skip to content

Commit ffe5fdf

Browse files
authored
Merge pull request #40073 from DougGregor/actor-isolation-infer-dynamic-replacement
2 parents d954e46 + 8700ecd commit ffe5fdf

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3353,6 +3353,13 @@ ActorIsolation ActorIsolationRequest::evaluate(
33533353
return inferredIsolation(isolation);
33543354
}
33553355

3356+
// If this is a dynamic replacement for another function, use the
3357+
// actor isolation of the function it replaces.
3358+
if (auto replacedDecl = value->getDynamicallyReplacedDecl()) {
3359+
if (auto isolation = getActorIsolation(replacedDecl))
3360+
return inferredIsolation(isolation);
3361+
}
3362+
33563363
if (shouldInferAttributeInContext(value->getDeclContext())) {
33573364
// If the declaration witnesses a protocol requirement that is isolated,
33583365
// use that.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@MainActor
2+
public dynamic func dynamicOnMainActor() { }

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)