@@ -216,12 +216,12 @@ cleanupCalleeValue(SILValue CalleeValue, ArrayRef<SILValue> CaptureArgs,
216
216
// /
217
217
// / In the case that a non-null value is returned, FullArgs contains effective
218
218
// / argument operands for the callee function.
219
- static SILFunction *
220
- getCalleeFunction (FullApplySite AI, bool &IsThick,
221
- SmallVectorImpl<SILValue>& CaptureArgs,
222
- SmallVectorImpl<SILValue>& FullArgs,
223
- PartialApplyInst *&PartialApply,
224
- SILModule::LinkingMode Mode) {
219
+ static SILFunction *getCalleeFunction (SILFunction *F, FullApplySite AI,
220
+ bool &IsThick,
221
+ SmallVectorImpl<SILValue> & CaptureArgs,
222
+ SmallVectorImpl<SILValue> & FullArgs,
223
+ PartialApplyInst *&PartialApply,
224
+ SILModule::LinkingMode Mode) {
225
225
IsThick = false ;
226
226
PartialApply = nullptr ;
227
227
CaptureArgs.clear ();
@@ -276,8 +276,7 @@ getCalleeFunction(FullApplySite AI, bool &IsThick,
276
276
// We are allowed to see through exactly one "partial apply" instruction or
277
277
// one "thin to thick function" instructions, since those are the patterns
278
278
// generated when using auto closures.
279
- if (PartialApplyInst *PAI =
280
- dyn_cast<PartialApplyInst>(CalleeValue)) {
279
+ if (auto *PAI = dyn_cast<PartialApplyInst>(CalleeValue)) {
281
280
for (const auto &Arg : PAI->getArguments ()) {
282
281
CaptureArgs.push_back (Arg);
283
282
FullArgs.push_back (Arg);
@@ -286,14 +285,12 @@ getCalleeFunction(FullApplySite AI, bool &IsThick,
286
285
CalleeValue = PAI->getCallee ();
287
286
IsThick = true ;
288
287
PartialApply = PAI;
289
- } else if (ThinToThickFunctionInst *TTTFI =
290
- dyn_cast<ThinToThickFunctionInst>(CalleeValue)) {
288
+ } else if (auto *TTTFI = dyn_cast<ThinToThickFunctionInst>(CalleeValue)) {
291
289
CalleeValue = TTTFI->getOperand ();
292
290
IsThick = true ;
293
291
}
294
292
295
293
auto *FRI = dyn_cast<FunctionRefInst>(CalleeValue);
296
-
297
294
if (!FRI)
298
295
return nullptr ;
299
296
@@ -318,6 +315,22 @@ getCalleeFunction(FullApplySite AI, bool &IsThick,
318
315
if (CalleeFunction->empty ()
319
316
&& !AI.getModule ().linkFunction (CalleeFunction, Mode))
320
317
return nullptr ;
318
+
319
+ // If the CalleeFunction is a not-transparent definition, we can not process
320
+ // it.
321
+ if (CalleeFunction->isTransparent () == IsNotTransparent)
322
+ return nullptr ;
323
+
324
+ if (F->isSerialized () && !CalleeFunction->hasValidLinkageForFragileRef ()) {
325
+ if (!CalleeFunction->hasValidLinkageForFragileInline ()) {
326
+ llvm::errs () << " caller: " << F->getName () << " \n " ;
327
+ llvm::errs () << " callee: " << CalleeFunction->getName () << " \n " ;
328
+ llvm_unreachable (" Should never be inlining a resilient function into "
329
+ " a fragile function" );
330
+ }
331
+ return nullptr ;
332
+ }
333
+
321
334
return CalleeFunction;
322
335
}
323
336
@@ -407,24 +420,10 @@ runOnFunctionRecursively(SILFunction *F, FullApplySite AI,
407
420
SILValue CalleeValue = InnerAI.getCallee ();
408
421
bool IsThick;
409
422
PartialApplyInst *PAI;
410
- SILFunction *CalleeFunction = getCalleeFunction (InnerAI, IsThick,
411
- CaptureArgs, FullArgs,
412
- PAI,
413
- Mode);
414
- if (!CalleeFunction ||
415
- CalleeFunction->isTransparent () == IsNotTransparent)
416
- continue ;
417
-
418
- if (F->isSerialized () &&
419
- !CalleeFunction->hasValidLinkageForFragileRef ()) {
420
- if (!CalleeFunction->hasValidLinkageForFragileInline ()) {
421
- llvm::errs () << " caller: " << F->getName () << " \n " ;
422
- llvm::errs () << " callee: " << CalleeFunction->getName () << " \n " ;
423
- llvm_unreachable (" Should never be inlining a resilient function into "
424
- " a fragile function" );
425
- }
423
+ SILFunction *CalleeFunction = getCalleeFunction (
424
+ F, InnerAI, IsThick, CaptureArgs, FullArgs, PAI, Mode);
425
+ if (!CalleeFunction)
426
426
continue ;
427
- }
428
427
429
428
// Then recursively process it first before trying to inline it.
430
429
if (!runOnFunctionRecursively (CalleeFunction, InnerAI, Mode,
0 commit comments