@@ -1425,19 +1425,19 @@ class DifferentiableActivityInfo {
1425
1425
// / The original function.
1426
1426
SILFunction &getFunction ();
1427
1427
1428
- // / The conformance lookup function .
1429
- // FIXME(TF-945): `LookupConformanceFn` is a type alias for
1430
- // `llvm::function_ref`, which does not own the underlying callable and should
1431
- // not be stored. Instead, delete `getLookupConformanceFunction()` and define
1432
- // a `hasTangentSpace(SILValue)` helper.
1433
- LookupConformanceFn getLookupConformanceFunction () {
1434
- // Look up in derivative generic signature, if defined.
1435
- if (derivativeGenericSignature)
1436
- return LookUpConformanceInSignature (
1437
- derivativeGenericSignature. getPointer ());
1438
- // Otherwise, look up in the module.
1439
- return LookUpConformanceInModule (
1440
- getFunction (). getModule (). getSwiftModule () );
1428
+ // / Returns true if the given SILValue has a tangent space .
1429
+ bool hasTangentSpace (SILValue value) {
1430
+ auto type = value-> getType (). getASTType ();
1431
+ // Remap archetypes in the derivative generic signature, if it exists.
1432
+ if (derivativeGenericSignature && type-> hasArchetype ()) {
1433
+ type = derivativeGenericSignature-> getCanonicalTypeInContext (
1434
+ type-> mapTypeOutOfContext ());
1435
+ }
1436
+ // Look up conformance in the current module.
1437
+ auto lookupConformance =
1438
+ LookUpConformanceInModule ( getFunction (). getModule (). getSwiftModule ());
1439
+ return type-> getAutoDiffAssociatedTangentSpace (
1440
+ lookupConformance). hasValue ( );
1441
1441
}
1442
1442
1443
1443
// / Perform analysis and populate variedness and usefulness sets.
@@ -2003,12 +2003,7 @@ void DifferentiableActivityInfo::propagateVaried(
2003
2003
if (isVaried (teai->getOperand (), i)) {
2004
2004
// Propagate variedness only if the `tuple_element_addr` result has a
2005
2005
// tangent space. Otherwise, the result does not need a derivative.
2006
- auto projType = teai->getType ().getASTType ();
2007
- if (derivativeGenericSignature && projType->hasArchetype ())
2008
- projType = derivativeGenericSignature->getCanonicalTypeInContext (
2009
- projType->mapTypeOutOfContext ());
2010
- if (projType->getAutoDiffAssociatedTangentSpace (
2011
- getLookupConformanceFunction ()))
2006
+ if (hasTangentSpace (teai))
2012
2007
setVariedAndPropagateToUsers (teai, i);
2013
2008
}
2014
2009
}
0 commit comments