@@ -1950,37 +1950,40 @@ reapplyFunctionConversion(SILValue newFunc, SILValue oldFunc,
1950
1950
for (auto *alloc : reversed (copiedIndirectParams))
1951
1951
builder.createDeallocStack (loc, alloc);
1952
1952
};
1953
- for (auto arg : pai->getArguments ()) {
1953
+ // Collect new arguments to for a new `partial_apply`.
1954
+ auto conv = pai->getSubstCalleeConv ();
1955
+ unsigned argIndex = conv.getNumSILArguments () - pai->getNumArguments ();
1956
+ for (auto argIt = pai->getArguments ().begin ();
1957
+ argIt != pai->getArguments ().end (); ++argIt, ++argIndex) {
1958
+ auto arg = *argIt;
1954
1959
// Retain the argument if it's to be owned by the newly created
1955
1960
// closure.
1956
1961
// Objects are to be retained.
1957
1962
if (arg->getType ().isObject ()) {
1958
1963
builder.createRetainValue (loc, arg, builder.getDefaultAtomicity ());
1959
1964
newArgs.push_back (arg);
1965
+ continue ;
1960
1966
}
1961
1967
// Addresses depend on argument conventions.
1962
- else {
1963
- auto conv = pai->getCalleeFunction ()->getConventions ();
1964
- auto argConv =
1965
- conv.getSILArgumentConvention (conv.getNumSILArguments () - 1 );
1966
- // If the argument is an aliasable inout reference, do not retain the
1967
- // argument since it's a `@noescape` capture.
1968
- if (argConv == SILArgumentConvention::Indirect_InoutAliasable) {
1969
- newArgs.push_back (arg);
1970
- }
1971
- // Otherwise, retain/copy the underlying value.
1972
- else if (arg->getType ().isLoadable (builder.getFunction ())) {
1973
- builder.createRetainValueAddr (loc, arg,
1974
- builder.getDefaultAtomicity ());
1975
- newArgs.push_back (arg);
1976
- } else {
1977
- auto *argCopy = builder.createAllocStack (loc, arg->getType ());
1978
- copiedIndirectParams.push_back (argCopy);
1979
- builder.createCopyAddr (loc, arg, argCopy, IsNotTake,
1980
- IsInitialization);
1981
- newArgs.push_back (argCopy);
1982
- }
1968
+ // If the argument is an aliasable inout reference, do not retain the
1969
+ // argument since it's a `@noescape` capture.
1970
+ auto argConv = conv.getSILArgumentConvention (argIndex);
1971
+ if (argConv == SILArgumentConvention::Indirect_InoutAliasable) {
1972
+ newArgs.push_back (arg);
1973
+ continue ;
1974
+ }
1975
+ // If it's a loadable address, perform a `retain_value_addr`.
1976
+ if (arg->getType ().isLoadable (builder.getFunction ())) {
1977
+ builder.createRetainValueAddr (loc, arg, builder.getDefaultAtomicity ());
1978
+ newArgs.push_back (arg);
1979
+ continue ;
1983
1980
}
1981
+ // Otherwise, it must be address-only. Create a new buffer and perform
1982
+ // `copy_addr`.
1983
+ auto *argCopy = builder.createAllocStack (loc, arg->getType ());
1984
+ copiedIndirectParams.push_back (argCopy);
1985
+ builder.createCopyAddr (loc, arg, argCopy, IsNotTake, IsInitialization);
1986
+ newArgs.push_back (argCopy);
1984
1987
}
1985
1988
auto innerNewFunc = reapplyFunctionConversion (
1986
1989
newFunc, oldFunc, pai->getCallee (), builder, loc, newFuncGenSig);
0 commit comments