@@ -231,10 +231,7 @@ class VJPCloner::Implementation final
231231 extractAllElements (origResult, Builder, origResults);
232232
233233 // Get and partially apply the pullback.
234- auto vjpGenericEnv = vjp->getGenericEnvironment ();
235- auto vjpSubstMap = vjpGenericEnv
236- ? vjpGenericEnv->getForwardingSubstitutionMap ()
237- : vjp->getForwardingSubstitutionMap ();
234+ auto vjpSubstMap = vjp->getForwardingSubstitutionMap ();
238235 auto *pullbackRef = Builder.createFunctionRef (loc, pullback);
239236
240237 // Prepare partial application arguments.
@@ -257,13 +254,10 @@ class VJPCloner::Implementation final
257254 auto *pullbackPartialApply = Builder.createPartialApply (
258255 loc, pullbackRef, vjpSubstMap, {partialApplyArg},
259256 ParameterConvention::Direct_Guaranteed);
260- auto pullbackType = vjp->getLoweredFunctionType ()
261- ->getResults ()
262- .back ()
263- .getSILStorageInterfaceType ();
264- pullbackType = pullbackType.substGenericArgs (
265- getModule (), vjpSubstMap, TypeExpansionContext::minimal ());
266- pullbackType = pullbackType.subst (getModule (), vjpSubstMap);
257+ auto pullbackType = vjp->mapTypeIntoContext (
258+ vjp->getConventions ().getSILType (
259+ vjp->getLoweredFunctionType ()->getResults ().back (),
260+ vjp->getTypeExpansionContext ()));
267261 auto pullbackFnType = pullbackType.castTo <SILFunctionType>();
268262 auto pullbackSubstType =
269263 pullbackPartialApply->getType ().castTo <SILFunctionType>();
0 commit comments