Skip to content

building rustc with autodiff and debug enabled fails. #139704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ZuseZ4 opened this issue Apr 12, 2025 · 5 comments · Fixed by #140030
Closed

building rustc with autodiff and debug enabled fails. #139704

ZuseZ4 opened this issue Apr 12, 2025 · 5 comments · Fixed by #140030
Assignees
Labels
C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. F-autodiff `#![feature(autodiff)]`

Comments

@ZuseZ4
Copy link
Member

ZuseZ4 commented Apr 12, 2025

I tried this code:

./configure --enable-llvm-link-shared --enable-llvm-plugins --enable-llvm-enzyme --release-channel=nightly --enable-llvm-assertions --enable-clang --enable-lld --enable-option-checking --enable-ninja --disable-docs --enable-debug
./x.py build --stage 1 library

I expected to see this happen: builds rustc

Instead, this happened:

thread 'rustc' panicked at compiler/rustc_codegen_ssa/src/codegen_attrs.rs:57:9:
unexpected `def_kind` in `codegen_fn_attrs`: GlobalAsm

[...]

query stack during panic:
#0 [codegen_fn_attrs] computing codegen attributes of `probestack::{global_asm#0}`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
... and 1 other queries... use `env RUST_BACKTRACE=1` to see the full query stack
error: could not compile `compiler_builtins` (lib)

Meta

rustc --version --verbose:

build from source

I know that debug builds used to work a few months ago.
So one could try to debug this by looking at the code. A much simpler solution probably is just
to do some binary search by building some older PR from the tracking issue with debug=true until finding one that builds. From there it should be easy to figure out which PR introduced the bug. Once that's clear it is hopefully easier to understand which change introduced the bug, and either directly fix it, or ask for help here or in the zulip channel. I'm marking it as easy, since it takes a bit of time to test multiple PRs but it isn't overly complex, and we had support for it and didn't introduce overly complex code changes in the last months. So the fix is likely also comparably simple.

This bug prevents us from enabling autodiff in CI and thus nightly, so any help would be appreciated!

Backtrace

<backtrace>

@ZuseZ4 ZuseZ4 added the C-bug Category: This is a bug. label Apr 12, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 12, 2025
@ZuseZ4 ZuseZ4 added F-autodiff `#![feature(autodiff)]` E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 12, 2025
@Shourya742
Copy link
Contributor

@rustbot claim

@ZuseZ4
Copy link
Member Author

ZuseZ4 commented Apr 19, 2025

@Shourya742 Since you still have the other open issue and I had some time today, I looked into it.
I could reproduce the bug starting with #133429, together with the error message it was easy from there to find the one-line fix. We want to prevent source functions to be inlined before autodiff, however we were incorrectly also checking for the other two MonoItem types, Static and GlobalAsm. Marking them as no-inline wouldn't be sensible.

@Shourya742
Copy link
Contributor

@Shourya742 Since you still have the other open issue and I had some time today, I looked into it. I could reproduce the bug starting with #133429, together with the error message it was easy from there to find the one-line fix. We want to prevent source functions to be inlined before autodiff, however we were incorrectly also checking for the other two MonoItem types, Static and GlobalAsm. Marking them as no-inline wouldn't be sensible.

That’s cool—I can help test and review it then. Naive me was going through all the commits that changed that file one by one, and each build took around 20 minutes to complete. Is there any way we can reduce the build time?

@ZuseZ4
Copy link
Member Author

ZuseZ4 commented Apr 20, 2025

Oh it's just a one line fix, so no need to review or test, oli should approve it soon. I am looking into some ways to improve bootstrap time and another person also wanted to check something related, I think it's better if not too many people work on it to avoid duplications.

If you look for other issues, it looks like no one is currently working on this one: EnzymeAD#193 (support for &dyn type) It's definitely a bit harder, but by now there should also be a lot of documentation. You'd need to work with opt and llvm-ir, if you want to give it a try. Once you figured out how to support it by hand, you can document it and we can add Rust wrapers which do it automatically. But I can also look for a pure Rust issue if you prefer?

@Shourya742
Copy link
Contributor

If you look for other issues, it looks like no one is currently working on this one: EnzymeAD#193 (support for &dyn type) It's definitely a bit harder, but by now there should also be a lot of documentation. You'd need to work with opt and llvm-ir, if you want to give it a try. Once you figured out how to support it by hand, you can document it and we can add Rust wrapers which do it automatically. But I can also look for a pure Rust issue if you prefer?

I can take this up. While more challenging issues might take some time, they will provide a great learning opportunity, and I'm ready for them. Pure Rust tasks can also be assigned — I have some time next week

@bors bors closed this as completed in c43b82f Apr 21, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 21, 2025
Rollup merge of rust-lang#140030 - EnzymeAD:autodiff-debug, r=jieyouxu

Fix autodiff debug builds

r? `@oli-obk`

closes: rust-lang#139704

Tracking:

- rust-lang#124509
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. F-autodiff `#![feature(autodiff)]`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants