You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SR-13169 Sema: lift derivative registration restriction for protocol requirements
SR-13168 SILGen: add SIL default witness table entries for default derivatives of protocol requirements
SR-13167 Parse: add parsing/syntax support for @differentiable(default, ...)
Issue Description:
Overview
Default derivative implementations enables protocol requirements (like requirements from AdditiveArithmetic, FloatingPoint, ElementaryFunctions, etc) to be differentiable by default.
// In the standard library:// public protocol AdditiveArithmetic: Equatable {// static func +(lhs: Self, rhs: Self) -> Self// ...// }extensionAdditiveArithmeticwhere Self:Differentiable{@derivative(of:+)staticfunc vjpAdd(_ lhs:Self, _ rhs:Self)->(value:Self, pullback:(TangentVector)->(TangentVector,TangentVector)){return(lhs + rhs,{ v in(v, v)})}}
This is important for idiomatic protocol-oriented programming to avoid tons of code duplication. Without this feature, all conforming types of the protocol must:
Define a @differentiable concrete implementation of the original protocol requirement, if none already exists (because a default implementation was used.)
Register a derivative function for the concrete implementation.
Supporting this may require lifting the current restriction that "all implementations of @differentiable protocol requirements must themselves be marked as @differentiable":
Additional Detail from JIRA
md5: b0201d55480662f7a4792a7ddd4694d2
Sub-Tasks:
@differentiable(default, ...)
Issue Description:
Overview
Default derivative implementations enables protocol requirements (like requirements from
AdditiveArithmetic
,FloatingPoint
,ElementaryFunctions
, etc) to be differentiable by default.See "default derivatives and transposes" from the Differentiable Programming Manifesto for more info.
Example:
This is important for idiomatic protocol-oriented programming to avoid tons of code duplication. Without this feature, all conforming types of the protocol must:
Define a
@differentiable
concrete implementation of the original protocol requirement, if none already exists (because a default implementation was used.)Register a derivative function for the concrete implementation.
Details
There are two cases to consider:
1. Non-
@differentiable
protocol requirement.2.
@differentiable
protocol requirement.Supporting this may require lifting the current restriction that "all implementations of
@differentiable
protocol requirements must themselves be marked as@differentiable
":SIL default witness table support may be needed.
The text was updated successfully, but these errors were encountered: