Skip to content

Commit 9851305

Browse files
committedFeb 12, 2025
[concurrency] Make sure both with and without the flag, we codegen execution(caller|concurrent) correctly.
The flag is specifically NonIsolatedAsyncInheritsIsolationFromContext. I noticed that we were not codegening @execution(caller) when the flag was disabled, so I fixed it and added this test.
1 parent 945d36e commit 9851305

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed
 

‎lib/SIL/IR/SILFunctionType.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -1649,9 +1649,7 @@ class DestructureInputs {
16491649
// If we are an async function that is unspecified or nonisolated, insert an
16501650
// isolated parameter if NonIsolatedAsyncInheritsIsolationFromContext is
16511651
// enabled.
1652-
if (TC.Context.LangOpts.hasFeature(
1653-
Feature::NonIsolatedAsyncInheritsIsolationFromContext) &&
1654-
IsolationInfo &&
1652+
if (IsolationInfo &&
16551653
IsolationInfo->getKind() == ActorIsolation::CallerIsolationInheriting &&
16561654
extInfoBuilder.isAsync()) {
16571655
auto actorProtocol = TC.Context.getProtocol(KnownProtocolKind::Actor);

‎lib/SILGen/SILGenConcurrency.cpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,18 @@ setExpectedExecutorForParameterIsolation(SILGenFunction &SGF,
7474
// If we have caller isolation inheriting... just grab from our isolated
7575
// argument.
7676
if (actorIsolation.getKind() == ActorIsolation::CallerIsolationInheriting) {
77-
if (auto *isolatedArg = SGF.F.maybeGetIsolatedArgument()) {
78-
ManagedValue isolatedMV;
79-
if (isolatedArg->getOwnershipKind() == OwnershipKind::Guaranteed) {
80-
isolatedMV = ManagedValue::forBorrowedRValue(isolatedArg);
81-
} else {
82-
isolatedMV = ManagedValue::forUnmanagedOwnedValue(isolatedArg);
83-
}
84-
85-
SGF.ExpectedExecutor.set(SGF.emitLoadActorExecutor(loc, isolatedMV));
86-
return;
77+
auto *isolatedArg = SGF.F.maybeGetIsolatedArgument();
78+
assert(isolatedArg &&
79+
"Caller Isolation Inheriting without isolated parameter");
80+
ManagedValue isolatedMV;
81+
if (isolatedArg->getOwnershipKind() == OwnershipKind::Guaranteed) {
82+
isolatedMV = ManagedValue::forBorrowedRValue(isolatedArg);
83+
} else {
84+
isolatedMV = ManagedValue::forUnmanagedOwnedValue(isolatedArg);
8785
}
86+
87+
SGF.ExpectedExecutor.set(SGF.emitLoadActorExecutor(loc, isolatedMV));
88+
return;
8889
}
8990

9091
llvm_unreachable("Unhandled case?!");

‎test/SILGen/execution_attr.swift

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
2+
// RUN: %target-swift-emit-silgen %s -enable-experimental-feature NonIsolatedAsyncInheritsIsolationFromContext | %FileCheck %s
3+
4+
// REQUIRES: concurrency
5+
// REQUIRES: asserts
6+
// REQUIRES: swift_feature_NonIsolatedAsyncInheritsIsolationFromContext
7+
8+
// Validate that both with and without the experimental flag we properly codegen
9+
// execution(caller) and execution(concurrent).
10+
11+
// CHECK-LABEL: // executionCaller()
12+
// CHECK-NEXT: // Isolation: caller_isolation_inheriting
13+
// CHECK-NEXT: sil hidden [ossa] @$s14execution_attr0A6CalleryyYaF : $@convention(thin) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>) -> () {
14+
@execution(caller)
15+
func executionCaller() async {}
16+
17+
// CHECK-LABEL: // executionConcurrent()
18+
// CHECK: // Isolation: nonisolated
19+
// CHECK: sil hidden [ossa] @$s14execution_attr0A10ConcurrentyyYaF : $@convention(thin) @async () -> () {
20+
@execution(concurrent)
21+
func executionConcurrent() async {}

0 commit comments

Comments
 (0)