File tree Expand file tree Collapse file tree 3 files changed +42
-0
lines changed
test/AutoDiff/Sema/DerivativeRegistrationCrossModule Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ public struct Struct {
2
+ public func method( _ x: Float ) -> Float { x }
3
+
4
+ public static func + ( _ lhs: Self , rhs: Self ) -> Self {
5
+ lhs
6
+ }
7
+ }
Original file line number Diff line number Diff line change
1
+ import _Differentiation
2
+ import a
3
+
4
+ extension Struct : Differentiable {
5
+ public struct TangentVector : Differentiable & AdditiveArithmetic { }
6
+ public mutating func move( along _: TangentVector ) { }
7
+
8
+ @usableFromInline
9
+ @derivative ( of: method, wrt: x)
10
+ func vjpMethod( _ x: Float ) -> ( value: Float , pullback: ( Float ) -> Float ) {
11
+ ( x, { $0 } )
12
+ }
13
+
14
+ @usableFromInline
15
+ @derivative ( of: + )
16
+ static func vjpAdd( _ lhs: Self , rhs: Self ) -> (
17
+ value: Self , pullback: ( TangentVector ) -> ( TangentVector , TangentVector )
18
+ ) {
19
+ ( lhs + rhs, { v in ( v, v) } )
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ // RUN: %empty-directory(%t)
2
+ // RUN: %target-swift-frontend -emit-module -primary-file %S/Inputs/a.swift -emit-module-path %t/a.swiftmodule
3
+ // RUN: %target-swift-frontend -emit-module -primary-file %S/Inputs/b.swift -emit-module-path %t/b.swiftmodule -I %t
4
+ // RUN: not --crash %target-swift-frontend-typecheck -verify -I %t %s
5
+
6
+ // SR-12526: Fix cross-module deserialization crash involving `@derivative` attribute.
7
+
8
+ import a
9
+ import b
10
+
11
+ func foo( _ s: Struct ) {
12
+ _ = Struct ( )
13
+ _ = s. method ( 1 )
14
+ }
You can’t perform that action at this time.
0 commit comments