File: differentiation_diagnostics_cross_file.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (61 lines) | stat: -rw-r--r-- 1,867 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// RUN: %target-swift-frontend -emit-sil -verify -primary-file %s %S/Inputs/differentiation_diagnostics_other_file.swift -module-name main -o /dev/null

// Test differentiation transform cross-file diagnostics.

import _Differentiation

// TF-1271: Test `@differentiable` original function in other file.
@differentiable(reverse)
func crossFileDifferentiableAttr<T: Protocol>(
  _ input: T
) -> T {
  return input.identityDifferentiableAttr()
}

// TF-1272: Test original function with registered derivatives in other files.
@differentiable(reverse)
func crossFileDerivativeAttr<T: Protocol>(
  _ input: T
) -> T {
  // No error expected
  return input.identityDerivativeAttr()
}

// TF-1234: Test `@differentiable` propagation from protocol requirement storage
// declarations to their accessors in other file.
@differentiable(reverse)
func protocolRequirementGetters<T: Protocol>(_ x: T) -> Float {
  // No error expected
  x.property + x[]
}

// TF-1184: Make `@differentiable` on storage declarations propagate to
// the setter in addition to the getter.
@differentiable(reverse)
func protocolRequirementSetters<T: Protocol>(_ x: inout T, _ newValue: Float) {
  // No error expected
  x.property = newValue
  // No error expected
  x[] = newValue
}

// TF-1234: Test `@differentiable` propagation from class member storage
// declarations to their accessors in other file.
@differentiable(reverse)
func classRequirementGetters(_ x: Class) -> Float {
  // No error expected
  x.property + x[]
}

@differentiable(reverse)
func classRequirementSetters(_ x: inout Class, _ newValue: Float) {
  x.property = newValue
  x[] = newValue
}

// Test cross-file lookup of a derivative function with all-concrete derivative generic signature.
@differentiable(reverse)
func allConcreteDerivativeGenericSignature(_ a: [S]) -> Float {
  // No error expected.
  return a.sum()
}