@@ -1305,27 +1305,6 @@ bool SILCombiner::optimizeIdentityCastComposition(ApplyInst *FInverse,
1305
1305
return true ;
1306
1306
}
1307
1307
1308
- // Return a new apply with the specified callee. This creates a new apply rather
1309
- // than simply rewriting the callee operand because the apply's SubstCalleeType,
1310
- // derived from the callee and substitution list, may change.
1311
- FullApplySite SILCombiner::rewriteApplyCallee (FullApplySite apply,
1312
- SILValue callee) {
1313
- SmallVector<SILValue, 4 > arguments;
1314
- for (SILValue arg : apply.getArguments ())
1315
- arguments.push_back (arg);
1316
-
1317
- Builder.addOpenedArchetypeOperands (apply.getInstruction ());
1318
- if (auto *TAI = dyn_cast<TryApplyInst>(apply)) {
1319
- return Builder.createTryApply (TAI->getLoc (), callee,
1320
- TAI->getSubstitutions (), arguments,
1321
- TAI->getNormalBB (), TAI->getErrorBB ());
1322
- } else {
1323
- return Builder.createApply (apply.getLoc (), callee, apply.getSubstitutions (),
1324
- arguments,
1325
- cast<ApplyInst>(apply)->isNonThrowing ());
1326
- }
1327
- }
1328
-
1329
1308
SILInstruction *SILCombiner::visitApplyInst (ApplyInst *AI) {
1330
1309
Builder.setCurrentDebugScope (AI->getDebugScope ());
1331
1310
// apply{partial_apply(x,y)}(z) -> apply(z,x,y) is triggered
@@ -1367,11 +1346,20 @@ SILInstruction *SILCombiner::visitApplyInst(ApplyInst *AI) {
1367
1346
1368
1347
// (apply (thin_to_thick_function f)) to (apply f)
1369
1348
if (auto *TTTFI = dyn_cast<ThinToThickFunctionInst>(AI->getCallee ())) {
1370
- // We currently don't remove any possible retain associated with the thick
1371
- // function when rewriting the callsite. This should be ok because the
1372
- // ABI normally expects a guaranteed callee.
1373
- if (!AI->getOrigCalleeType ()->isCalleeConsumed ())
1374
- return rewriteApplyCallee (AI, TTTFI->getOperand ()).getInstruction ();
1349
+ // TODO: Handle substitutions and indirect results
1350
+ if (AI->hasSubstitutions () || AI->hasIndirectResults ())
1351
+ return nullptr ;
1352
+ SmallVector<SILValue, 4 > Arguments;
1353
+ for (auto &Op : AI->getArgumentOperands ()) {
1354
+ Arguments.push_back (Op.get ());
1355
+ }
1356
+ // The type of the substitution is the source type of the thin to thick
1357
+ // instruction.
1358
+ Builder.addOpenedArchetypeOperands (AI);
1359
+ auto *NewAI = Builder.createApply (AI->getLoc (), TTTFI->getOperand (),
1360
+ AI->getSubstitutions (), Arguments,
1361
+ AI->isNonThrowing ());
1362
+ return NewAI;
1375
1363
}
1376
1364
1377
1365
// (apply (witness_method)) -> propagate information about
@@ -1489,12 +1477,21 @@ SILInstruction *SILCombiner::visitTryApplyInst(TryApplyInst *AI) {
1489
1477
1490
1478
// (try_apply (thin_to_thick_function f)) to (try_apply f)
1491
1479
if (auto *TTTFI = dyn_cast<ThinToThickFunctionInst>(AI->getCallee ())) {
1492
- // We currently don't remove any possible retain associated with the thick
1493
- // function when rewriting the callsite. This should be ok because the
1494
- // ABI normally expects a guaranteed callee.
1495
- if (!AI->getOrigCalleeType ()->isCalleeConsumed ())
1496
- return rewriteApplyCallee (AI, TTTFI->getOperand ()).getInstruction ();
1480
+ // TODO: Handle substitutions and indirect results
1481
+ if (AI->hasSubstitutions () || AI->hasIndirectResults ())
1482
+ return nullptr ;
1483
+ SmallVector<SILValue, 4 > Arguments;
1484
+ for (auto &Op : AI->getArgumentOperands ()) {
1485
+ Arguments.push_back (Op.get ());
1486
+ }
1487
+ // The type of the substitution is the source type of the thin to thick
1488
+ // instruction.
1489
+ auto *NewAI = Builder.createTryApply (AI->getLoc (), TTTFI->getOperand (),
1490
+ AI->getSubstitutions (), Arguments,
1491
+ AI->getNormalBB (), AI->getErrorBB ());
1492
+ return NewAI;
1497
1493
}
1494
+
1498
1495
// (apply (witness_method)) -> propagate information about
1499
1496
// a concrete type from init_existential_addr or init_existential_ref.
1500
1497
if (auto *WMI = dyn_cast<WitnessMethodInst>(AI->getCallee ())) {
0 commit comments