rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
94.9k stars 12.23k forks source link

Rust 1.60 segmentation fault related to const generics #96672

Closed NickHu closed 2 years ago

NickHu commented 2 years ago

Code

I tried this code:

nix build github:homotopy-io/homotopy-rs?rev=0cc608109c699f7fac2e7979f2f0d440ac4ac786

I expected to see this happen: successful compilation

Instead, this happened:

@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/v4fmilsv73fjm9gy6ggvdlkds4m8a9af-source
source root is source
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
[naersk] cargo_version (read): 1.60.0 (d1fd9fe 2022-03-01)
[naersk] cargo_message_format (set): json-diagnostic-rendered-ansi
[naersk] cargo_release: --release
[naersk] cargo_options: 
[naersk] cargo_build_options: $cargo_release -j "$NIX_BUILD_CORES" --message-format=$cargo_message_format -p homotopy-web
[naersk] cargo_test_options: $cargo_release -j "$NIX_BUILD_CORES"
[naersk] RUST_TEST_THREADS: 32
[naersk] cargo_bins_jq_filter: select(.reason == "compiler-artifact" and .executable != null and .profile.test == false)
[naersk] cargo_build_output_json (created): /build/tmp.AMfM0fmYyn
[naersk] crate_sources: /nix/store/hjmyjcasiifgnpm0s0ss264ry3100iq8-crates-io
[naersk] RUSTFLAGS: 
[naersk] CARGO_BUILD_RUSTFLAGS: 
[naersk] CARGO_BUILD_RUSTFLAGS (updated): --remap-path-prefix /nix/store/hjmyjcasiifgnpm0s0ss264ry3100iq8-crates-io=/sources
[naersk] pre-installing dep /nix/store/4risald0r359aliark65q2fmhif5ml0j-homotopy-web-deps-0.1.2
@nix { "action": "setPhase", "phase": "buildPhase" }
building
cargo build $cargo_release -j "$NIX_BUILD_CORES" --message-format=$cargo_message_format -p homotopy-web
   Compiling homotopy-common v0.1.0 (/build/source/homotopy-common)
   Compiling homotopy-core v0.1.0 (/build/source/homotopy-core)
   Compiling homotopy-graphics v0.1.0 (/build/source/homotopy-graphics)
   Compiling homotopy-web v0.1.2 (/build/source/homotopy-web)
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/librustc_driver-75e5f32fc3580f6c.so(+0x4b3d23)[0x7ffff469bd23]
/nix/store/ayrsyv7npr0lcbann4k9lxr19x813f0z-glibc-2.34-115/lib/libc.so.6(+0x41100)[0x7ffff3cab100]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libLLVM-14-rust-1.60.0-stable.so(_ZN4llvm10BasicBlockC1ERNS_11LLVMContextERKNS_5TwineEPNS_8FunctionEPS0_+0xc5)[0x7ffff132a075]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libLLVM-14-rust-1.60.0-stable.so(+0x2707510)[0x7ffff0f23510]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libLLVM-14-rust-1.60.0-stable.so(+0x27008af)[0x7ffff0f1c8af]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libLLVM-14-rust-1.60.0-stable.so(_ZN4llvm11simplifyCFGEPNS_10BasicBlockERKNS_19TargetTransformInfoEPNS_14DomTreeUpdaterERKNS_18SimplifyCFGOptionsENS_8ArrayRefINS_6WeakVHEEE+0x2315)[0x7ffff0ed8965]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libLLVM-14-rust-1.60.0-stable.so(+0x26b7bc5)[0x7ffff0ed3bc5]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libLLVM-14-rust-1.60.0-stable.so(+0x26b529a)[0x7ffff0ed129a]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libLLVM-14-rust-1.60.0-stable.so(+0x2387229)[0x7ffff0ba3229]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libLLVM-14-rust-1.60.0-stable.so(_ZN4llvm27ModuleToFunctionPassAdaptor3runERNS_6ModuleERNS_15AnalysisManagerIS1_JEEE+0x329)[0x7ffff1aa7659]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libLLVM-14-rust-1.60.0-stable.so(+0x328b31d)[0x7ffff1aa731d]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libLLVM-14-rust-1.60.0-stable.so(_ZN4llvm11PassManagerINS_6ModuleENS_15AnalysisManagerIS1_JEEEJEE3runERS1_RS3_+0x144)[0x7ffff19285c4]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/librustc_driver-75e5f32fc3580f6c.so(+0x23dfef1)[0x7ffff65c7ef1]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/librustc_driver-75e5f32fc3580f6c.so(+0x23cdb54)[0x7ffff65b5b54]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/librustc_driver-75e5f32fc3580f6c.so(+0x23ce0a1)[0x7ffff65b60a1]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/librustc_driver-75e5f32fc3580f6c.so(+0x2365d7d)[0x7ffff654dd7d]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/librustc_driver-75e5f32fc3580f6c.so(+0x238380f)[0x7ffff656b80f]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/librustc_driver-75e5f32fc3580f6c.so(+0x2372bc7)[0x7ffff655abc7]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libstd-8d61b92a0a02f53a.so(rust_metadata_std_cd3cf6af28dff6de+0xa7d03)[0x7ffff3f21d03]
/nix/store/ayrsyv7npr0lcbann4k9lxr19x813f0z-glibc-2.34-115/lib/libc.so.6(+0x89eb2)[0x7ffff3cf3eb2]
/nix/store/ayrsyv7npr0lcbann4k9lxr19x813f0z-glibc-2.34-115/lib/libc.so.6(+0x10c31c)[0x7ffff3d7631c]
error: could not compile `homotopy-web`

