Skip to content

[SR-14989] [AutoDiff] Struct genericized over differentiable type can't access that type differentiably #57331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
porterchild opened this issue Jul 30, 2021 · 2 comments
Labels
AutoDiff bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself generics Feature: generic declarations and types unexpected error Bug: Unexpected error

Comments

@porterchild
Copy link

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
    }
}
@typesanitizer
Copy link

@swift-ci create

@jkshtj
Copy link
Contributor

jkshtj commented May 3, 2024

Does not crash on 05/24 toolchain.

@AnthonyLatsis AnthonyLatsis added unexpected error Bug: Unexpected error generics Feature: generic declarations and types labels May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoDiff bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself generics Feature: generic declarations and types unexpected error Bug: Unexpected error
Projects
None yet
Development

No branches or pull requests

4 participants