@@ -1187,28 +1187,16 @@ static bool shouldDestroyPartialApplyCapturedArg(SILValue arg,
1187
1187
return true ;
1188
1188
}
1189
1189
1190
- // *HEY YOU, YES YOU, PLEASE READ*. Even though a textual partial apply is
1191
- // printed with the convention of the closed over function upon it, all
1192
- // non-inout arguments to a partial_apply are passed at +1. This includes
1193
- // arguments that will eventually be passed as guaranteed or in_guaranteed to
1194
- // the closed over function. This is because the partial apply is building up a
1195
- // boxed aggregate to send off to the closed over function. Of course when you
1196
- // call the function, the proper conventions will be used.
1197
- void swift::releasePartialApplyCapturedArg (SILBuilder &builder, SILLocation loc,
1198
- SILValue arg,
1199
- SILParameterInfo paramInfo,
1200
- InstModCallbacks callbacks) {
1201
- if (!shouldDestroyPartialApplyCapturedArg (arg, paramInfo,
1202
- builder.getFunction ()))
1203
- return ;
1204
-
1205
- // Otherwise, we need to destroy the argument. If we have an address, we
1206
- // insert a destroy_addr and return. Any live range issues must have been
1207
- // dealt with by our caller.
1208
- if (arg->getType ().isAddress ()) {
1209
- // Then emit the destroy_addr for this arg
1210
- SILInstruction *newInst = builder.emitDestroyAddrAndFold (loc, arg);
1211
- callbacks.createdNewInst (newInst);
1190
+ void swift::emitDestroyOperation (SILBuilder &builder, SILLocation loc,
1191
+ SILValue operand, InstModCallbacks callbacks) {
1192
+ // If we have an address, we insert a destroy_addr and return. Any live range
1193
+ // issues must have been dealt with by our caller.
1194
+ if (operand->getType ().isAddress ()) {
1195
+ // Then emit the destroy_addr for this operand. This function does not
1196
+ // delete any instructions
1197
+ SILInstruction *newInst = builder.emitDestroyAddrAndFold (loc, operand);
1198
+ if (newInst != nullptr )
1199
+ callbacks.createdNewInst (newInst);
1212
1200
return ;
1213
1201
}
1214
1202
@@ -1217,12 +1205,12 @@ void swift::releasePartialApplyCapturedArg(SILBuilder &builder, SILLocation loc,
1217
1205
1218
1206
// If we have qualified ownership, we should just emit a destroy value.
1219
1207
if (builder.getFunction ().hasOwnership ()) {
1220
- callbacks.createdNewInst (builder.createDestroyValue (loc, arg ));
1208
+ callbacks.createdNewInst (builder.createDestroyValue (loc, operand ));
1221
1209
return ;
1222
1210
}
1223
1211
1224
- if (arg ->getType ().hasReferenceSemantics ()) {
1225
- auto u = builder.emitStrongRelease (loc, arg );
1212
+ if (operand ->getType ().hasReferenceSemantics ()) {
1213
+ auto u = builder.emitStrongRelease (loc, operand );
1226
1214
if (u.isNull ())
1227
1215
return ;
1228
1216
@@ -1235,7 +1223,7 @@ void swift::releasePartialApplyCapturedArg(SILBuilder &builder, SILLocation loc,
1235
1223
return ;
1236
1224
}
1237
1225
1238
- auto u = builder.emitReleaseValue (loc, arg );
1226
+ auto u = builder.emitReleaseValue (loc, operand );
1239
1227
if (u.isNull ())
1240
1228
return ;
1241
1229
@@ -1247,6 +1235,24 @@ void swift::releasePartialApplyCapturedArg(SILBuilder &builder, SILLocation loc,
1247
1235
callbacks.createdNewInst (u.get <ReleaseValueInst *>());
1248
1236
}
1249
1237
1238
+ // *HEY YOU, YES YOU, PLEASE READ*. Even though a textual partial apply is
1239
+ // printed with the convention of the closed over function upon it, all
1240
+ // non-inout arguments to a partial_apply are passed at +1. This includes
1241
+ // arguments that will eventually be passed as guaranteed or in_guaranteed to
1242
+ // the closed over function. This is because the partial apply is building up a
1243
+ // boxed aggregate to send off to the closed over function. Of course when you
1244
+ // call the function, the proper conventions will be used.
1245
+ void swift::releasePartialApplyCapturedArg (SILBuilder &builder, SILLocation loc,
1246
+ SILValue arg,
1247
+ SILParameterInfo paramInfo,
1248
+ InstModCallbacks callbacks) {
1249
+ if (!shouldDestroyPartialApplyCapturedArg (arg, paramInfo,
1250
+ builder.getFunction ()))
1251
+ return ;
1252
+
1253
+ emitDestroyOperation (builder, loc, arg, callbacks);
1254
+ }
1255
+
1250
1256
void swift::deallocPartialApplyCapturedArg (SILBuilder &builder, SILLocation loc,
1251
1257
SILValue arg,
1252
1258
SILParameterInfo paramInfo) {
@@ -1415,11 +1421,7 @@ bool swift::tryDeleteDeadClosure(SingleValueInstruction *closure,
1415
1421
for (Operand *argOp : argsToHandle) {
1416
1422
SILValue arg = argOp->get ();
1417
1423
SILBuilderWithScope builder (pai, builderCtxt);
1418
- if (arg->getType ().isObject ()) {
1419
- builder.emitDestroyValueOperation (pai->getLoc (), arg);
1420
- } else {
1421
- builder.emitDestroyAddr (pai->getLoc (), arg);
1422
- }
1424
+ emitDestroyOperation (builder, pai->getLoc (), arg, callbacks);
1423
1425
}
1424
1426
}
1425
1427
}
0 commit comments