@@ -767,19 +767,25 @@ void SILGenModule::postEmitFunction(SILDeclRef constant,
767
767
constant.kind != SILDeclRef::Kind::DefaultArgGenerator &&
768
768
!constant.isThunk ()) {
769
769
auto *AFD = constant.getAbstractFunctionDecl ();
770
- // Visit all `@differentiable` attributes.
771
- for (auto *diffAttr : AFD->getAttrs ().getAttributes <DifferentiableAttr>()) {
772
- SILFunction *jvp = nullptr ;
773
- SILFunction *vjp = nullptr ;
774
- if (auto *jvpDecl = diffAttr->getJVPFunction ())
775
- jvp = getFunction (SILDeclRef (jvpDecl), NotForDefinition);
776
- if (auto *vjpDecl = diffAttr->getVJPFunction ())
777
- vjp = getFunction (SILDeclRef (vjpDecl), NotForDefinition);
778
- auto *resultIndices = IndexSubset::get (getASTContext (), 1 , {0 });
779
- AutoDiffConfig config (diffAttr->getParameterIndices (), resultIndices,
780
- diffAttr->getDerivativeGenericSignature ().getPointer ());
781
- emitDifferentiabilityWitness (AFD, F, config, jvp, vjp);
782
- }
770
+ auto emitWitnesses = [&](DeclAttributes &Attrs) {
771
+ for (auto *diffAttr : Attrs.getAttributes <DifferentiableAttr>()) {
772
+ SILFunction *jvp = nullptr ;
773
+ SILFunction *vjp = nullptr ;
774
+ if (auto *jvpDecl = diffAttr->getJVPFunction ())
775
+ jvp = getFunction (SILDeclRef (jvpDecl), NotForDefinition);
776
+ if (auto *vjpDecl = diffAttr->getVJPFunction ())
777
+ vjp = getFunction (SILDeclRef (vjpDecl), NotForDefinition);
778
+ auto *resultIndices = IndexSubset::get (getASTContext (), 1 , {0 });
779
+ AutoDiffConfig config (
780
+ diffAttr->getParameterIndices (), resultIndices,
781
+ diffAttr->getDerivativeGenericSignature ().getPointer ());
782
+ emitDifferentiabilityWitness (AFD, F, config, jvp, vjp);
783
+ }
784
+ };
785
+ if (auto *accessor = dyn_cast<AccessorDecl>(AFD))
786
+ if (accessor->isGetter ())
787
+ emitWitnesses (accessor->getStorage ()->getAttrs ());
788
+ emitWitnesses (AFD->getAttrs ());
783
789
}
784
790
F->verify ();
785
791
}
@@ -817,21 +823,6 @@ void SILGenModule::emitDifferentiabilityWitness(
817
823
CanGenericSignature derivativeCanGenSig;
818
824
if (auto derivativeGenSig = config.derivativeGenericSignature )
819
825
derivativeCanGenSig = derivativeGenSig->getCanonicalSignature ();
820
- // TODO(TF-835): Use simpler derivative generic signature logic below when
821
- // type-checking no longer generates implicit `@differentiable` attributes.
822
- // See TF-835 for replacement code.
823
- if (jvp) {
824
- auto jvpCanGenSig = jvp->getLoweredFunctionType ()->getSubstGenericSignature ();
825
- if (!derivativeCanGenSig && jvpCanGenSig)
826
- derivativeCanGenSig = jvpCanGenSig;
827
- assert (derivativeCanGenSig == jvpCanGenSig);
828
- }
829
- if (vjp) {
830
- auto vjpCanGenSig = vjp->getLoweredFunctionType ()->getSubstGenericSignature ();
831
- if (!derivativeCanGenSig && vjpCanGenSig)
832
- derivativeCanGenSig = vjpCanGenSig;
833
- assert (derivativeCanGenSig == vjpCanGenSig);
834
- }
835
826
// Create new SIL differentiability witness.
836
827
// Witness JVP and VJP are set below.
837
828
// TODO(TF-919): Explore creating serialized differentiability witnesses.
0 commit comments