Skip to content

Commit 7648bce

Browse files
authored
Merge pull request #80210 from gottesmm/pr-5cf03315e9a3442419b1bab18b46f755fdf0b405
[concurrency] Make sure that TypeLowering inserts the extra actor parameter for @execution(caller) parameters.
2 parents b0ffa78 + 2d5dd75 commit 7648bce

File tree

4 files changed

+74
-4
lines changed

4 files changed

+74
-4
lines changed

include/swift/AST/ActorIsolation.h

+4
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ class ActorIsolation {
233233

234234
bool isDistributedActor() const;
235235

236+
bool isCallerIsolationInheriting() const {
237+
return getKind() == CallerIsolationInheriting;
238+
}
239+
236240
Type getGlobalActor() const {
237241
assert(isGlobalActor());
238242

lib/AST/ASTDumper.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -6313,6 +6313,22 @@ namespace {
63136313
break;
63146314
}
63156315
}
6316+
auto isolation = T->getIsolation();
6317+
switch (isolation.getKind()) {
6318+
case FunctionTypeIsolation::Kind::NonIsolated:
6319+
case FunctionTypeIsolation::Kind::Parameter:
6320+
break;
6321+
case FunctionTypeIsolation::Kind::GlobalActor:
6322+
printRec(isolation.getGlobalActorType(),
6323+
Label::always("global_actor"));
6324+
break;
6325+
case FunctionTypeIsolation::Kind::Erased:
6326+
printFlag("@isolated(any)");
6327+
break;
6328+
case FunctionTypeIsolation::Kind::NonIsolatedCaller:
6329+
printFlag("@execution(caller)");
6330+
break;
6331+
}
63166332
}
63176333
if (Type globalActor = T->getGlobalActor()) {
63186334
printFieldQuoted(globalActor.getString(), Label::always("global_actor"));

lib/SIL/IR/SILFunctionType.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -1665,8 +1665,7 @@ class DestructureInputs {
16651665

16661666
// If we are an async function that is unspecified or nonisolated, insert an
16671667
// isolated parameter if AsyncCallerExecution is enabled.
1668-
if (IsolationInfo &&
1669-
IsolationInfo->getKind() == ActorIsolation::CallerIsolationInheriting &&
1668+
if (IsolationInfo && IsolationInfo->isCallerIsolationInheriting() &&
16701669
extInfoBuilder.isAsync()) {
16711670
auto actorProtocol = TC.Context.getProtocol(KnownProtocolKind::Actor);
16721671
auto actorType =
@@ -2592,6 +2591,13 @@ static CanSILFunctionType getSILFunctionType(
25922591
actorIsolation =
25932592
getActorIsolationOfContext(constant->getInnermostDeclContext());
25942593
}
2594+
} else if (substFnInterfaceType->hasExtInfo() &&
2595+
substFnInterfaceType->getExtInfo()
2596+
.getIsolation()
2597+
.isNonIsolatedCaller()) {
2598+
// If our function type is a nonisolated caller and we can not infer from
2599+
// our constant, we must be caller isolation inheriting.
2600+
actorIsolation = ActorIsolation::forCallerIsolationInheriting();
25952601
}
25962602
DestructureInputs destructurer(expansionContext, TC, conventions,
25972603
foreignInfo, actorIsolation, inputs,

test/SILGen/execution_attr.swift

+46-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-swift-emit-silgen %s -enable-experimental-feature ExecutionAttribute | %FileCheck %s
2-
// RUN: %target-swift-emit-silgen %s -enable-experimental-feature ExecutionAttribute -enable-experimental-feature AsyncCallerExecution | %FileCheck %s
1+
// RUN: %target-swift-emit-silgen %s -enable-experimental-feature ExecutionAttribute | %FileCheck -check-prefix CHECK -check-prefix DISABLED %s
2+
// RUN: %target-swift-emit-silgen %s -enable-experimental-feature ExecutionAttribute -enable-experimental-feature AsyncCallerExecution | %FileCheck -check-prefix CHECK -check-prefix ENABLED %s
33

44
// REQUIRES: concurrency
55
// REQUIRES: swift_feature_ExecutionAttribute
@@ -19,3 +19,47 @@ func executionCaller() async {}
1919
// CHECK: sil hidden [ossa] @$s14execution_attr0A10ConcurrentyyYaF : $@convention(thin) @async () -> () {
2020
@execution(concurrent)
2121
func executionConcurrent() async {}
22+
23+
// DISABLED: sil hidden [ossa] @$s14execution_attr0A15CallerParameteryyyyYaYCXEYaF : $@convention(thin) @async (@guaranteed @noescape @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>) -> ()) -> () {
24+
// ENABLED: sil hidden [ossa] @$s14execution_attr0A15CallerParameteryyyyYaYCXEYaF : $@convention(thin) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, @guaranteed @noescape @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>) -> ()) -> () {
25+
// CHECK: } // end sil function '$s14execution_attr0A15CallerParameteryyyyYaYCXEYaF'
26+
func executionCallerParameter(_ x: @execution(caller) () async -> ()) async {
27+
await x()
28+
}
29+
30+
// DISABLED-LABEL: sil hidden [ossa] @$s14execution_attr0A19ConcurrentParameteryyyyYaXEYaF : $@convention(thin) @async (@guaranteed @noescape @async @callee_guaranteed () -> ()) -> () {
31+
// ENABLED-LABEL: sil hidden [ossa] @$s14execution_attr0A19ConcurrentParameteryyyyYaXEYaF : $@convention(thin) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, @guaranteed @noescape @async @callee_guaranteed () -> ()) -> () {
32+
func executionConcurrentParameter(_ x: @execution(concurrent) () async -> ()) async {
33+
await x()
34+
}
35+
36+
struct S {
37+
let field: @execution(caller) () async -> ()
38+
}
39+
40+
// DISABLED: sil hidden [ossa] @$s14execution_attr0A11CallerFieldyyAA1SVYaF : $@convention(thin) @async (@guaranteed S) -> () {
41+
// DISABLED: bb0([[ARG:%.*]] : @guaranteed $S):
42+
// DISABLED: [[FIELD:%.*]] = struct_extract [[ARG]]
43+
// DISABLED: [[FIELD_COPY:%.*]] = copy_value [[FIELD]]
44+
// DISABLED: [[ACTOR_NONE:%.*]] = enum $Optional<any Actor>, #Optional.none!enumelt
45+
// DISABLED: [[BORROWED_FIELD:%.*]] = begin_borrow [[FIELD_COPY]]
46+
// DISABLED: apply [[BORROWED_FIELD]]([[ACTOR_NONE]])
47+
// DISABLED: } // end sil function '$s14execution_attr0A11CallerFieldyyAA1SVYaF'
48+
49+
// ENABLED: sil hidden [ossa] @$s14execution_attr0A11CallerFieldyyAA1SVYaF : $@convention(thin) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, @guaranteed S) -> () {
50+
// ENABLED: bb0([[ACTOR:%.*]] : @guaranteed $Optional<any Actor>, [[ARG:%.*]] : @guaranteed $S):
51+
// ENABLED: [[FIELD:%.*]] = struct_extract [[ARG]]
52+
// ENABLED: [[FIELD_COPY:%.*]] = copy_value [[FIELD]]
53+
// ENABLED: [[BORROWED_FIELD:%.*]] = begin_borrow [[FIELD_COPY]]
54+
// ENABLED: apply [[BORROWED_FIELD]]([[ACTOR]])
55+
// ENABLED: } // end sil function '$s14execution_attr0A11CallerFieldyyAA1SVYaF'
56+
func executionCallerField(_ s: S) async {
57+
await s.field()
58+
}
59+
60+
extension S {
61+
// CHECK-LABEL: // S.executionCallerFieldMethod(_:)
62+
// CHECK: // Isolation: unspecified
63+
// CHECK: sil hidden [ossa] @$s14execution_attr1SV0A17CallerFieldMethodyyyyYaYCXEF : $@convention(method) (@guaranteed @noescape @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>) -> (), @guaranteed S) -> () {
64+
func executionCallerFieldMethod(_ x: @execution(caller) () async -> ()) {}
65+
}

0 commit comments

Comments
 (0)