pub(crate) fn expand(
ecx: &mut ExtCtxt<'_>,
expand_span: Span,
meta_item: &MetaItem,
item: Annotatable,
) -> Vec<Annotatable>
Expand description
We expand the autodiff macro to generate a new placeholder function which passes type-checking and can be called by users. The function body of the placeholder function will later be replaced on LLVM-IR level, so the design of the body is less important and for now should just prevent early inlining and optimizations which alter the function signature. The exact signature of the generated function depends on the configuration provided by the user, but here is an example:
#[autodiff(cos_box, Reverse, Duplicated, Active)]
fn sin(x: &Box<f32>) -> f32 {
f32::sin(**x)
}
which becomes expanded to:
#[rustc_autodiff]
#[inline(never)]
fn sin(x: &Box<f32>) -> f32 {
f32::sin(**x)
}
#[rustc_autodiff(Reverse, Duplicated, Active)]
#[inline(never)]
fn cos_box(x: &Box<f32>, dx: &mut Box<f32>, dret: f32) -> f32 {
unsafe {
asm!("NOP");
};
::core::hint::black_box(sin(x));
::core::hint::black_box((dx, dret));
::core::hint::black_box(sin(x))
}
FIXME(ZuseZ4): Once autodiff is enabled by default, make this a doc comment which is checked in CI.