Caused by:
  process didn't exit successfully: `/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/bin/rustc --crate-name homotopy_web --edition=2021 homotopy-web/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type cdylib --crate-type rlib --emit=dep-info,link -C opt-level=3 --cfg 'feature="console_error_panic_hook"' --cfg 'feature="default"' -C metadata=d0edfb7c13dcde66 --out-dir /build/source/target/wasm32-unknown-unknown/release/deps --target wasm32-unknown-unknown -L dependency=/build/source/target/wasm32-unknown-unknown/release/deps -L dependency=/build/source/target/release/deps --extern arrayvec=/build/source/target/wasm32-unknown-unknown/release/deps/libarrayvec-064facd1d3b4ac08.rlib --extern closure=/build/source/target/wasm32-unknown-unknown/release/deps/libclosure-22ef8d2fe5957b87.rlib --extern console_error_panic_hook=/build/source/target/wasm32-unknown-unknown/release/deps/libconsole_error_panic_hook-2057c4514695902f.rlib --extern euclid=/build/source/target/wasm32-unknown-unknown/release/deps/libeuclid-3dae85bc5bb07a71.rlib --extern gloo=/build/source/target/wasm32-unknown-unknown/release/deps/libgloo-b43aad26b340de48.rlib --extern gloo_timers=/build/source/target/wasm32-unknown-unknown/release/deps/libgloo_timers-bc23fdea00850d70.rlib --extern homotopy_common=/build/source/target/wasm32-unknown-unknown/release/deps/libhomotopy_common-0ba795d2fc24788e.rlib --extern homotopy_core=/build/source/target/wasm32-unknown-unknown/release/deps/libhomotopy_core-5b86ed58e29945d8.rlib --extern homotopy_graphics=/build/source/target/wasm32-unknown-unknown/release/deps/libhomotopy_graphics-5b9942fcbc1b42fd.rlib --extern im=/build/source/target/wasm32-unknown-unknown/release/deps/libim-f68605f388142b72.rlib --extern instant=/build/source/target/wasm32-unknown-unknown/release/deps/libinstant-15f531c8d8e23534.rlib --extern js_sys=/build/source/target/wasm32-unknown-unknown/release/deps/libjs_sys-d892199c945c5dfe.rlib --extern log=/build/source/target/wasm32-unknown-unknown/release/deps/liblog-f0424ddc1a3d06f8.rlib --extern lyon_path=/build/source/target/wasm32-unknown-unknown/release/deps/liblyon_path-4c1b5b611b75ca6b.rlib --extern obake=/build/source/target/wasm32-unknown-unknown/release/deps/libobake-5427d7eb3090cf45.rlib --extern palette=/build/source/target/wasm32-unknown-unknown/release/deps/libpalette-087ea92923972b9c.rlib --extern paste=/build/source/target/release/deps/libpaste-9f4ba831280a7332.so --extern quote=/build/source/target/wasm32-unknown-unknown/release/deps/libquote-0bea2f79134eb277.rlib --extern rmp_serde=/build/source/target/wasm32-unknown-unknown/release/deps/librmp_serde-104a28574bf452c8.rlib --extern serde=/build/source/target/wasm32-unknown-unknown/release/deps/libserde-8cef68772708519b.rlib --extern syn=/build/source/target/wasm32-unknown-unknown/release/deps/libsyn-fc3acf24a1e49ab3.rlib --extern thiserror=/build/source/target/wasm32-unknown-unknown/release/deps/libthiserror-033ceb9e6bdfab8c.rlib --extern ultraviolet=/build/source/target/wasm32-unknown-unknown/release/deps/libultraviolet-40630f624adb9f9d.rlib --extern wasm_bindgen=/build/source/target/wasm32-unknown-unknown/release/deps/libwasm_bindgen-a75edcdc1a8fc987.rlib --extern wasm_logger=/build/source/target/wasm32-unknown-unknown/release/deps/libwasm_logger-235f2a8f6828be52.rlib --extern web_sys=/build/source/target/wasm32-unknown-unknown/release/deps/libweb_sys-96345e1705e5ba46.rlib --extern yew=/build/source/target/wasm32-unknown-unknown/release/deps/libyew-e97f053b58fd785b.rlib --extern yew_agent=/build/source/target/wasm32-unknown-unknown/release/deps/libyew_agent-af8da546ff0d9932.rlib --extern yew_macro=/build/source/target/release/deps/libyew_macro-967187fef99f778d.so --remap-path-prefix /nix/store/hjmyjcasiifgnpm0s0ss264ry3100iq8-crates-io=/sources` (signal: 11, SIGSEGV: invalid memory reference)
