Skip to content

autodiff incorrectly applies fat-lto to proc-macro crate. #147487

@ZuseZ4

Description

@ZuseZ4

std::autodiff requires fat-lto to work (although we intend to support embed-bc in the future).
Since it's an experimental feature, we require users to set -Zautodiff=Enable to be able to use it as well.

A while ago I opened an issue to automatically enable fat-lto if the user sets the autodiff=Enable flag, so users can't forget about it. The implementation PR was a nice improvement for most cases. Unfortunately, though, I just noticed that it looks like the implementation had a slightly different effect than desired:

I tried this code:

cargo init <name>
cd <name>
cargo add faer
 RUSTFLAGS="-Z autodiff=Enable" cargo +enzyme build -r

I expected to see this happen: compiles

Instead, this happened:

   Compiling libm v0.2.15
   Compiling proc-macro2 v1.0.101
   Compiling autocfg v1.5.0
   Compiling unicode-ident v1.0.19
   Compiling quote v1.0.41
   Compiling crossbeam-utils v0.8.21
   Compiling bytemuck v1.24.0
   Compiling rand_core v0.6.4
   Compiling cfg-if v1.0.3
   Compiling nano-gemm-codegen v0.1.0
   Compiling rayon-core v1.13.0
   Compiling version_check v0.9.5
   Compiling libc v0.2.176
   Compiling reborrow v0.5.5
   Compiling either v1.15.0
   Compiling dyn-stack-macros v0.1.0
   Compiling paste v1.0.15
   Compiling bitflags v2.9.4
   Compiling zerocopy v0.8.27
error: lto cannot be used for `proc-macro` crate type without `-Zdylib-lto`

error: could not compile `dyn-stack-macros` (lib) due to 1 previous error

The same example used to compile though, if we revert the PR and manually set "lto=fat" in our Cargo.toml.
So apparently the PR enforces fat-lto for slightly more than the equivalent Cargo.toml setting? It would be good if we could match it and not try to fat-lto proc-macro crates.

cc @Hayden602 and @helldawg in case you want to look into this follow-up issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.F-autodiff`#![feature(autodiff)]`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions