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: MIR must not use Struct(NodeId(42)) (which refers to a local ID) #38180

Closed
cedrickcooke opened this issue Dec 5, 2016 · 6 comments
Closed
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@cedrickcooke
Copy link

I'm getting an ICE when trying to compile my reimplementation of C#'s decimal type. I've trimmed it down to the following (smallest I could make it ICE without actually writing new code).

#![feature(const_fn)]
extern crate extprim;
use extprim::u128::u128;
pub struct Decimal (u128);
const DECIMAL_BITS_SIGN: u128 = u128::from_parts(0x80000000_00000000, 0x00000000_00000000);
impl Decimal {
    /// Returns -1 if the decimal is negative, or 1 if it is 0 or positive
    pub fn get_signum_i8(self) -> i8 {
        match self.0 & DECIMAL_BITS_SIGN {
            DECIMAL_BITS_SIGN => -1,
            _                 =>  1
        }
    }
}

As far as I can tell this should have been an error anyways (I don't think you're able to match against stuctures like this?). Everything compiles and runs as expected if I use a if a == DECIMAL_BITS_SIGN => -1, which is good. But still, the original form gave me the message to report bugs, so here I am. Didn't see an existing issue, although I'll admit I'm no good at searching.

error: internal compiler error: ../src/librustc_trans/mir/constant.rs:98: MIR must not use `Struct(NodeId(42))` (which refers to a local ID)

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

Meta

rustc --version --verbose:

rustc 1.15.0-nightly (ebeee0e27 2016-12-04)
binary: rustc
commit-hash: ebeee0e27e32e212979d9f38d285b1dc2816cd0a
commit-date: 2016-12-04
host: x86_64-unknown-linux-gnu
release: 1.15.0-nightly
LLVM version: 3.9

Backtrace:

