@@ -1187,28 +1187,16 @@ static bool shouldDestroyPartialApplyCapturedArg(SILValue arg,
11871187 return true ;
11881188}
11891189
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);
12121200 return ;
12131201 }
12141202
@@ -1217,12 +1205,12 @@ void swift::releasePartialApplyCapturedArg(SILBuilder &builder, SILLocation loc,
12171205
12181206 // If we have qualified ownership, we should just emit a destroy value.
12191207 if (builder.getFunction ().hasOwnership ()) {
1220- callbacks.createdNewInst (builder.createDestroyValue (loc, arg ));
1208+ callbacks.createdNewInst (builder.createDestroyValue (loc, operand ));
12211209 return ;
12221210 }
12231211
1224- if (arg ->getType ().hasReferenceSemantics ()) {
1225- auto u = builder.emitStrongRelease (loc, arg );
1212+ if (operand ->getType ().hasReferenceSemantics ()) {
1213+ auto u = builder.emitStrongRelease (loc, operand );
12261214 if (u.isNull ())
12271215 return ;
12281216
@@ -1235,7 +1223,7 @@ void swift::releasePartialApplyCapturedArg(SILBuilder &builder, SILLocation loc,
12351223 return ;
12361224 }
12371225
1238- auto u = builder.emitReleaseValue (loc, arg );
1226+ auto u = builder.emitReleaseValue (loc, operand );
12391227 if (u.isNull ())
12401228 return ;
12411229
@@ -1247,6 +1235,24 @@ void swift::releasePartialApplyCapturedArg(SILBuilder &builder, SILLocation loc,
12471235 callbacks.createdNewInst (u.get <ReleaseValueInst *>());
12481236}
12491237
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+
12501256void swift::deallocPartialApplyCapturedArg (SILBuilder &builder, SILLocation loc,
12511257 SILValue arg,
12521258 SILParameterInfo paramInfo) {
@@ -1415,11 +1421,7 @@ bool swift::tryDeleteDeadClosure(SingleValueInstruction *closure,
14151421 for (Operand *argOp : argsToHandle) {
14161422 SILValue arg = argOp->get ();
14171423 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);
14231425 }
14241426 }
14251427 }
0 commit comments