-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
Description
Originally posted by @rxwei in #66873 (comment)
I think there are two angles where we need to decide:
- Whether non-wrt parameters should be treated as semantic results.
- It seems that our conclusion was "no".
- The default wrt inference behavior, i.e. the behavior when you apply
@differentiablewithout specifyingwrt:.- My current preference is to never infer wrt-ness on any
inoutargument. If the user explicitly specifieswrt:on an inout argument, we treat it as a semantic result. - Enforcing explicit wrt annotations has better clarity. We can always add inference rules in the future if there's a usability benefit, without breaking source code.
- My current preference is to never infer wrt-ness on any
@differentiable // inferred as wrt: x, semantic result: formal result (no y)
func foo(x: Float, y: inout Float) -> Float
@differentiable // error: 'String' does not conform to 'Differentiable'
func foo(x: Float, y: inout Float) -> String
@differentiable // error: function does not have a differentiable return type
// note: did you mean to differentiate wrt the inout parameter `y`?
// fixit: insert `(wrt: y)`
func foo(x: Float, y: inout Float)