Skip to content

Commit 69b4995

Browse files
dan-zhengrxwei
authored andcommitted
[AutoDiff] Modify non-@differentiable external function diagnostic. (#24891)
Change diagnostic text from "external function" to "functions from other modules". Add test.
1 parent 89be5fb commit 69b4995

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ ERROR(autodiff_expression_not_differentiable_error,none,
409409
NOTE(autodiff_expression_not_differentiable_note,none,
410410
"expression is not differentiable", ())
411411
NOTE(autodiff_external_nondifferentiable_function,none,
412-
"cannot differentiate an external function that has not been marked "
413-
"'@differentiable'", ())
412+
"cannot differentiate functions that have not been marked "
413+
"'@differentiable' and that are defined in other files", ())
414414
NOTE(autodiff_nondifferentiable_argument,none,
415415
"cannot differentiate through a non-differentiable argument; do you want "
416416
"to add '.withoutDerivative()'?", ())
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// A public function that is not marked with `@differentiable`.
2+
// Differentiation of `externalFunction` in other modules should fail.
3+
public func externalFunction(_ x: Float) -> Float {
4+
return x + x
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -primary-file %S/Inputs/nondifferentiable_function_other_module.swift -emit-module-path %t/nondifferentiable_function_other_module.swiftmodule
3+
// RUN: %target-swift-frontend -emit-sil -I %t -primary-file %s -verify
4+
5+
import nondifferentiable_function_other_module
6+
7+
func test() {
8+
// expected-error @+2 {{function is not differentiable}}
9+
// expected-note @+1 {{cannot differentiate functions that have not been marked '@differentiable' and that are defined in other files}}
10+
_ = gradient(at: Float(1), in: externalFunction)
11+
}

0 commit comments

Comments
 (0)