EnzymeAD / rust

A rust fork to work towards Enzyme integration
https://www.rust-lang.org
Other
72 stars 8 forks source link

autodiff macro fails to compile when used on functions defined within other functions #184

Open sYgbpNA5UEVufjsHNwF3Xvf9ANZi5bNs opened 3 weeks ago

sYgbpNA5UEVufjsHNwF3Xvf9ANZi5bNs commented 3 weeks ago

output of rustc +enzyme --version --verbose:

rustc 1.84.0-nightly (1203575c6 2024-10-30) binary: rustc commit-hash: 1203575c627a2e96bc3543145526b5091a58be65 commit-date: 2024-10-30 host: x86_64-unknown-linux-gnu release: 1.84.0-nightly LLVM version: 19.1.1

an example:

#![feature(autodiff)]
use std::autodiff::autodiff;

fn main() {
    #[autodiff(d_inner, Forward, Dual, DualOnly)]
    fn inner(x: f32) -> f32 {
        x * x
    }
}

build results in the error message (with the first line with the path manually removed)

error: autodiff must be applied to function
 --> src/main.rs:6:5
  |
6 | /     fn inner(x: f32) -> f32 {
7 | |         x * x
8 | |     }
  | |_____^

error: could not compile `enzyme-test` (bin "enzyme-test") due to 1 previous error
ZuseZ4 commented 3 weeks ago

Thanks for the issue report! I'm a bit short on time till Nov 15, but will look at it afterwards. That being said it's a frontend error, and those are usually easy to fix. Here is the PR where I merged the frontend logic: https://github.com/rust-lang/rust/pull/129458/files#diff-548c9b1b2ceb2091452377c3716d4fe1b707295b33705834a97ce4274eb82afa The error should be in compiler/rustc_builtin_macros/src/autodiff.rs, you probably need to look at the match statements which as fallback lead to this error and add the one case that matches this inner function (and is currently not getting matched). But otherwise I can also add handling for it after my deadlines.