mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
In #58965, lookup for custom derivatives in non-primary source files was introduced. It required triggering delayed members parsing of nominal types in a file if the file was compiled with differential programming enabled. This patch introduces `CustomDerivativesRequest` to address the issue. We only parse delayed members if tokens `@` and `derivative` appear together inside skipped nominal type body (similar to how member operators are handled). Resolves #60102
67 lines
1.5 KiB
Swift
67 lines
1.5 KiB
Swift
import _Differentiation
|
|
|
|
protocol Protocol: Differentiable {
|
|
// Test cross-file `@differentiable` attribute.
|
|
@differentiable(reverse, wrt: self)
|
|
func identityDifferentiableAttr() -> Self
|
|
|
|
// Test `@differentiable` propagation from storage declaration to accessors.
|
|
@differentiable(reverse)
|
|
var property: Float { get set }
|
|
|
|
// Test `@differentiable` propagation from storage declaration to accessors.
|
|
@differentiable(reverse)
|
|
subscript() -> Float { get set }
|
|
}
|
|
|
|
extension Protocol {
|
|
func identityDerivativeAttr() -> Self { self }
|
|
|
|
// Test cross-file `@derivative` attribute.
|
|
@derivative(of: identityDerivativeAttr)
|
|
func vjpIdentityDerivativeAttr() -> (
|
|
value: Self, pullback: (TangentVector) -> TangentVector
|
|
) {
|
|
fatalError()
|
|
}
|
|
}
|
|
|
|
struct Struct: Differentiable {
|
|
func identityDerivativeAttr() -> Self { self }
|
|
|
|
// Test cross-file `@derivative` attribute.
|
|
@derivative(of: identityDerivativeAttr)
|
|
func vjpIdentityDerivativeAttr() -> (
|
|
value: Self, pullback: (TangentVector) -> TangentVector
|
|
) {
|
|
fatalError()
|
|
}
|
|
}
|
|
|
|
class Class: Differentiable {
|
|
// Test `@differentiable` propagation from storage declaration to accessors.
|
|
@differentiable(reverse)
|
|
var property: Float {
|
|
get { 1 }
|
|
set {}
|
|
}
|
|
|
|
// Test `@differentiable` propagation from storage declaration to accessors.
|
|
@differentiable(reverse)
|
|
subscript() -> Float {
|
|
get { 1 }
|
|
set {}
|
|
}
|
|
}
|
|
|
|
struct S: Differentiable {
|
|
var value: Float
|
|
}
|
|
|
|
extension Array where Element == S {
|
|
@differentiable(reverse)
|
|
func sum() -> Float {
|
|
return 0
|
|
}
|
|
}
|