expand_with_mode

Function expand_with_mode 

Source
pub(crate) fn expand_with_mode(
    ecx: &mut ExtCtxt<'_>,
    expand_span: Span,
    meta_item: &MetaItem,
    item: Annotatable,
    mode: DiffMode,
) -> 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 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]
fn sin(x: &Box<f32>) -> f32 {
    f32::sin(**x)
}
#[rustc_autodiff(Reverse, Duplicated, Active)]
fn cos_box(x: &Box<f32>, dx: &mut Box<f32>, dret: f32) -> f32 {
    std::intrinsics::autodiff(sin::<>, cos_box::<>, (x, dx, dret))
}

FIXME(ZuseZ4): Once autodiff is enabled by default, make this a doc comment which is checked in CI.