EnzymeAD / rust

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

panic computing autodiff attributes of `<&T as core::fmt::Debug>::fmt` #183

Closed jedbrown closed 3 days ago

jedbrown commented 1 month ago

Code

This occurs while building rustc at 012062a3d7d2d52614eff5bc30526fc88596e3b7. I used the config.toml below and did a clean rebuild x build --stage 1 library after deleting my build directory.

```toml # Use different pre-set defaults than the global defaults. # # See `src/bootstrap/defaults` for more information. # Note that this has no default value (x.py uses the defaults in `config.example.toml`). profile = 'dist' change-id = 129176 [llvm] # Indicates whether the LLVM assertions are enabled or not # NOTE: When assertions are disabled, bugs in the integration between rustc and LLVM can lead to # unsoundness (segfaults, etc.) in the rustc process itself, not just in the generated code. assertions = true # Indicates whether the LLVM plugin is enabled or not plugins = true # Whether to use Ninja to build LLVM. This runs much faster than make. ninja = true # Whether to build LLVM as a dynamically linked library (as opposed to statically linked). # Under the hood, this passes `--shared` to llvm-config. # NOTE: To avoid performing LTO multiple times, we suggest setting this to `true` when `thin-lto` is enabled. link-shared = true # Whether to build the clang compiler. clang = true # Whether to build Enzyme as AutoDiff backend. enzyme = true [build] # Whether to build documentation by default. If false, rustdoc and # friends will still be compiled but they will not be used to generate any # documentation. # # You can still build documentation when this is disabled by explicitly passing paths, # e.g. `x doc library`. docs = false # Arguments passed to the `./configure` script, used during distcheck. You # probably won't fill this in but rather it's filled in by the `./configure` # script. Useful for debugging. configure-args = ['--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'] [install] [rust] debug = true #debuginfo-level = 2 # The "channel" for the Rust build to produce. The stable/beta channels only # allow using stable features, whereas the nightly and dev channels allow using # nightly features channel = 'nightly' # Indicates whether LLD will be compiled and made available in the sysroot for # rustc to execute. lld = true # Indicates whether the `self-contained` llvm-bitcode-linker, will be made available # in the sysroot. It is required for running nvptx tests. llvm-bitcode-linker = true [target.x86_64-unknown-linux-gnu] [dist] ```

Error output

thread 'rustc' panicked at /home/jed/src/rust-enzyme/compiler/rustc_middle/src/ty/mod.rs:1782:13:
assertion failed: rustc_feature::encode_cross_crate(attr)
[...]

rustc version: 1.84.0-nightly (012062a3d 2024-10-27)
platform: x86_64-unknown-linux-gnu

query stack during panic:
#0 [autodiff_attrs] computing autodiff attributes of `<&T as core::fmt::Debug>::fmt`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack

Full trace: rustc-ice-2024-10-28T18_58_06-3594632.txt

ZuseZ4 commented 1 month ago

What OS are you on? I couldn't reproduce it on 3 different systems.

jedbrown commented 1 month ago

Arch Linux and Debian (reproduced on both systems), both x86-64.

ZuseZ4 commented 1 month ago

I don't have these three, maybe try without?

[rust]
debug = true
llvm-bitcode-linker = true
lld = true

Independently, try to change

EncodeCrossCrate::No to EncodeCrossCrate::Yes in compiler/rustc_feature/src/builtin_attrs.rs line ~756

ZuseZ4 commented 1 month ago

potentially related: https://github.com/rust-lang/rust/pull/129458#discussion_r1738204301

jedbrown commented 1 month ago

Removing debug = true works on both machines and I can run the samples and integration tests in rustbook (great). I'm having trouble tracking down how to activate the new enzyme-loose-types key with rust.

ZuseZ4 commented 1 month ago

Does this work?

https://enzyme.mit.edu/index.fcgi/rust/debug_flags.html#benchmark-flags

jedbrown commented 1 month ago

Thanks. Seems to work (accepts the option), but rustbook/samples-loose-types is currently failing

Illegal updateAnalysis prev:{[-1]:Pointer, [-1,-1]:Integer} new: {[-1]:Pointer, [-1,0]:Float@double}
val:   %10 = getelementptr inbounds [6 x double], ptr %3, i64 0, i64 2, !dbg !254 origin=  store double %29, ptr %10, align 8, !dbg !254, !alias.scope !261, !noalias !264

error: could not compile `samples-loose-types` (test "mod")

after setting

diff --git c/samples-loose-types/tests/neohookean/mod.rs w/samples-loose-types/tests/neohookean/mod.rs
index e122c81..234ee75 100644
--- c/samples-loose-types/tests/neohookean/mod.rs
+++ w/samples-loose-types/tests/neohookean/mod.rs
@@ -3,6 +3,7 @@

 #![allow(non_snake_case)]

+use std::autodiff::autodiff;
 use std::ops::{Add, Mul, Sub};

 type Mat3x3 = [[f64; 3]; 3];

This is low priority and perhaps that example needs more changes (it uses second derivatives).

ZuseZ4 commented 3 days ago

closing, since the original bug was fixed. If the higher order persists after moving to the pass approach you can open a new issue (though probably against enzyme core).