thread 'rustc' panicked at 'Box<Any>', ../src/librustc_errors/lib.rs:423
stack backtrace:
   1:     0x7fa9f43c07ba - std::sys::imp::backtrace::tracing::imp::write::hbea47d9dd19b523c
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:42
   2:     0x7fa9f43cf68f - std::panicking::default_hook::{{closure}}::h6875a2976258b020
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:247
   3:     0x7fa9f43cf22d - std::panicking::default_hook::h88ffbc5922643264
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:257
   4:     0x7fa9f43cfb37 - std::panicking::rust_panic_with_hook::hc790e47d4ecc86cd
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:451
   5:     0x7fa9ecdb868a - std::panicking::begin_panic::h264cdc75d51b518b
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:413
   6:     0x7fa9ecdcb3ad - rustc_errors::Handler::bug::h620f7270292f0095
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_errors/lib.rs:423
   7:     0x7fa9f1723951 - rustc::session::opt_span_bug_fmt::{{closure}}::h4a9b70c3df8b4b3a
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/session/mod.rs:783
   8:     0x7fa9f172376e - rustc::session::opt_span_bug_fmt::h7d83586c6e2c7ae6
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/ty/context.rs:1062
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/session/mod.rs:779
   9:     0x7fa9f17233d2 - rustc::session::bug_fmt::he2d2f00a4afa9d1e
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/session/mod.rs:763
  10:     0x7fa9f362185d - rustc_trans::mir::constant::Const::from_constval::h33060e9b972aae5f
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/mir/constant.rs:98
  11:     0x7fa9f36292eb - rustc_trans::mir::constant::<impl rustc_trans::mir::MirContext<'bcx, 'tcx>>::trans_constant::hf65f3ef36c4ae551
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/mir/constant.rs:975
  12:     0x7fa9f362b31c - rustc_trans::mir::operand::<impl rustc_trans::mir::MirContext<'bcx, 'tcx>>::trans_operand::h78fe026f72924eaf
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/mir/operand.rs:232
  13:     0x7fa9f362ebe8 - rustc_trans::mir::rvalue::<impl rustc_trans::mir::MirContext<'bcx, 'tcx>>::trans_rvalue_operand::h4c3853775a6b1e20
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/mir/rvalue.rs:392
  14:     0x7fa9f361a83c - rustc_trans::mir::block::<impl rustc_trans::mir::MirContext<'bcx, 'tcx>>::trans_block::h5297e1a9e17de5f2
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/mir/statement.rs:39
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/mir/block.rs:104
  15:     0x7fa9f3618816 - rustc_trans::mir::trans_mir::h66a6eca5084c2485
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/mir/mod.rs:302
  16:     0x7fa9f3634e4e - rustc_trans::trans_item::TransItem::define::h88bbe0179f734cd1
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/base.rs:1054
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/trans_item.rs:88
  17:     0x7fa9f35aec19 - rustc_trans::base::trans_crate::h6e0b0bf1b66798ce
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/base.rs:1636
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/dep_graph/graph.rs:77
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/base.rs:1634
  18:     0x7fa9f4780b8d - rustc_driver::driver::phase_4_translate_to_llvm::h48ed91c172294403
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_driver/driver.rs:1046
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/util/common.rs:34
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_driver/driver.rs:1044
  19:     0x7fa9f475138f - rustc_driver::driver::compile_input::{{closure}}::hf13172fc4e5a2f4d
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_driver/driver.rs:205
  20:     0x7fa9f4779f81 - rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::hd97ec26bf3a98036
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_driver/driver.rs:992
  21:     0x7fa9f475f518 - rustc_driver::driver::phase_3_run_analysis_passes::h6d446abb74c09795
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/ty/context.rs:1033
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/thread/local.rs:245
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/ty/context.rs:1030
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/ty/context.rs:1017
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/thread/local.rs:245
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/ty/context.rs:1014
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/ty/context.rs:782
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_driver/driver.rs:866
  22:     0x7fa9f474f2c2 - rustc_driver::driver::compile_input::h8e119234b60571d5
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_driver/driver.rs:172
  23:     0x7fa9f4795308 - rustc_driver::run_compiler::h57c4f233cd1a0c04
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_driver/lib.rs:221
  24:     0x7fa9f46af8d8 - std::panicking::try::do_call::hf679f17bf3b43b0b
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_driver/lib.rs:1117
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_driver/lib.rs:137
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_driver/lib.rs:1051
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panic.rs:295
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:356
  25:     0x7fa9f43da07a - __rust_maybe_catch_panic
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libpanic_unwind/lib.rs:97
  26:     0x7fa9f46d2448 - <F as alloc::boxed::FnBox<A>>::call_box::h21b5b32059700da6
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:332
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panic.rs:351
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/thread/mod.rs:287
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/liballoc/boxed.rs:595
  27:     0x7fa9f43ce4f4 - std::sys::imp::thread::Thread::new::thread_start::h8084b1107992ae5b
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/liballoc/boxed.rs:605
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/sys_common/thread.rs:21
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/sys/unix/thread.rs:84
  28:     0x7fa9ec548183 - start_thread
  29:     0x7fa9f407a37c - clone
  30:                0x0 - <unknown>
@Stebalien
Copy link
Contributor

/cc @eddyb

@eddyb
Copy link
Member

eddyb commented Dec 5, 2016

I think this was some change to the existing AST-based const_eval - MIR building should blacklist such "constant values" and instead rely on having the MIR of the constant available (which is always the case).
cc @oli-obk

@sanxiyn sanxiyn added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Dec 7, 2016
@SergioBenitez
Copy link
Contributor

Ran into this myself. Here is the shortest bit of code I could find that exhibits this error:

#![feature(const_fn)]
#![feature(associated_consts)]

#[derive(PartialEq, Eq)]
struct Thing {
    num: u8,
}

impl Thing {
    const fn new(num: u8) -> Thing {
        Thing { num: num }
    }
    
    const ZERO: Thing = Thing::new(0);
}

fn main() {
    let thing = Thing { num: 0 };
    
    match Some(thing) {
        Some(Thing::ZERO) => println!("Hi"),
        _ => println!("Hello")
    }
}

The ICE seems to only occur when a matched against constant comes from a const fn call.

@oli-obk
Copy link
Contributor

oli-obk commented Dec 14, 2016

duplicate of #29928 only related. Yea this is a MIR-only thing... Should be easy enough to fix

@Mark-Simulacrum
Copy link
Member

Updated backtrace:

