-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] Improve @derivative
attribute diagnostics.
#29918
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2972,18 +2972,18 @@ NOTE(protocol_witness_missing_differentiable_attr,none, | |
// @derivative | ||
ERROR(derivative_attr_expected_result_tuple,none, | ||
"'@derivative(of:)' attribute requires function to return a two-element " | ||
"tuple of type '(value: T..., pullback: (U.TangentVector) -> T.TangentVector...)' " | ||
"or '(value: T..., differential: (T.TangentVector...) -> U.TangentVector)'", ()) | ||
"tuple; first element must have label 'value:' and second element must " | ||
"have label 'pullback:' or 'differential:'", ()) | ||
ERROR(derivative_attr_invalid_result_tuple_value_label,none, | ||
"'@derivative(of:)' attribute requires function to return a two-element " | ||
"tuple (first element must have label 'value:')", ()) | ||
"tuple; first element must have label 'value:'", ()) | ||
ERROR(derivative_attr_invalid_result_tuple_func_label,none, | ||
"'@derivative(of:)' attribute requires function to return a two-element " | ||
"tuple (second element must have label 'pullback:' or 'differential:')", | ||
"tuple; second element must have label 'pullback:' or 'differential:'", | ||
()) | ||
ERROR(derivative_attr_result_value_not_differentiable,none, | ||
"'@derivative(of:)' attribute requires function to return a two-element " | ||
"tuple (first element type %0 must conform to 'Differentiable')", (Type)) | ||
"tuple; first element type %0 must conform to 'Differentiable'", (Type)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why's "conform to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That would be ideal. However, for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, but I feel the "must conform to
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand your point. I pushed some further diagnostics improvements along this direction. Now, original function lookup occurs before the "does first element type conform to Example: import _Differentiation
@derivative(of: nonexistentFunction)
func derivative(_ x: Float) -> (value: Int, pullback: (Float) -> Float) {
fatalError()
} Before: unideal diagnostic about
After: ideal diagnostic about original function not found.
Example: import _Differentiation
func original(_ x: Int) -> Int { x }
@derivative(of: original)
func vjpOriginalFunctionNotFound2(_ x: Float) -> (value: Int, pullback: (Float) -> Float) {
fatalError()
} Before: unideal diagnostic about
After: ideal diagnostic about original function not found.
Let me know if these changes make sense, and if you'd like further changes! I'd like to defer major diagnostic changes until later to unblock progress. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very nice! |
||
ERROR(derivative_attr_result_func_type_mismatch,none, | ||
"function result's %0 type does not match %1", (Identifier, DeclName)) | ||
NOTE(derivative_attr_result_func_type_mismatch_note,none, | ||
|
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:
derivative_attr_expected_result_tuple
(1) is somewhat duplicated byderivative_attr_invalid_result_tuple_value_label
(2) andderivative_attr_invalid_result_tuple_func_label
(3).(1) is produced when the
@derivative
function type doesn't return a two-element tuple. (2) and (3) are produced when the returned two-element tuple's labels are incorrect.Unless someone has suggestions, I'm content to leave (2) and (3) as is, since they're more specific than (1).