Skip to content

Commit e2ddb08

Browse files
committed
[region-isolation] Change semantics of function_extract_isolation from AssertingIfNonSendable -> Require.
The reason why I am doing this is that: 1. function_extract_isolation can take as a parameter a non-Sendable function today in SIL so in such a case, we crash. 2. It returns an Optional<any Actor> which always must be Sendable. So it makes sense for it to just require that its non-Sendable parameter not be transferred at that point.
1 parent 4c5558d commit e2ddb08

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2638,7 +2638,7 @@ CONSTANT_TRANSLATION(DynamicMethodBranchInst, TerminatorPhi)
26382638
CONSTANT_TRANSLATION(AwaitAsyncContinuationInst, AssertingIfNonSendable)
26392639
CONSTANT_TRANSLATION(GetAsyncContinuationInst, AssertingIfNonSendable)
26402640
CONSTANT_TRANSLATION(ExtractExecutorInst, AssertingIfNonSendable)
2641-
CONSTANT_TRANSLATION(FunctionExtractIsolationInst, AssertingIfNonSendable)
2641+
CONSTANT_TRANSLATION(FunctionExtractIsolationInst, Require)
26422642

26432643
//===---
26442644
// Existential Box

test/Concurrency/transfernonsendable_instruction_matching.sil

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ sil_stage raw
1717

1818
import Swift
1919
import Builtin
20+
import _Concurrency
2021

2122
class NonSendableKlass {}
2223

@@ -1545,6 +1546,22 @@ bb0(%index : $Builtin.Word):
15451546
return %9999 : $()
15461547
}
15471548

1549+
sil @function_extract_isolation_test_closure : $@convention(thin) (@guaranteed Optional<any Actor>, Int) -> ()
1550+
1551+
// This used to crash when function_extract_isolation was AssertingIfNonSendable.
1552+
sil [ossa] @function_extract_isolation_test : $@async @convention(thin) (@owned Optional<any Actor>, Int) -> () {
1553+
bb0(%actor : @owned $Optional<any Actor>, %int : $Int):
1554+
%f = function_ref @function_extract_isolation_test_closure : $@convention(thin) (@guaranteed Optional<any Actor>, Int) -> ()
1555+
%closure = partial_apply [isolated_any] [callee_guaranteed] %f(%actor, %int) : $@convention(thin) (@guaranteed Optional<any Actor>, Int) -> ()
1556+
%closure_b = begin_borrow %closure : $@callee_guaranteed @isolated(any) () -> ()
1557+
%outputActor = function_extract_isolation %closure_b : $@callee_guaranteed @isolated(any) () -> ()
1558+
end_borrow %closure_b : $@callee_guaranteed @isolated(any) () -> ()
1559+
destroy_value %closure : $@callee_guaranteed @isolated(any) () -> ()
1560+
1561+
%9999 = tuple ()
1562+
return %9999 : $()
1563+
}
1564+
15481565
sil [ossa] @begin_unpaired_access_test : $@async @convention(thin) () -> () {
15491566
bb0:
15501567
%constructFn = function_ref @constructNonSendableKlass : $@convention(thin) () -> @owned NonSendableKlass

0 commit comments

Comments
 (0)