-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] Fix @differentiable(linear)
type-checking.
#28927
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
[AutoDiff] Fix @differentiable(linear)
type-checking.
#28927
Conversation
For all non-`@noDerivative` parameter and result types, `@differentiable(linear)` function types should require and imply `T: Differentiable`, `T == T.TangentVector` requirements instead of `T: Differentiable & AdditiveArithmetic`. Update tests.
@swift-ci Please test tensorflow |
Two issues:
|
The errors are not duplicate: one's for the invalid parameter and one's for the invalid result.
This was the existing behavior. We could fix the fix-it so it appears only if at least one differentiability parameter remains after adding Edit: fixed in 642f2e4. Emit |
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.
Not adding T.TangentVector == T
was by design, but adding this constraint is okay with me. Did you encounter any concrete use cases where the absence of T.TangentVector == T
requires extra user attention?
Ah, interesting. I assumed that Do we want to consistently require Relaxing the requirement to make |
Consensus after chatting: let's consistently require |
Emit `@noDerivative` fixit only when there is at least one valid differentiability/linearity parameter. Otherwise, adding `@noDerivative` results in an ill-formed `@differentiable` function type.
@swift-ci Please test tensorflow |
For all non-
@noDerivative
parameter and result types,@differentiable(linear)
function types should require and implyT: Differentiable
,T == T.TangentVector
requirements instead ofT: Differentiable & AdditiveArithmetic
.Update tests.
Type-checking example:
Before:
After:
Inference example:
Before:
After: