From dec3a9a1d9419d833e2a80c1604b00b463774595 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 5 Nov 2021 15:37:58 -0700 Subject: [PATCH 1/2] 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. --- lib/Sema/TypeCheckConcurrency.cpp | 7 +++++++ test/Concurrency/global_actor_inference.swift | 13 ++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/Sema/TypeCheckConcurrency.cpp b/lib/Sema/TypeCheckConcurrency.cpp index 4737591f2e15a..8c188fe83e67a 100644 --- a/lib/Sema/TypeCheckConcurrency.cpp +++ b/lib/Sema/TypeCheckConcurrency.cpp @@ -3344,6 +3344,13 @@ ActorIsolation ActorIsolationRequest::evaluate( return inferredIsolation(isolation); } + // If this is a dynamic replacement for another function, use the + // actor isolation of the function it replaces. + if (auto replacedDecl = value->getDynamicallyReplacedDecl()) { + if (auto isolation = getActorIsolation(replacedDecl)) + return inferredIsolation(isolation); + } + if (shouldInferAttributeInContext(value->getDeclContext())) { // If the declaration witnesses a protocol requirement that is isolated, // use that. diff --git a/test/Concurrency/global_actor_inference.swift b/test/Concurrency/global_actor_inference.swift index 84de2be68f223..d23cc3992c586 100644 --- a/test/Concurrency/global_actor_inference.swift +++ b/test/Concurrency/global_actor_inference.swift @@ -1,5 +1,8 @@ -// RUN: %target-typecheck-verify-swift -disable-availability-checking +// RUN: %empty-directory(%t) +// RUN: %target-swift-frontend -emit-module -emit-module-path %t/dynamically_replaceable.swiftmodule -module-name dynamically_replaceable -warn-concurrency %S/Inputs/dynamically_replaceable.swift +// RUN: %target-typecheck-verify-swift -I %t -disable-availability-checking // REQUIRES: concurrency +import dynamically_replaceable actor SomeActor { } @@ -552,3 +555,11 @@ func useFooInADefer() -> String { return "hello" } + +// ---------------------------------------------------------------------- +// Dynamic replacement +// ---------------------------------------------------------------------- +@_dynamicReplacement(for: dynamicOnMainActor) +func replacesDynamicOnMainActor() { + onlyOnMainActor() +} From 8700ecdc15c5ceec32be624144fc4d4615235002 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 5 Nov 2021 19:29:26 -0700 Subject: [PATCH 2/2] Add missing test input --- test/Concurrency/Inputs/dynamically_replaceable.swift | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 test/Concurrency/Inputs/dynamically_replaceable.swift diff --git a/test/Concurrency/Inputs/dynamically_replaceable.swift b/test/Concurrency/Inputs/dynamically_replaceable.swift new file mode 100644 index 0000000000000..08632d00bee2a --- /dev/null +++ b/test/Concurrency/Inputs/dynamically_replaceable.swift @@ -0,0 +1,2 @@ +@MainActor +public dynamic func dynamicOnMainActor() { }