Commit 16daae9
authored
[AutoDiff] [Sema] Reject function types where all parameters are '@noDerivative'. (swiftlang#34861)
A `@differentiable` function type require at least 1 differentiability parameter. This PR adds a diagnostic that rejects cases where all parameters are marked with `@noDerivative`. This fixes a compiler crasher.
```swift
test2.swift:3:24: error: '@differentiable' function type requires at least one differentiability parameter, i.e. a non-'@noDerivative' parameter whose type conforms to 'Differentiable'
let _: @differentiable (@noDerivative Float) -> Float = { _ in 0 }
^~~~~~~~~~~~~~~~~~~~~
test2.swift:4:32: error: '@differentiable' function type requires at least one differentiability parameter, i.e. a non-'@noDerivative' parameter whose type conforms to 'Differentiable' with its 'TangentVector' equal to itself
let _: @differentiable(linear) (@noDerivative Float, @noDerivative Int) -> Float = { _, _ in 0 }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```1 parent 887464b commit 16daae9
File tree
3 files changed
+31
-2
lines changed- include/swift/AST
- lib/Sema
- test/AutoDiff/Sema
3 files changed
+31
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4473 | 4473 | | |
4474 | 4474 | | |
4475 | 4475 | | |
4476 | | - | |
| 4476 | + | |
4477 | 4477 | | |
4478 | 4478 | | |
4479 | 4479 | | |
4480 | 4480 | | |
4481 | 4481 | | |
4482 | 4482 | | |
| 4483 | + | |
| 4484 | + | |
| 4485 | + | |
| 4486 | + | |
| 4487 | + | |
| 4488 | + | |
4483 | 4489 | | |
4484 | 4490 | | |
4485 | 4491 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2610 | 2610 | | |
2611 | 2611 | | |
2612 | 2612 | | |
| 2613 | + | |
2613 | 2614 | | |
2614 | 2615 | | |
2615 | 2616 | | |
2616 | 2617 | | |
2617 | 2618 | | |
2618 | 2619 | | |
2619 | | - | |
| 2620 | + | |
2620 | 2621 | | |
2621 | 2622 | | |
2622 | 2623 | | |
2623 | 2624 | | |
2624 | 2625 | | |
2625 | 2626 | | |
| 2627 | + | |
2626 | 2628 | | |
2627 | 2629 | | |
2628 | 2630 | | |
| 2631 | + | |
| 2632 | + | |
| 2633 | + | |
| 2634 | + | |
| 2635 | + | |
| 2636 | + | |
| 2637 | + | |
| 2638 | + | |
| 2639 | + | |
2629 | 2640 | | |
2630 | 2641 | | |
2631 | 2642 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
122 | 134 | | |
123 | 135 | | |
124 | 136 | | |
| |||
0 commit comments