Skip to content

Commit 606c070

Browse files
committed
[SILOptimizer] Disable SILCombiner::visitPartialApplyInst for method callees.
Disable `SILCombiner::visitPartialApplyInst` from rewriting `partial_apply` with with `@convention(method)` callee to `thin_to_thick_function`. This fixes SIL verification errors: `thin_to_thick_function` only supports `@convention(thin)` operands. Resolves SR-12548.
1 parent 06f5218 commit 606c070

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ SILInstruction *SILCombiner::visitPartialApplyInst(PartialApplyInst *PAI) {
8383
return nullptr;
8484

8585
// partial_apply without any substitutions or arguments is just a
86-
// thin_to_thick_function.
87-
if (!PAI->hasSubstitutions() && (PAI->getNumArguments() == 0)) {
86+
// thin_to_thick_function. thin_to_thick_function supports only thin operands.
87+
if (!PAI->hasSubstitutions() && (PAI->getNumArguments() == 0) &&
88+
PAI->getSubstCalleeType()->getRepresentation() ==
89+
SILFunctionTypeRepresentation::Thin) {
8890
if (!PAI->isOnStack())
8991
return Builder.createThinToThickFunction(PAI->getLoc(), PAI->getCallee(),
9092
PAI->getType());

test/AutoDiff/compiler_crashers/sr12548-siloptimizer-rewrite-partial-apply-convention-method.swift renamed to test/AutoDiff/compiler_crashers_fixed/sr12548-siloptimizer-rewrite-partial-apply-convention-method.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not %target-build-swift -O %s
1+
// RUN: %target-build-swift -O %s
22

33
// SR-12548: SIL verification error regarding
44
// `CapturePropagation::rewritePartialApply` for `partial_apply` with

test/SILOptimizer/sil_combine_apply.sil

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,3 +974,20 @@ bb0(%0: $*FakeProtocol):
974974
%r = tuple ()
975975
return %r : $()
976976
}
977+
978+
// Test `partial_apply` with a `@convention(method)` callee.
979+
// Rewriting `partial_apply` to `thin_to_thick_function` is not okay because
980+
// `thin_to_thick_function` supports only `@convention(thin)` operands.
981+
982+
sil @method : $@convention(method) (Int32) -> ()
983+
984+
sil @test_partial_apply_method : $@convention(thin) () -> @owned @callee_owned (Int32) -> () {
985+
%1 = function_ref @method : $@convention(method) (Int32) -> ()
986+
%2 = partial_apply %1() : $@convention(method) (Int32) -> ()
987+
return %2 : $@callee_owned (Int32) -> ()
988+
}
989+
990+
// CHECK-LABEL: sil @test_partial_apply_method
991+
// CHECK: [[FN:%.*]] = function_ref @method
992+
// CHECK-NEXT: partial_apply [[FN]]()
993+
// CHECK-NEXT: return

0 commit comments

Comments
 (0)