Files
swift-mirror/test/AutoDiff/SILOptimizer/Inputs/differentiation_diagnostics_other_file.swift
Daniil Kovalev 0d7e37e4ec [AutoDiff] Enhance performance of custom derivatives lookup
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
2024-10-29 12:45:14 +03:00

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
}
}