You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[AutoDiff][SR-13152] Better diagnostic for static decl modifier mismatch. (#36128)
Improved diagnostic for when the registered derivative function and
the function it derivates (the original) differ in terms of
`static` declaration modifier usage. Suggesting as well a fix-it,
to either remove or add the `static` keyword.
The registered derivative needs to be marked as `static` in two cases:
1. When the original function is a constructor.
2. When the original function is static as well.
When the original function is an instance method, the registered derivative must be as well.
Resolves [SR-13152](https://bugs.swift.org/browse/SR-13152).
// Test invalid derivative type context: instance vs static method mismatch.
673
-
674
-
structInvalidTypeContext<T:Differentiable>{
675
-
// expected-note @+1 {{candidate static method does not have type equal to or less constrained than '<T where T : Differentiable> (InvalidTypeContext<T>) -> (T) -> T'}}
676
-
staticfunc staticMethod(_ x:T)->T{ x }
677
-
678
-
// expected-error @+1 {{referenced declaration 'staticMethod' could not be resolved}}
// expected-error @+1 {{unexpected derivative function declaration; 'instanceMethod' requires the derivative function 'jvpInstance' to be an instance method}}
1172
+
@derivative(of: instanceMethod)
1173
+
// expected-note @+1 {{make derivative function 'jvpInstance' an instance method}}{{3-10=}}
// expected-error @+1 {{unexpected derivative function declaration; 'staticMethod' requires the derivative function 'jvpStatic' to be a 'static' method}}
1181
+
@derivative(of: staticMethod)
1182
+
// expected-note @+1 {{make derivative function 'jvpStatic' a 'static' method}}{{3-3=static }}
Copy file name to clipboardExpand all lines: test/AutoDiff/Sema/transpose_attr_type_checking.swift
+3-5Lines changed: 3 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -474,7 +474,6 @@ extension Float {
474
474
475
475
// Test non-`func` original declarations.
476
476
477
-
// expected-note @+1 {{candidate initializer does not have type equal to or less constrained than '<T where T : Differentiable, T == T.TangentVector> (Struct<T>) -> (Float) -> Struct<T>'}}
// expected-note @+1 {{candidate initializer does not have type equal to or less constrained than '<T where T : Differentiable, T == T.TangentVector> (Struct<T>) -> (Float) -> Struct<T>'}}
501
+
// expected-note @+1 {{original function 'init(_:)' is a 'static' method}}
503
502
init(_ x:Float){}
504
-
// expected-note @+1 {{candidate initializer does not have type equal to or less constrained than '<T where T : Differentiable, T == T.TangentVector> (Struct<T>) -> (Float) -> Struct<T>'}}
505
503
init(_ x:T, y:Float){}
506
504
}
507
505
@@ -517,9 +515,9 @@ extension Struct where T: Differentiable, T == T.TangentVector {
517
515
}
518
516
519
517
// Test instance transpose for static original initializer.
520
-
// TODO(TF-1015): Add improved instance/static member mismatch error.
521
-
// expected-error @+1 {{referenced declaration 'init' could not be resolved}}
518
+
// expected-error @+1 {{unexpected transpose function declaration; 'init(_:)' requires the transpose function 'vjpInitStaticMismatch' to be a 'static' method}}
522
519
@transpose(of: init, wrt:0)
520
+
// expected-note @+1 {{make transpose function 'vjpInitStaticMismatch' a 'static' method}}{{3-3=static }}
0 commit comments