@@ -78,30 +78,6 @@ template <typename T> static inline void debugDump(T &v) {
78
78
<< v << " \n ==== END DEBUG DUMP ====\n " );
79
79
}
80
80
81
- // / Creates arguments in the entry block based on the function type.
82
- static void createEntryArguments (SILFunction *f) {
83
- auto *entry = f->getEntryBlock ();
84
- auto conv = f->getConventions ();
85
- auto &ctx = f->getASTContext ();
86
- auto moduleDecl = f->getModule ().getSwiftModule ();
87
- assert ((entry->getNumArguments () == 0 || conv.getNumSILArguments () == 0 ) &&
88
- " Entry already has arguments?!" );
89
- auto createFunctionArgument = [&](SILType type) {
90
- // Create a dummy parameter declaration.
91
- // Necessary to prevent crash during argument explosion optimization.
92
- auto loc = f->getLocation ().getSourceLoc ();
93
- auto *decl = new (ctx)
94
- ParamDecl (VarDecl::Specifier::Default, loc, loc, Identifier (), loc,
95
- Identifier (), moduleDecl);
96
- decl->setType (type.getASTType ());
97
- entry->createFunctionArgument (type, decl);
98
- };
99
- for (auto indResTy : conv.getIndirectSILResultTypes ())
100
- createFunctionArgument (f->mapTypeIntoContext (indResTy).getAddressType ());
101
- for (auto paramTy : conv.getParameterSILTypes ())
102
- createFunctionArgument (f->mapTypeIntoContext (paramTy));
103
- }
104
-
105
81
static bool isWithoutDerivative (SILValue v) {
106
82
if (auto *fnRef = dyn_cast<FunctionRefInst>(v))
107
83
return fnRef->getReferencedFunctionOrNull ()->hasSemanticsAttr (
@@ -3003,9 +2979,8 @@ class VJPEmitter final
3003
2979
original->isBare (), IsNotTransparent, original->isSerialized (),
3004
2980
original->isDynamicallyReplaceable ());
3005
2981
pullback->setOwnershipEliminated ();
3006
- pullback->setDebugScope (new (module )
3007
- SILDebugScope (original->getLocation (),
3008
- pullback));
2982
+ pullback->setDebugScope (
2983
+ new (module ) SILDebugScope (original->getLocation (), pullback));
3009
2984
return pullback;
3010
2985
}
3011
2986
@@ -3677,7 +3652,7 @@ class JVPEmitter final
3677
3652
void visitAutoDiffFunctionInst (AutoDiffFunctionInst *adfi) {
3678
3653
// Clone `autodiff_function` from original to JVP, then add the cloned
3679
3654
// instruction to the `autodiff_function` worklist.
3680
- SILClonerWithScopes ::visitAutoDiffFunctionInst (adfi);
3655
+ TypeSubstCloner ::visitAutoDiffFunctionInst (adfi);
3681
3656
auto *newADFI = cast<AutoDiffFunctionInst>(getOpValue (adfi));
3682
3657
context.getAutoDiffFunctionInsts ().push_back (newADFI);
3683
3658
}
@@ -6588,10 +6563,12 @@ SILValue ADContext::promoteToDifferentiableFunction(
6588
6563
// returned function value with an `autodiff_function` instruction,
6589
6564
// and process the `autodiff_function` instruction.
6590
6565
if (newThunk->empty ()) {
6566
+ if (auto newThunkGenSig = thunkType->getGenericSignature ())
6567
+ newThunk->setGenericEnvironment (
6568
+ newThunkGenSig->createGenericEnvironment ());
6591
6569
newThunk->setOwnershipEliminated ();
6592
- SILFunctionCloner cloner (newThunk);
6593
- cloner.cloneFunction (thunk);
6594
-
6570
+ BasicTypeSubstCloner cloner (thunk, newThunk);
6571
+ cloner.run ();
6595
6572
auto *retInst =
6596
6573
cast<ReturnInst>(newThunk->findReturnBB ()->getTerminator ());
6597
6574
SILBuilder thunkBuilder (retInst);
0 commit comments