@@ -3573,19 +3573,22 @@ SILDeserializer::readDifferentiabilityWitness(DeclID DId) {
35733573 }
35743574 auto derivativeGenSig = MF->getGenericSignature (derivativeGenSigID);
35753575
3576+ auto originalFnType = original->getLoweredFunctionType ();
35763577 SmallVector<unsigned , 8 > parameterAndResultIndices (
35773578 rawParameterAndResultIndices.begin (), rawParameterAndResultIndices.end ());
35783579 assert (parameterAndResultIndices.size () ==
35793580 numParameterIndices + numResultIndices &&
35803581 " Parameter/result indices count mismatch" );
3581- auto *parameterIndices = IndexSubset::get (
3582- MF->getContext (), original->getLoweredFunctionType ()->getNumParameters (),
3583- ArrayRef<unsigned >(parameterAndResultIndices)
3584- .take_front (numParameterIndices));
3585- auto *resultIndices = IndexSubset::get (
3586- MF->getContext (), original->getLoweredFunctionType ()->getNumResults (),
3587- ArrayRef<unsigned >(parameterAndResultIndices)
3588- .take_back (numResultIndices));
3582+ auto *parameterIndices =
3583+ IndexSubset::get (MF->getContext (), originalFnType->getNumParameters (),
3584+ ArrayRef<unsigned >(parameterAndResultIndices)
3585+ .take_front (numParameterIndices));
3586+ auto numResults = originalFnType->getNumResults () +
3587+ originalFnType->getNumIndirectMutatingParameters ();
3588+ auto *resultIndices =
3589+ IndexSubset::get (MF->getContext (), numResults,
3590+ ArrayRef<unsigned >(parameterAndResultIndices)
3591+ .take_back (numResultIndices));
35893592
35903593 AutoDiffConfig config (parameterIndices, resultIndices, derivativeGenSig);
35913594 auto *diffWitness =
0 commit comments