swift
swift copied to clipboard
[SR-14989] [AutoDiff] Struct genericized over differentiable type can't access that type differentiably
| Previous ID | SR-14989 |
| Radar | rdar://problem/81347317 |
| Original Reporter | @porterchild |
| Type | Bug |
Environment
7/7 snapshot
Additional Detail from JIRA
| Votes | 1 |
| Component/s | Compiler |
| Labels | Bug, AutoDiff |
| Assignee | [email protected] (JIRA) |
| Priority | Medium |
md5: f5d010cdf3f202bb1c50f71d8f3ee6b4
Issue Description:
Even though the P protocol has declared that 'var a' is differentiable, using it below fails:
import Foundation
import _Differentiation
protocol P: Differentiable {
@differentiable(reverse)
var a: Double {get set}
}
struct S: P {
var a: Double = 3
}
// this works when something concrete is held, setA is differentiable
//struct Holder: Differentiable {
// var p: S
//
// @differentiable(reverse)
// mutating func setA(a: Double) {
// self.p.a = a
// }
//}
// this doesn't work, after genericizing the Holder,
struct Holder<ConcreteP: P>: Differentiable {
var p: ConcreteP
@differentiable(reverse)
mutating func setA(a: Double) {
self.p.a = a // "Expression is not differentiable" at line 'self.p.a = a' even though P.a has been marked @differentiable
}
}
@swift-ci create
Does not crash on 05/24 toolchain.