Follow up of #wg-autodiff > Simplify autodiff handling of dependencies (rlib) @ 💬 for @ZuseZ4 and @sgasho
Summary:
Generating the code to compute the derivatives of a function that calls other functions like powi results in a compiler error. Both autodiff_forward and autodiff_reverse are affected.
Minimal working example:
#![feature(autodiff)]
use std::autodiff::*;
#[autodiff_forward(rb_fwd, Dual, Dual, Const, Const, Dual)]
#[autodiff_reverse(rb_rev, Active, Active, Const, Const, Active)]
fn rosenbrock(x: f64, y: f64, a: f64, b: f64) -> f64 {
(a - x).powi(2) + b * (y - x.powi(2)).powi(2)
}
fn main() {
let (x, y) = (3.0, 5.0);
let (a, b) = (1.0, 100.0);
let z = rosenbrock(x, y, a, b);
let (_, vjp_x, vjp_y) = rb_rev(x, y, a, b, 1.0);
println!("{}", z);
println!("{} {}", vjp_x, vjp_y);
}
The code above should compile and print the following when ran:
Instead, it results in a compiler error. Building with -Z autodiff=Enable,PrintPasses outputs:
error: examples/rosenbrock.rs:8:43: in function preprocess__RNvCsdrX0DD2DCiN_10rosenbrock10rosenbrockB1_ double (double, double, double, double): Enzyme: No reverse pass found for _RNvMNtCs4FJwUMN6RBB_3std3f64d4powiCsdrX0DD2DCiN_10rosenbrock
at context: %9 = call double @_RNvMNtCs4FJwUMN6RBB_3std3f64d4powiCsdrX0DD2DCiN_10rosenbrock(double %8, i32 2) #6, !dbg !24
function(ee-instrument<>),always-inline,coro-cond(coro-early,cgscc(coro-split),coro-cleanup,globaldce),alloc-token,function(annotation-remarks),EnzymeNewPM
function(ee-instrument<>),always-inline,coro-cond(coro-early,cgscc(coro-split),coro-cleanup,globaldce),alloc-token,function(annotation-remarks),EnzymeNewPM
function(ee-instrument<>),always-inline,coro-cond(coro-early,cgscc(coro-split),coro-cleanup,globaldce),alloc-token,function(annotation-remarks),EnzymeNewPM
function(ee-instrument<>),always-inline,coro-cond(coro-early,cgscc(coro-split),coro-cleanup,globaldce),alloc-token,function(annotation-remarks),EnzymeNewPM
function(ee-instrument<>),always-inline,coro-cond(coro-early,cgscc(coro-split),coro-cleanup,globaldce),alloc-token,function(annotation-remarks),EnzymeNewPM
function(ee-instrument<>),always-inline,coro-cond(coro-early,cgscc(coro-split),coro-cleanup,globaldce),alloc-token,function(annotation-remarks),EnzymeNewPM
function(ee-instrument<>),always-inline,coro-cond(coro-early,cgscc(coro-split),coro-cleanup,globaldce),alloc-token,function(annotation-remarks),EnzymeNewPM
function(ee-instrument<>),always-inline,coro-cond(coro-early,cgscc(coro-split),coro-cleanup,globaldce),alloc-token,function(annotation-remarks),EnzymeNewPM
error: could not compile `enzyme-playground` (example "rosenbrock") due to 1 previous error
Removing the calls to powi in the function to differentiate overcomes the issue and produces the expected output:
#[autodiff_forward(rb_fwd, Dual, Dual, Const, Const, Dual)]
#[autodiff_reverse(rb_rev, Active, Active, Const, Const, Active)]
fn rosenbrock(x: f64, y: f64, a: f64, b: f64) -> f64 {
let c = a - x;
let d = y - x * x;
(c * c) + b * (d * d)
}
Meta
rustc --version --verbose:
rustc 1.95.0-nightly (f21b4c088 2026-02-10)
binary: rustc
commit-hash: f21b4c0888ca6a388fcf9365fc0044fa0642ab98
commit-date: 2026-02-10
host: aarch64-apple-darwin
release: 1.95.0-nightly
LLVM version: 22.1.0
Built following these instructions.
Follow up of #wg-autodiff > Simplify autodiff handling of dependencies (rlib) @ 💬 for @ZuseZ4 and @sgasho
Summary:
Generating the code to compute the derivatives of a function that calls other functions like
powiresults in a compiler error. Bothautodiff_forwardandautodiff_reverseare affected.Minimal working example:
The code above should compile and print the following when ran:
Instead, it results in a compiler error. Building with
-Z autodiff=Enable,PrintPassesoutputs:Removing the calls to
powiin the function to differentiate overcomes the issue and produces the expected output:Meta
rustc --version --verbose:Built following these instructions.