@@ -294,6 +294,9 @@ combineMemoryBehavior(SILInstruction::MemoryBehavior B1,
294
294
// / Pretty-print the MemoryBehavior.
295
295
llvm::raw_ostream &operator <<(llvm::raw_ostream &OS,
296
296
SILInstruction::MemoryBehavior B);
297
+ // / Pretty-print the ReleasingBehavior.
298
+ llvm::raw_ostream &operator <<(llvm::raw_ostream &OS,
299
+ SILInstruction::ReleasingBehavior B);
297
300
#endif
298
301
299
302
// / A template base class for instructions that take a single SILValue operand
@@ -680,11 +683,19 @@ class ApplyInstBase<Impl, Base, false> : public Base {
680
683
681
684
SILValue getCallee () const { return Operands[Callee].get (); }
682
685
686
+ // / Gets the referenced function by looking through partial apply,
687
+ // / convert_function, and thin to thick function until we find a function_ref.
688
+ // /
689
+ // / This is defined out of line to work around incomplete definition
690
+ // / issues. It is at the bottom of the file.
691
+ SILFunction *getCalleeFunction () const ;
692
+
683
693
// / Gets the referenced function if the callee is a function_ref instruction.
684
- SILFunction *getCalleeFunction () const {
685
- if (auto *FRI = dyn_cast<FunctionRefInst>(getCallee ()))
686
- return FRI->getReferencedFunction ();
687
- return nullptr ;
694
+ SILFunction *getReferencedFunction () const {
695
+ auto *FRI = dyn_cast<FunctionRefInst>(getCallee ());
696
+ if (!FRI)
697
+ return nullptr ;
698
+ return FRI->getReferencedFunction ();
688
699
}
689
700
690
701
// / Get the type of the callee without the applied substitutions.
@@ -4354,12 +4365,18 @@ class ApplySite {
4354
4365
FOREACH_IMPL_RETURN (getCallee ());
4355
4366
}
4356
4367
4357
- // / Return the referenced function if the callee is a function_ref
4358
- // / instruction .
4368
+ // / Gets the referenced function by looking through partial apply,
4369
+ // / convert_function, and thin to thick function until we find a function_ref .
4359
4370
SILFunction *getCalleeFunction () const {
4360
4371
FOREACH_IMPL_RETURN (getCalleeFunction ());
4361
4372
}
4362
4373
4374
+ // / Return the referenced function if the callee is a function_ref
4375
+ // / instruction.
4376
+ SILFunction *getReferencedFunction () const {
4377
+ FOREACH_IMPL_RETURN (getReferencedFunction ());
4378
+ }
4379
+
4363
4380
// / Return the type.
4364
4381
SILType getType () const {
4365
4382
FOREACH_IMPL_RETURN (getSubstCalleeType ()->getSILResult ());
@@ -4552,6 +4569,32 @@ class FullApplySite : public ApplySite {
4552
4569
}
4553
4570
};
4554
4571
4572
+ // This is defined out of line to work around the fact that this depends on
4573
+ // PartialApplyInst being defined, but PartialApplyInst is a subclass of
4574
+ // ApplyInstBase, so we can not place ApplyInstBase after it.
4575
+ template <class Impl , class Base >
4576
+ SILFunction *ApplyInstBase<Impl, Base, false >::getCalleeFunction() const {
4577
+ SILValue Callee = getCallee ();
4578
+
4579
+ while (true ) {
4580
+ if (auto *FRI = dyn_cast<FunctionRefInst>(Callee)) {
4581
+ return FRI->getReferencedFunction ();
4582
+ }
4583
+
4584
+ if (auto *PAI = dyn_cast<PartialApplyInst>(Callee)) {
4585
+ Callee = PAI->getCallee ();
4586
+ continue ;
4587
+ }
4588
+
4589
+ if (auto *TTTFI = dyn_cast<ThinToThickFunctionInst>(Callee)) {
4590
+ Callee = TTTFI->getCallee ();
4591
+ continue ;
4592
+ }
4593
+
4594
+ return nullptr ;
4595
+ }
4596
+ }
4597
+
4555
4598
} // end swift namespace
4556
4599
4557
4600
// ===----------------------------------------------------------------------===//
0 commit comments