[naersk] cargo returned with exit code 101, exiting

Version it worked on

It most recently worked on (nix build github:homotopy-io/homotopy-rs?rev=5ba852c72a3e552d3668233a14fd9769dea0797e):

rustc 1.59.0 (9d1b2106e 2022-02-23)
binary: rustc
commit-hash: 9d1b2106e23b1abd32fce1f17267604a5102f57a
commit-date: 2022-02-23
host: x86_64-unknown-linux-gnu
release: 1.59.0
LLVM version: 13.0.0

Version with regression

rustc --version --verbose:

rustc 1.60.0 (7737e0b5c 2022-04-04)
binary: rustc
commit-hash: 7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c
commit-date: 2022-04-04
host: x86_64-unknown-linux-gnu
release: 1.60.0
LLVM version: 14.0.0

Other information

We've determined that https://github.com/homotopy-io/homotopy-rs/blob/0cc608109c699f7fac2e7979f2f0d440ac4ac786/homotopy-web/src/app/workspace.rs#L101 is the culprit; either removing that line or replacing <0> with <1> both fix the compiler crashing (although this does not produce the code we want).

This looks like it's possibly related to the LLVM version.

@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged

apiraino commented 2 years ago

A bit of reducing could help here. ideally we want to be able to reproduce.

@rustbot label +O-wasm

tagging also @rustbot ping icebreakers-cleanup-crew

rustbot commented 2 years ago

Hey Cleanup Crew ICE-breakers! This bug has been identified as a good "Cleanup ICE-breaking candidate". In case it's useful, here are some instructions for tackling these sorts of bugs. Maybe take a look? Thanks! <3

cc @AminArria @ayazhafiz @camelid @chrissimpkins @contrun @elshize @h-michael @HallerPatrick @hdhoang @hellow554 @henryboisdequin @imtsuki @JamesPatrickGill @kanru @KarlK90 @matheus-consoli @mental32 @nmccarty @Noah-Kennedy @pard68 @PeytonT @pierreN @Redblueflame @RobbieClarken @RobertoSnap @robjtede @SarthakSingh31 @shekohex @sinato @smmalis37 @steffahn @Stupremee @tamuhey @turboladen @woshilapin @yerke

SNCPlay42 commented 2 years ago

Reduced: (must be compiled with --target=wasm32-unknown-unknown -C opt-level=3, which can be done on playground by setting to "release" and clicking "WASM" instead of "Run")

fn explode<V, F, V2>(mut node_map: F) -> Option<()>
where
    F: FnMut(V) -> Option<V2>,
{
    let key = conjure();
    node_map(key)?;
    None
}

pub struct Layout<const N: usize>;
impl<const N: usize> Layout<N> {
    pub fn new() {
        for i in 0..N {
            let node_map = |key: [(); N]| -> Option<[f32; N]> {
                key[i];
                None
            };
            explode(node_map);
        }
    }
}

fn conjure<T>() -> T {
    unimplemented!()
}

pub fn main() {
    Layout::<0>::new();
}
SNCPlay42 commented 2 years ago

searched nightlies: from nightly-2022-01-13 to nightly-2022-05-03 regressed nightly: nightly-2022-03-11 searched commit range: https://github.com/rust-lang/rust/compare/458262b1315e0de7be940fe95e111bb045e4a2a4...5f4e0677190b82e61dc507e3e72caf89da8e5e28 regressed commit: https://github.com/rust-lang/rust/commit/282778aee26166754315815552bae454fc968960

bisected with cargo-bisect-rustc v0.6.3 Host triple: x86_64-unknown-linux-gnu Reproduce with: ```bash cargo bisect-rustc --preserve --start=2022-01-13 --target=wasm32-unknown-unknown -- build --release --target=wasm32-unknown-unknown ```

This did indeed regress in the LLVM bump (#94764).

@rustbot label I-crash A-llvm

apiraino commented 2 years ago

Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

Great work @SNCPlay42 thanks!

@rustbot label -I-prioritize +P-high -ICEBreaker-Cleanup-Crew

luqmana commented 2 years ago

Looks like https://reviews.llvm.org/D119854 is the change where it starts failing. Adding -C llvm-args="-switch-range-to-icmp=1" does seem to work around the crash.

cc @nikic

nikic commented 2 years ago

IR: https://gist.github.com/nikic/66478e84510d35b763a6b99a2aefa508 Running this through opt -O3 crashes with LLVM 14 but works fine on main, so this was apparently already fixed in the meantime.

nikic commented 2 years ago

Bisect points to https://github.com/llvm/llvm-project/commit/857c612d899f271402470d4026d2e3be1dce53a4, which probably just hides the problem.

nikic commented 2 years ago

Ah no, I misread. That does look like the actual fix for the issue.

nikic commented 2 years ago

Filed backport issue: https://github.com/llvm/llvm-project/issues/55304

NickHu commented 2 years ago

Apologies for the noise, but did this fix make its way into 1.61? I'm still getting similar issues there.