-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Previous ID | SR-13168 |
Radar | rdar://problem/69987700 |
Original Reporter | @dan-zheng |
Type | Sub-task |
Additional Detail from JIRA
Votes | 0 |
Component/s | Compiler |
Labels | Sub-task |
Assignee | None |
Priority | Medium |
md5: 06cd5fd689baa87628f642979fcf9761
Parent-Task:
- SR-13166 Default derivative implementations for protocol requirements
Issue Description:
Resilient protocol default implementations are encoded in SIL default witness tables: https://github.com/apple/swift/blob/master/docs/SIL.rst#default-witness-tables.
Derivatives registered for protocol requirements should be lowered to entries in SIL default witness tables. SILDeclRef already has support for derivative functions (via SILDeclRef::derivativeFunctionIdentifier
).
protocol P {
static func +(lhs: Self, rhs: Self) -> Self
}
extension P where Self: Differentiable {
@derivative(of: add)
static func vjpAdd(lhs: Self, rhs: Self) -> (value: Self, pullback: (TangentVector) -> (TangentVector, TangentVector)) {
return (lhs + rhs, { v in (v, v) }
}
}
The default derivative P.vjpAdd
should appear in a default witness table for P
.
You can start implementing this by:
-
Finding existing SILGen logic for generating default witness tables. Add logic that finds derivatives registered for protocol requirements (
@derivative
) and emits default witness table entries for those derivatives. -
You can test generated default witness tables via
swiftc -emit-silgen
.