-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] Fix derivative generic signature same-type requirements. #28772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
lib/Sema/TypeCheckAttr.cpp
Outdated
@@ -3816,8 +3848,20 @@ void AttributeChecker::visitDerivativeAttr(DerivativeAttr *attr) { | |||
auto vectorTy = valueResultConf.getTypeWitnessByName( | |||
valueResultType, Ctx.Id_TangentVector); | |||
|
|||
// Compute the actual differential/pullback type that we use for comparison |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// - Return the witness derivative generic signature if it exists. | ||
/// - Otherwise, return the original function's generic signature. | ||
CanGenericSignature | ||
getDerivativeGenericSignature(SILDifferentiabilityWitness *witness, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this helper is removed because the witness derivative generic signature can be used directly, now that derivative generic signatures are propagated correctly. There's no need to fallback to the original generic signature.
e51ed47
to
e298623
Compare
Will this fix |
Yes, that's exactly what's tested. |
Fix derivative generic signature calculation when same-type requirements bind all generic parameters to concrete types, i.e. when all generic parameters are concrete. Declarations whose generic signature have all concrete generic parameters are lowered as SIL functions with no generic signature: they are specialized with the concrete types from the same-type requirements. For `@differentiable` attributes: when the original generic signature and the derivative generic signature are equal and all generic parameters are concrete, do not set the attribute's derivative generic signature. Update SIL infrastructure to handle derivative generic signatures with all concrete generic parameters. In such cases: - SIL derivative function types are specialized with concrete types and have no generic signature. - SIL differentiability witnesses have a derivative generic signature iff it differs from the original generic signature. Witness generic signatures should be used for remapping types during the differentiation transform. Resolves TF-1059 and TF-1062.
e298623
to
d39eaf4
Compare
@swift-ci Please test tensorflow |
Upstream `@derivative` attribute type-checking fixes regarding derivative generic signatures with all concrete generic parameters. Cherry-picked from: - swiftlang#28762 - swiftlang#28772
Fix derivative generic signature calculation when same-type requirements bind
all generic parameters to concrete types, i.e. when all generic parameters are
concrete.
Declarations whose generic signature have all concrete generic parameters are
lowered as SIL functions with no generic signature: they are specialized with
the concrete types from the same-type requirements.
For
@differentiable
attributes: when the original generic signature and thederivative generic signature are equal and all generic parameters are concrete,
do not set the attribute's derivative generic signature.
Update SIL infrastructure to handle derivative generic signatures with all
concrete generic parameters. In such cases:
no generic signature.
differs from the original generic signature. Witness generic signatures should
be used for remapping types during the differentiation transform.
Resolves TF-1059 and TF-1062.
Exposes SR-11950: SIL parser crash for SILGen round-trip.
Examples
TF-1059
Before:
After: runs successfully.
TF-1062
Before:
After: runs successfully.