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

Unwrap on a None in librustc_mir/borrow_check/region_infer when using rustc_args_required_const #74599

Closed
SuperTails opened this issue Jul 21, 2020 · 8 comments
Labels
C-bug Category: This is a bug. 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

@SuperTails
Copy link

Code

Minimization by @Kixiron

#![feature(rustc_attrs)]

extern "C" {
    #[rustc_args_required_const(0, 1)]
    pub fn print_raw(data: *const u8, len: usize);
}

pub enum Stmt {
    Print {},
    Let {},
    Loop {}
}

pub fn interpret() {
    match (Stmt::Print {}) {
        Stmt::Let {} => {
            [()].iter().find(|v| *v == &());
        }
        
        Stmt::Print {} => {
            print_raw(b"hello".as_ptr(), 5);
        }

        Stmt::Loop {} => {}
    }
}

Meta

This can only be built on nightly, since it requires an internal rustc attribute on print_raw.

rustc +nightly --version --verbose:

rustc 1.46.0-nightly (346aec9b0 2020-07-11)
binary: rustc
commit-hash: 346aec9b02f3c74f3fce97fd6bda24709d220e49
commit-date: 2020-07-11
host: x86_64-unknown-linux-gnu
release: 1.46.0-nightly
LLVM version: 10.0

Error output

When run with RUST_BACKTRACE=1 rustc +nightly main.rs

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', src/librustc_mir/borrow_check/region_infer/mod.rs:2109:35
stack backtrace:
 <... shown below ...>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.46.0-nightly (346aec9b0 2020-07-11) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_borrowck] borrow-checking `main`
#1 [analysis] running analysis passes on this crate
end of query stack
Backtrace

stack 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:1076
   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:217
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:530
  12: rust_begin_unwind
             at src/libstd/panicking.rs:437
  13: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
  14: core::panicking::panic
             at src/libcore/panicking.rs:50
  15: rustc_mir::borrow_check::region_infer::RegionInferenceContext::find_outlives_blame_span
  16: rustc_mir::borrow_check::do_mir_borrowck
  17: rustc_infer::infer::InferCtxtBuilder::enter
  18: rustc_mir::borrow_check::mir_borrowck
  19: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_borrowck>::compute
  20: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  21: rustc_query_system::query::plumbing::get_query_impl
  22: rustc_query_system::query::plumbing::ensure_query_impl
  23: rustc_session::utils::<impl rustc_session::session::Session>::time
  24: rustc_interface::passes::analysis
  25: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  26: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  27: rustc_query_system::query::plumbing::get_query_impl
  28: rustc_middle::ty::context::tls::enter_global
  29: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  30: rustc_span::with_source_map
  31: rustc_interface::interface::create_compiler_and_run
  32: scoped_tls::ScopedKey<T>::set

@SuperTails SuperTails 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 Jul 21, 2020
@jonas-schievink jonas-schievink added the requires-nightly This issue requires a nightly compiler in some way. label Jul 21, 2020
@Kixiron
Copy link
Member

Kixiron commented Jul 21, 2020

The absolute smallest I was able to get it is this (playground)

#![feature(rustc_attrs)]

extern {
    // The external function & its parameters don't matter
    #[rustc_args_required_const(0, 1)]
    pub fn print_raw(data: *const u8, len: usize);
}

pub enum A {
    B {},
    C {},
    D {},
}

fn main() {
    // The variant used here doesn't matter
    match (A::B {}) {
        A::B {} => {
            [()].iter().find(|v| *v == &());
        }
        A::C {} => {
            print_raw(b"hello".as_ptr(), 5);
        }
        A::D {} => {}
    }
}

The specific external function doesn't seem to matter, nor do any variable names

The panicking line of code is here, as the comment above it says, "Maybe everything is in the same SCC or something?"

@mibac138
Copy link
Contributor

mibac138 commented Jul 21, 2020

Further minimized (playground) minimized the wrong ICE, see here for correct minimization or see #74608 for bug report.

#![feature(rustc_attrs)]

#[rustc_args_required_const(1)]
fn intrinsic(a: u8){}

fn main() {
    intrinsic(1);
}

It appears this issue happens when in #[rustc_args_required_const(x)], x is greater than the amount of a function's parameters

@SuperTails
Copy link
Author

But in the original example, that's not true--

extern "C" {
    #[rustc_args_required_const(0, 1)]
    pub fn print_raw(data: *const u8, len: usize);
}

// later...
print_raw(b"hello".as_ptr(), 5);

There are two parameters, and in the code I use both of them, yet the issue still seems to occur.
Same outcome, different cause?

@mibac138
Copy link
Contributor

I might've worded my response poorly, however I still stand my ground. I believe that whenever any of the indexes in rustc_args_required_const exceeds the amount of parameters a function has, it will ICE. So, for example

#[rustc_args_required_const(0, 1)]
fn x(a: u8, b:u8) {} // won't error as 0 refers to `a`, and 1 refers to `b`

#[rustc_args_required_const(0, 1)]
fn y(a: u8) {} // will error as 1 refers to nonexistent parameter, i.e. parameter 1 doesn't exist (only parameter 0 exists)

Does this match with your experience?

@Kixiron
Copy link
Member

Kixiron commented Jul 21, 2020

This ICE's, it's the original example

#![feature(rustc_attrs)]

extern "C" {
    #[rustc_args_required_const(0, 1)]
    pub fn print_raw(data: *const u8, len: usize);
}

pub enum Stmt {
    Print {},
    Let {},
    Loop {}
}

pub fn interpret() {
    match (Stmt::Print {}) {
        Stmt::Let {} => {
            [()].iter().find(|v| *v == &());
        }
        
        Stmt::Print {} => {
            print_raw(b"hello".as_ptr(), 5);
        }

        Stmt::Loop {} => {}
    }
}

The indices line up with the function parameters, yet it still ICE's

extern "C" {
    #[rustc_args_required_const(0, 1)]
    pub fn print_raw(data: *const u8, len: usize);
}

@mibac138
Copy link
Contributor

mibac138 commented Jul 21, 2020

Oh sorry, turns out I have misunderstood what @SuperTails meant. I guess I have accidentally found another ICE then.

Edit: A bit minimized example this time of the correct ICE (playground)

#![feature(rustc_attrs)]

#[rustc_args_required_const(0)]
pub fn print_raw(_: *const u8) {}

fn interpret() {
    match true {
        true => {
            [()].iter().filter(|_| true);
        }
        false => {
            print_raw("".as_ptr());
        }
        _ => {}
    };
}

@isabelmu
Copy link
Contributor

isabelmu commented Jan 22, 2021

The snippet in the original report starts ICE'ing on nightly-2019-10-05. Tracked it down to 2180c24. (EDIT: same for the minimized example.)

@Alexendoo
Copy link
Member

rustc_args_required_const has been removed - #85110

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. 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

No branches or pull requests

7 participants