Skip to content

Commit ea23b8a

Browse files
Merge pull request #76685 from nate-chandler/rdar136609584
[SILCombine] Destroy unowned with unowned_release.
2 parents ef148eb + 14f9088 commit ea23b8a

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/SILOptimizer/Utils/InstOptUtils.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,13 @@ void swift::emitDestroyOperation(SILBuilder &builder, SILLocation loc,
10081008
return;
10091009
}
10101010

1011+
if (operand->getType().isUnownedStorageType()) {
1012+
auto release = builder.createUnownedRelease(loc, operand,
1013+
builder.getDefaultAtomicity());
1014+
callbacks.createdNewInst(release);
1015+
return;
1016+
}
1017+
10111018
if (operand->getType().isReferenceCounted(builder.getModule())) {
10121019
auto u = builder.emitStrongRelease(loc, operand);
10131020
if (u.isNull())

test/SILOptimizer/sil_combine_pa_removal.sil

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,27 @@ bb0(%0 : $K):
4040

4141
sil @our_closure_function2 : $@convention(thin) (@owned K) -> Bool
4242
sil @our_closure_function1 : $@convention(thin) (Int64) -> Bool
43+
44+
sil @toBeClosed : $@convention(thin) (@guaranteed @sil_unowned K) -> ()
45+
sil @takeClosure : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> ()
46+
47+
// CHECK-LABEL: sil @opt_partial_apply_of_an_unowned : {{.*}} {
48+
// CHECK: bb0([[UNOWNED_VALUE:%[^,]+]] :
49+
// CHECK: [[TO_BE_CLOSED:%[^,]+]] = function_ref @toBeClosed
50+
// CHECK: unowned_retain [[UNOWNED_VALUE]]
51+
// CHECK: apply [[TO_BE_CLOSED]]([[UNOWNED_VALUE]])
52+
// CHECK: unowned_release [[UNOWNED_VALUE]]
53+
// CHECK: unowned_release [[UNOWNED_VALUE]]
54+
// CHECK-LABEL: } // end sil function 'opt_partial_apply_of_an_unowned'
55+
sil @opt_partial_apply_of_an_unowned : $@convention(thin) (@guaranteed @sil_unowned K) -> () {
56+
bb0(%1 : @closureCapture $@sil_unowned K):
57+
%678 = function_ref @toBeClosed : $@convention(thin) (@guaranteed @sil_unowned K) -> ()
58+
%680 = partial_apply [callee_guaranteed] %678(%1) : $@convention(thin) (@guaranteed @sil_unowned K) -> ()
59+
%681 = function_ref @takeClosure : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> ()
60+
strong_retain %680 : $@callee_guaranteed () -> ()
61+
%683 = partial_apply [callee_guaranteed] %681(%680) : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> ()
62+
%876 = apply %680() : $@callee_guaranteed () -> ()
63+
strong_release %680 : $@callee_guaranteed () -> ()
64+
%retval = tuple ()
65+
return %retval : $()
66+
}

0 commit comments

Comments
 (0)