forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathno_lto_flag.rs
More file actions
31 lines (24 loc) · 1014 Bytes
/
no_lto_flag.rs
File metadata and controls
31 lines (24 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//@ needs-enzyme
//@ no-prefer-dynamic
//@ revisions: with_lto no_lto
//@[with_lto] compile-flags: -Zautodiff=Enable -C opt-level=3 -Clto=fat
//@[no_lto] compile-flags: -Zautodiff=Enable -C opt-level=3 -Clto=thin
#![feature(autodiff)]
//@[no_lto] build-fail
//@[with_lto] build-pass
// Autodiff requires users to enable lto=fat (for now).
// In the past, autodiff did not run if users forget to enable fat-lto, which caused functions to
// returning zero-derivatives. That's obviously wrong and confusing to users. We now added a check
// which will abort compilation instead.
use std::autodiff::autodiff_reverse;
//[no_lto]~? ERROR using the autodiff feature requires setting `lto="fat"` in your Cargo.toml
#[autodiff_reverse(d_square, Duplicated, Active)]
fn square(x: &f64) -> f64 {
*x * *x
}
fn main() {
let xf64: f64 = std::hint::black_box(3.0);
let mut df_dxf64: f64 = std::hint::black_box(0.0);
let _output_f64 = d_square(&xf64, &mut df_dxf64, 1.0);
assert_eq!(6.0, df_dxf64);
}