Skip to content
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

ICE with const_generics + const_compare_raw_pointers: broken MIR / NoSolution #72352

Closed
jplatte opened this issue May 19, 2020 · 3 comments · Fixed by #73795
Closed

ICE with const_generics + const_compare_raw_pointers: broken MIR / NoSolution #72352

jplatte opened this issue May 19, 2020 · 3 comments · Fixed by #73795
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-const_generics `#![feature(const_generics)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jplatte
Copy link
Contributor

jplatte commented May 19, 2020

I've tried reducing this but wasn't really able to so far. I might try again some other time.

The code below currently ICEs on Nightly (a74d1862d 2020-05-14). When trying to reproduce locally for the backtrace, I had an older Nightly first (5d04ce67f 2020-02-13) where this actually didn't crash the compiler, so it's apparently a regression.

Code

#![allow(incomplete_features)]
#![feature(const_compare_raw_pointers)]
#![feature(const_generics)]

use std::ffi::{CStr, CString};

fn main() {
    let baguette = CString::new("baguette").unwrap();
    let ptr = baguette.as_ptr();
    println!("{}", unsafe {
        unsafely_do_the_thing::<safely_do_the_thing>(ptr)
    });
}

unsafe fn unsafely_do_the_thing<const F: fn(&CStr) -> usize>(ptr: *const i8) -> usize {
    F(CStr::from_ptr(ptr))
}

fn safely_do_the_thing(s: &CStr) -> usize {
    s.to_bytes().len()
}

Playground

Error output

error: internal compiler error: broken MIR in DefId(0:6 ~ foo[317d]::main[0]) (CanonicalUserTypeAnnotation { user_ty: Canonical { max_universe: U0, variables: [], value: TypeOf(DefId(0:7 ~ foo[317d]::unsafely_do_the_thing[0]), UserSubsts { substs: [Const { ty: for<'r> fn(&'r std::ffi::CStr) -> usize, val: Unevaluated(DefId(0:14 ~ foo[317d]::main[0]::{{constant}}[0]), [], None) }], user_self_ty: None }) }, span: foo.rs:11:9: 11:53, inferred_ty: unsafe fn(*const i8) -> usize {unsafely_do_the_thing::<{safely_do_the_thing as for<'r> fn(&'r std::ffi::CStr) -> usize}>} }): bad user type AscribeUserType(unsafe fn(*const i8) -> usize {unsafely_do_the_thing::<{safely_do_the_thing as for<'r> fn(&'r std::ffi::CStr) -> usize}>}, DefId(0:7 ~ foo[317d]::unsafely_do_the_thing[0]) UserSubsts { substs: [Const { ty: for<'r> fn(&'r std::ffi::CStr) -> usize, val: Unevaluated(DefId(0:14 ~ foo[317d]::main[0]::{{constant}}[0]), [], None) }], user_self_ty: None }): NoSolution

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:366:17
Backtrace

   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1537
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:481
  12: std::panicking::begin_panic
  13: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
  14: core::ptr::drop_in_place
  15: <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop
  16: core::ptr::drop_in_place
  17: rustc_interface::interface::run_compiler_in_existing_thread_pool
  18: scoped_tls::ScopedKey<T>::set
  19: rustc_ast::attr::with_globals

@jplatte jplatte added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 19, 2020
@lcnr lcnr added A-const-generics Area: const generics (parameters and arguments) F-const_generics `#![feature(const_generics)]` labels May 19, 2020
@jonas-schievink jonas-schievink added the requires-nightly This issue requires a nightly compiler in some way. label May 19, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label May 20, 2020
@tones111
Copy link

This is my first time using cargo-bisect-rustc and it's fantastic. It identified the regression as...

searched nightlies: from nightly-2020-02-13 to nightly-2020-05-14
regressed nightly: nightly-2020-03-20
searched commits: from f509b26 to f4c675c
regressed commit: 57e1da5

bisected with cargo-bisect-rustc v0.5.2

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --test-dir=ice --start=2020-02-13 --end=2020-05-14

@jplatte
Copy link
Contributor Author

jplatte commented May 27, 2020

57e1da5 is a rollup commit. The only PR which was part of that and (to me) looks like it could have caused this issue is #69189 .

@JohnTitor
Copy link
Member

Triage: the const_compare_raw_pointers feature was removed by #73398 and the ICE no longer occurs with the latest nightly.

@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jun 27, 2020
@bors bors closed this as completed in 2c1b732 Jun 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-const_generics `#![feature(const_generics)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants