Skip to content

Commit 6713168

Browse files
authored
Merge pull request swiftlang#83947 from eeckstein/fix-combine-apply-of-convertfunction-6.2
[6.2] SILCombine: fix `convert_function` -> `apply` peephole for generic function types
2 parents 90e599b + bf3a05b commit 6713168

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,18 @@ SILCombiner::optimizeApplyOfConvertFunctionInst(FullApplySite AI,
172172
auto oldOpParamTypes = substConventions.getParameterSILTypes(context);
173173
auto newOpParamTypes = convertConventions.getParameterSILTypes(context);
174174

175+
// Currently we cannot deal with generic arguments/returns. Bail in this case.
176+
for (auto newRetTy : newOpRetTypes) {
177+
if (newRetTy.hasTypeParameter())
178+
return nullptr;
179+
}
180+
for (auto newParamTy : newOpParamTypes) {
181+
if (newParamTy.hasTypeParameter())
182+
return nullptr;
183+
}
184+
if (newIndirectErrorResultType && newIndirectErrorResultType.hasTypeParameter())
185+
return nullptr;
186+
175187
llvm::SmallVector<SILValue, 8> Args;
176188
llvm::SmallVector<BeginBorrowInst *, 8> Borrows;
177189
auto convertOp = [&](SILValue Op, SILType OldOpType, SILType NewOpType,

test/SILOptimizer/sil_combine_apply.sil

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,24 @@ bb0:
583583
return %return : $()
584584
}
585585

586+
class GenC<T> {
587+
}
588+
589+
sil @takeGenC : $@convention(thin) <τ_0_0> (@owned GenC<τ_0_0>) -> ()
590+
591+
// CHECK-LABEL: sil [ossa] @convert_function_with_generic_arg :
592+
// CHECK: [[C:%.*]] = convert_function
593+
// CHECK: apply [[C]]
594+
// CHECK: } // end sil function 'convert_function_with_generic_arg'
595+
sil [ossa] @convert_function_with_generic_arg : $@convention(thin) (@owned AnyObject) -> () {
596+
bb0(%0 : @owned $AnyObject):
597+
%2 = function_ref @takeGenC : $@convention(thin) <τ_0_0> (@owned GenC<τ_0_0>) -> ()
598+
%9 = convert_function %2 to $@convention(thin) (@owned AnyObject) -> ()
599+
%30 = apply %9(%0) : $@convention(thin) (@owned AnyObject) -> ()
600+
%r = tuple ()
601+
return %r
602+
}
603+
586604
sil shared [transparent] [thunk] @genericClosure : $@convention(thin) <T> (@in T) -> @out T {
587605
bb0(%0 : $*T, %1 : $*T):
588606
%12 = tuple ()

0 commit comments

Comments
 (0)