File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -3354,7 +3354,15 @@ getAutoDiffOriginalFunctionType(AnyFunctionType *derivativeFnTy) {
3354
3354
}
3355
3355
3356
3356
void AttributeChecker::visitDerivativeAttr (DerivativeAttr *attr) {
3357
- FuncDecl *derivative = cast<FuncDecl>(D);
3357
+ // `@derivative` attribute requires experimental differentiable programming
3358
+ // to be enabled.
3359
+ auto &ctx = D->getASTContext ();
3360
+ if (!ctx.LangOpts .EnableExperimentalDifferentiableProgramming ) {
3361
+ diagnoseAndRemoveAttr (
3362
+ attr, diag::experimental_differentiable_programming_disabled);
3363
+ return ;
3364
+ }
3365
+ auto *derivative = cast<FuncDecl>(D);
3358
3366
auto lookupConformance =
3359
3367
LookUpConformanceInModule (D->getDeclContext ()->getParentModule ());
3360
3368
auto originalName = attr->getOriginalFunctionName ();
Original file line number Diff line number Diff line change 2
2
3
3
// expected-error @+1 {{differentiable programming is an experimental feature that is currently disabled}}
4
4
let _: @differentiable ( Float ) -> Float
5
+
6
+ func id( _ x: Float ) -> Float {
7
+ return x
8
+ }
9
+ // expected-error @+1 {{differentiable programming is an experimental feature that is currently disabled}}
10
+ @derivative ( of: id)
11
+ func jvpId( x: Float ) -> ( value: Float , differential: ( Float ) -> ( Float ) ) {
12
+ return ( x, { $0 } )
13
+ }
You can’t perform that action at this time.
0 commit comments