File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed
lib/SILOptimizer/SILCombiner Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -1914,6 +1914,9 @@ class PartialApplyInst
1914
1914
CanSILFunctionType getFunctionType () const {
1915
1915
return getType ().castTo <SILFunctionType>();
1916
1916
}
1917
+ bool hasCalleeGuaranteedContext () const {
1918
+ return getType ().castTo <SILFunctionType>()->isCalleeGuaranteed ();
1919
+ }
1917
1920
};
1918
1921
1919
1922
// ===----------------------------------------------------------------------===//
Original file line number Diff line number Diff line change @@ -334,14 +334,16 @@ bool PartialApplyCombiner::processSingleApply(FullApplySite AI) {
334
334
for (auto Arg : ToBeReleasedArgs) {
335
335
Builder.emitDestroyValueOperation (PAI->getLoc (), Arg);
336
336
}
337
- Builder.createStrongRelease (AI.getLoc (), PAI, Builder.getDefaultAtomicity ());
337
+ if (!PAI->hasCalleeGuaranteedContext ())
338
+ Builder.emitDestroyValueOperation (PAI->getLoc (), PAI);
338
339
Builder.setInsertionPoint (AI.getInstruction ());
339
340
} else {
340
341
// Release the non-consumed parameters.
341
342
for (auto Arg : ToBeReleasedArgs) {
342
343
Builder.emitDestroyValueOperation (PAI->getLoc (), Arg);
343
344
}
344
- Builder.createStrongRelease (AI.getLoc (), PAI, Builder.getDefaultAtomicity ());
345
+ if (!PAI->hasCalleeGuaranteedContext ())
346
+ Builder.emitDestroyValueOperation (PAI->getLoc (), PAI);
345
347
}
346
348
347
349
if (auto apply = dyn_cast<ApplyInst>(AI))
Original file line number Diff line number Diff line change @@ -437,3 +437,29 @@ bb99:
437
437
%empty = tuple ()
438
438
return %empty : $()
439
439
}
440
+
441
+ class C {}
442
+
443
+ sil @guaranteed_closure : $@convention(thin) (@guaranteed C) -> ()
444
+
445
+ // CHECK-LABEL: sil @test_guaranteed_closure
446
+ // CHECK: bb0([[ARG:%.*]] : $C):
447
+ // CHECK: strong_retain [[ARG]]
448
+ // CHECK: [[F:%.*]] = function_ref @guaranteed_closure
449
+ // CHECK: [[C:%.*]] = partial_apply [callee_guaranteed] [[F]]([[ARG]])
450
+ // CHECK: strong_retain [[ARG]]
451
+ // CHECK: apply [[F]]
452
+ // Don't release the closure context -- it is @callee_guaranteed.
453
+ // CHECK-NOT: strong_release [[C]] : $@callee_guaranteed () -> ()
454
+ // CHECK: strong_release [[ARG]]
455
+ // CHECK-NOT: strong_release [[C]] : $@callee_guaranteed () -> ()
456
+ // CHECK: return [[C]]
457
+
458
+ sil @test_guaranteed_closure : $@convention(thin) (@guaranteed C) -> @owned @callee_guaranteed () -> () {
459
+ bb0(%0: $C):
460
+ strong_retain %0 : $C
461
+ %closure_fun = function_ref @guaranteed_closure : $@convention(thin) (@guaranteed C) -> ()
462
+ %closure = partial_apply [callee_guaranteed] %closure_fun(%0) : $@convention(thin) (@guaranteed C) -> ()
463
+ apply %closure() : $@callee_guaranteed () -> ()
464
+ return %closure : $@callee_guaranteed () -> ()
465
+ }
You can’t perform that action at this time.
0 commit comments