Skip to content

Commit ca0061d

Browse files
authored
Merge pull request #66773 from eeckstein/fix-hop-to-executor
SIL: hop_to_executor can release
2 parents 1dcdb6e + ceb32c0 commit ca0061d

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

include/swift/SIL/SILNodes.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ NON_VALUE_INST(FixLifetimeInst, fix_lifetime,
796796
SILInstruction, MayHaveSideEffects, DoesNotRelease)
797797

798798
NON_VALUE_INST(HopToExecutorInst, hop_to_executor,
799-
SILInstruction, MayHaveSideEffects, DoesNotRelease)
799+
SILInstruction, MayHaveSideEffects, MayRelease)
800800

801801
NON_VALUE_INST(DestroyValueInst, destroy_value,
802802
SILInstruction, MayHaveSideEffects, MayRelease)

lib/SIL/IR/SILInstruction.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,7 @@ bool SILInstruction::mayRelease() const {
11191119
return true;
11201120

11211121
case SILInstructionKind::DestroyValueInst:
1122+
case SILInstructionKind::HopToExecutorInst:
11221123
return true;
11231124

11241125
case SILInstructionKind::UnconditionalCheckedCastAddrInst:

test/SILOptimizer/retain_release_code_motion.sil

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ class C2 {
5050
init()
5151
}
5252

53+
class Y {
54+
@_hasStorage public var c: C2 { get }
55+
}
56+
57+
actor Act {
58+
}
59+
5360
struct S {
5461
var ptr : Builtin.NativeObject
5562
}
@@ -1078,3 +1085,24 @@ bb0:
10781085
%12 = tuple ()
10791086
return %12 : $()
10801087
}
1088+
1089+
// CHECK-LABEL: sil @test_hop_to_executor :
1090+
// CHECK: strong_retain
1091+
// CHECK: hop_to_executor
1092+
// CHECK: strong_release
1093+
// CHECK: } // end sil function 'test_hop_to_executor'
1094+
sil @test_hop_to_executor : $@convention(thin) @async (@guaranteed Y, @guaranteed Act) -> A {
1095+
bb0(%0 : $Y, %1 : $Act):
1096+
%2 = ref_element_addr %0 : $Y, #Y.c
1097+
%3 = load %2 : $*C2
1098+
strong_retain %3 : $C2
1099+
1100+
// This is a synchronization point and any kind of other code might run here,
1101+
// which potentially can release C2.
1102+
hop_to_executor %1 : $Act
1103+
1104+
%6 = ref_element_addr %3 : $C2, #C2.current
1105+
%7 = load %6 : $*A
1106+
strong_release %3 : $C2
1107+
return %7 : $A
1108+
}

0 commit comments

Comments
 (0)