error: internal compiler error: src/librustc_const_eval/_match.rs:246: bad constructor ConstantValue(Struct({num(89): Integral(U8(0))})) for adt Thing

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: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:473
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
...
  13: rustc_const_eval::_match::Constructor::variant_index_for_adt
             at /rust/src/librustc_const_eval/_match.rs:246
  14: rustc_const_eval::_match::constructor_sub_pattern_tys
             at /rust/src/librustc_const_eval/_match.rs:777
  15: rustc_const_eval::_match::is_useful_specialized
             at /rust/src/librustc_const_eval/_match.rs:673
  16: core::ops::impls::<impl core::ops::FnOnce<A> for &'a mut F>::call_once
             at /rust/src/librustc_const_eval/_match.rs:585
             at /rust/src/libcore/ops.rs:2711
  17: <&'a mut I as core::iter::iterator::Iterator>::next
             at /rust/src/libcore/option.rs:392
             at /rust/src/libcore/iter/mod.rs:1011
             at /rust/src/libcore/iter/iterator.rs:2202
  18: rustc_const_eval::_match::is_useful
             at /rust/src/libcore/iter/iterator.rs:1489
             at /rust/src/librustc_const_eval/_match.rs:584
  19: rustc_const_eval::_match::is_useful_specialized
             at /rust/src/librustc_const_eval/_match.rs:686
  20: core::ops::impls::<impl core::ops::FnOnce<A> for &'a mut F>::call_once
             at /rust/src/librustc_const_eval/_match.rs:585
             at /rust/src/libcore/ops.rs:2711
  21: <&'a mut I as core::iter::iterator::Iterator>::next
             at /rust/src/libcore/option.rs:392
             at /rust/src/libcore/iter/mod.rs:1011
             at /rust/src/libcore/iter/iterator.rs:2202
  22: rustc_const_eval::_match::is_useful
             at /rust/src/libcore/iter/iterator.rs:1489
             at /rust/src/librustc_const_eval/_match.rs:584
  23: rustc_const_eval::check_match::check_arms
             at /rust/src/librustc_const_eval/check_match.rs:316
  24: rustc_const_eval::_match::MatchCheckCtxt::create_and_enter
             at /rust/src/librustc_const_eval/check_match.rs:180
             at /rust/src/librustc_const_eval/_match.rs:168
  25: rustc_const_eval::check_match::MatchVisitor::check_match
             at /rust/src/librustc_const_eval/check_match.rs:158
  26: <rustc_const_eval::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
             at /rust/src/librustc_const_eval/check_match.rs:82
  27: <rustc_const_eval::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_body
             at /rust/src/librustc_const_eval/check_match.rs:102
  28: <rustc_const_eval::check_match::OuterVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_fn
             at /rust/src/librustc_const_eval/check_match.rs:51
  29: rustc::hir::intravisit::walk_item
             at /rust/src/librustc/hir/intravisit.rs:457
  30: rustc::hir::Crate::visit_all_item_likes
             at /rust/src/librustc/hir/mod.rs:512
  31: rustc_const_eval::check_match::check_crate
             at /rust/src/librustc_const_eval/check_match.rs:61
  32: rustc::util::common::time
             at /rust/src/librustc_driver/driver.rs:992
             at /rust/src/librustc/util/common.rs:48
  33: <std::thread::local::LocalKey<T>>::with
             at /rust/src/librustc_driver/driver.rs:990
             at /rust/src/librustc/ty/context.rs:915
             at /rust/src/libstd/thread/local.rs:265
  34: rustc::ty::context::tls::enter
             at /rust/src/librustc/ty/context.rs:912
  35: <std::thread::local::LocalKey<T>>::with
             at /rust/src/librustc/ty/context.rs:899
             at /rust/src/libstd/thread/local.rs:265
  36: rustc::ty::context::tls::enter_global
             at /rust/src/librustc/ty/context.rs:896
  37: rustc::ty::context::TyCtxt::create_and_enter
             at /rust/src/librustc/ty/context.rs:706
  38: rustc_driver::driver::phase_3_run_analysis_passes
             at /rust/src/librustc_driver/driver.rs:942
  39: rustc_driver::driver::compile_input
             at /rust/src/librustc_driver/driver.rs:172
  40: rustc_driver::run_compiler
             at /rust/src/librustc_driver/lib.rs:224

@oli-obk
Copy link
Contributor

oli-obk commented Mar 9, 2018

This has been fixed (works now without error or ICE)

@oli-obk oli-obk closed this as completed Mar 9, 2018
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. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

7 participants