When I try to register a derivative for a function that rethrows with a derivative that also rethrows, the type checker is unable to match the expected candidate.
Failure:
The nil-coalescing operator ?? needs a derivative in order to be differentiable. Defining the following derivative will show that the type checker has disregarded the rethrowing-ness of the derivative function, causing it to think that no candidate original functions match.
/home/rxwei/Development/Swift/swift-source/swift/stdlib/public/Differentiation/OptionalDifferentiation.swift:85:17: error: referenced declaration '??' could not be resolved
@derivative(of: ??, wrt: optional)
^
Swift.??:1:13: note: candidate operator function does not have type equal to or less constrained than '<T where T : Differentiable> (optional: T?, defaultValue: @autoclosure () throws -> T) -> T?'
public func ?? <T>(optional: T?, defaultValue: @autoclosure () throws -> T) rethrows -> T
^
Swift.??:1:13: note: candidate operator function does not have type equal to or less constrained than '<T where T : Differentiable> (optional: T?, defaultValue: @autoclosure () throws -> T) -> T?'
public func ?? <T>(optional: T?, defaultValue: @autoclosure () throws -> T?) rethrows -> T?
^
For context, unlike rethrowing functions, throwing functions are okay:
Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, AutoDiff | |Assignee | None | |Priority | Medium | md5: dd36f68f8af4408fe46600b0524f8839blocks:
??
is not differentiableIssue Description:
When I try to register a derivative for a function that rethrows with a derivative that also rethrows, the type checker is unable to match the expected candidate.
Failure:
The nil-coalescing operator
??
needs a derivative in order to be differentiable. Defining the following derivative will show that the type checker has disregarded the rethrowing-ness of the derivative function, causing it to think that no candidate original functions match.For context, unlike rethrowing functions, throwing functions are okay: