Skip to content

Commit 709d7d5

Browse files
author
marcrasi
authored
[AutoDiff] @_alwaysEmitIntoClient registration tests (#29129)
Here are some negative tests demonstrating the problem in TF-1103.
1 parent 152d71c commit 709d7d5

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@_alwaysEmitIntoClient
2+
public func f(_ x: Float) -> Float {
3+
x
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@derivative(of: f)
2+
@_alwaysEmitIntoClient
3+
public func df(_ x: Float) -> (value: Float, pullback: (Float) -> Float) {
4+
(x, { 10 * $0 })
5+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@_alwaysEmitIntoClient
2+
public func f(_ x: Float) -> Float {
3+
x
4+
}
5+
6+
@derivative(of: f)
7+
@_alwaysEmitIntoClient
8+
public func df(_ x: Float) -> (value: Float, pullback: (Float) -> Float) {
9+
(x, { 10 * $0 })
10+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// TODO(TF-1103): Fix this test so that there is not a linker error. Then, move this test to
2+
// cross_module_derivative_attr_e2e.swift.
3+
4+
// RUN: %empty-directory(%t)
5+
// RUN: %target-build-swift -Xfrontend -enable-experimental-cross-file-derivative-registration -parse-as-library -emit-module -module-name MultiFileModule -emit-module-path %t/MultiFileModule.swiftmodule -emit-library -o %t/%target-library-name(MultiFileModule) %S/Inputs/always_emit_into_client/MultiFileModule/file1.swift %S/Inputs/always_emit_into_client/MultiFileModule/file2.swift
6+
// RUN: not %target-build-swift -I%t -L%t %s -o %t/a.out -lm -lMultiFileModule 2>&1 | %FileCheck %s
7+
8+
import StdlibUnittest
9+
10+
import MultiFileModule
11+
12+
var AlwaysEmitIntoClientTests = TestSuite("AlwaysEmitIntoClient")
13+
14+
AlwaysEmitIntoClientTests.test("registration") {
15+
expectEqual(10, gradient(at: 0, in: f))
16+
}
17+
18+
runAllTests()
19+
20+
// CHECK: {{[Uu]}}ndefined
21+
// CHECK: AD__$s15MultiFileModule1fyS2fF_PSRS
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// TODO(TF-1103): Fix this test so that there is not a linker error. Then, move this test to
2+
// cross_module_derivative_attr_e2e.swift.
3+
4+
// RUN: %empty-directory(%t)
5+
// RUN: %target-build-swift -Xfrontend -enable-experimental-cross-file-derivative-registration -parse-as-library -emit-module -module-name SingleFileModule -emit-module-path %t/SingleFileModule.swiftmodule -emit-library -o %t/%target-library-name(SingleFileModule) %S/Inputs/always_emit_into_client/SingleFileModule/file.swift
6+
// RUN: not %target-build-swift -I%t -L%t %s -o %t/a.out -lm -lSingleFileModule 2>&1 | %FileCheck %s
7+
8+
import StdlibUnittest
9+
10+
import SingleFileModule
11+
12+
var AlwaysEmitIntoClientTests = TestSuite("AlwaysEmitIntoClient")
13+
14+
AlwaysEmitIntoClientTests.test("registration") {
15+
expectEqual(10, gradient(at: 0, in: f))
16+
}
17+
18+
runAllTests()
19+
20+
// CHECK: {{[Uu]}}ndefined
21+
// CHECK: AD__$s16SingleFileModule1fyS2fF_PSRS

0 commit comments

Comments
 (0)