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: Unexpected panic in libcollections/vec.rs #42679

Closed
Robbepop opened this issue Jun 15, 2017 · 1 comment
Closed

ICE: Unexpected panic in libcollections/vec.rs #42679

Robbepop opened this issue Jun 15, 2017 · 1 comment

Comments

@Robbepop
Copy link
Contributor

Robbepop commented Jun 15, 2017

I was editing the following code when the bug appeared:

fn transform_bvult(&mut self, mut ult: Lt) -> Expr {
	self.transform_assign(&mut ult.left);
	self.transform_assign(&mut ult.right);

	// Symbolic contradiction: `(< x x)` to `false`
	if ult.left == ult.right {
		return Expr::boolconst(false)
	}

	match (ult.left, ult.right) {

		// - `(< x (-y))` to `(< y x)`
		(left, box Expr::Neg(right)) => {
			Expr::bvult(left.ty(), right.inner, left)
		}

		// - `(< (-x) y)` to `(< y x)`
		(box Expr::Neg(left), right) => {
			Expr::bvult(left.ty(), right, left.inner)

		}

		// - `(< (-x) (-y))` to `(< x y)`
		(box Expr::Neg(left), box Expr::Neg(right)) => {
			Expr::bvult(left.ty(), left.inner, right.inner)
		}

		// Constant evaluation
		// (Expr::BitVecConst(left), Expr::BitVecConst(right)) => {
			// TODO: `x < y where x < y and x,y consteval => true`
			// TODO: `x < y where not(x < y) and x,y consteval => false`
		// }

		// Do nothing since no simplification pattern matches
		_ => {
			ult.into_expr()
		}
	}
}

Apparently swapping

// - `(< (-x) (-y))` to `(< x y)`
(box Expr::Neg(left), box Expr::Neg(right)) => {
	Expr::bvult(left.ty(), left.inner, right.inner)
}

To the front of the match expression results in a sane compile error which is equally unfortunate to me since nothing moved in theory when the default case triggers.

error[E0382]: use of partially moved value: `ult`
   --> src/ast/simplifier.rs:413:5
    |
387 | 		match (ult.left, ult.right) {
    | 		       -------- value moved here
...
413 | 				ult.into_expr()
    | 		  ^^^ value used here after move
    |
    = note: move occurs because `ult.left` has type `std::boxed::Box<ast::variants::Expr>`, which does not implement the `Copy` trait

error: aborting due to previous error(s)

Output with RUST_BACKTRACE=1

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

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', /checkout/src/libcollections/vec.rs:1561
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:60
             at /checkout/src/libstd/panicking.rs:355
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:365
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:549
   5: std::panicking::begin_panic
             at /checkout/src/libstd/panicking.rs:511
   6: std::panicking::begin_panic_fmt
             at /checkout/src/libstd/panicking.rs:495
   7: rust_begin_unwind
             at /checkout/src/libstd/panicking.rs:471
   8: core::panicking::panic_fmt
             at /checkout/src/libcore/panicking.rs:69
   9: core::panicking::panic_bounds_check
             at /checkout/src/libcore/panicking.rs:56
  10: rustc_const_eval::_match::specialize
  11: rustc_const_eval::_match::is_useful_specialized
  12: rustc_const_eval::_match::is_useful::{{closure}}
  13: <core::option::Option<T>>::map
  14: rustc_const_eval::_match::is_useful
  15: rustc_const_eval::_match::is_useful_specialized
  16: rustc_const_eval::_match::is_useful::{{closure}}
  17: <core::option::Option<T>>::map
  18: rustc_const_eval::_match::is_useful
  19: rustc_const_eval::_match::is_useful_specialized
  20: rustc_const_eval::_match::is_useful::{{closure}}
  21: <core::option::Option<T>>::map
  22: rustc_const_eval::_match::is_useful
  23: <rustc_const_eval::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  24: <rustc_const_eval::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  25: <rustc_const_eval::check_match::OuterVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_fn
  26: rustc::hir::intravisit::walk_impl_item
  27: rustc_const_eval::check_match::check_crate
  28: rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}
  29: rustc_driver::driver::phase_3_run_analysis_passes
  30: rustc_driver::driver::compile_input
  31: rustc_driver::run_compiler

Output with RUST_BACKTRACE=full

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

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', /checkout/src/libcollections/vec.rs:1561
stack backtrace:
   0:     0x7fdc4be1cee3 - std::sys::imp::backtrace::tracing::imp::unwind_backtrace::hf6993ec76a3b39d8
                               at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1:     0x7fdc4be18504 - std::sys_common::backtrace::_print::h3d630ba2218f7ec3
                               at /checkout/src/libstd/sys_common/backtrace.rs:71
   2:     0x7fdc4be2a82a - std::panicking::default_hook::{{closure}}::hd0df6de62c549847
                               at /checkout/src/libstd/sys_common/backtrace.rs:60
                               at /checkout/src/libstd/panicking.rs:355
   3:     0x7fdc4be2a27d - std::panicking::default_hook::h9bbcc81c50b40ea3
                               at /checkout/src/libstd/panicking.rs:365
   4:     0x7fdc4be2ac3b - std::panicking::rust_panic_with_hook::hcb9f41173fe183d3
                               at /checkout/src/libstd/panicking.rs:549
   5:     0x7fdc4be2aac4 - std::panicking::begin_panic::h6af6db04028173d3
                               at /checkout/src/libstd/panicking.rs:511
   6:     0x7fdc4be2aa49 - std::panicking::begin_panic_fmt::h2ea6b56a88fe4f9f
                               at /checkout/src/libstd/panicking.rs:495
   7:     0x7fdc4be2a9d7 - rust_begin_unwind
                               at /checkout/src/libstd/panicking.rs:471
   8:     0x7fdc4be675dd - core::panicking::panic_fmt::h883a028e9f4b4457
                               at /checkout/src/libcore/panicking.rs:69
   9:     0x7fdc4be67588 - core::panicking::panic_bounds_check::hc3c2775988732c0b
                               at /checkout/src/libcore/panicking.rs:56
  10:     0x7fdc4a2b34ad - rustc_const_eval::_match::specialize::hadc7768d150b8c58
  11:     0x7fdc4a2b0be3 - rustc_const_eval::_match::is_useful_specialized::hdb71f059cfe9dea5
  12:     0x7fdc4a2b03fe - rustc_const_eval::_match::is_useful::{{closure}}::ha30ce4b8498e1202
  13:     0x7fdc4a28e88f - <core::option::Option<T>>::map::ha82a0cc47260c3a2
  14:     0x7fdc4a2adb7a - rustc_const_eval::_match::is_useful::h9052c30b8ec0f26e
  15:     0x7fdc4a2b0c34 - rustc_const_eval::_match::is_useful_specialized::hdb71f059cfe9dea5
  16:     0x7fdc4a2b03fe - rustc_const_eval::_match::is_useful::{{closure}}::ha30ce4b8498e1202
  17:     0x7fdc4a28e88f - <core::option::Option<T>>::map::ha82a0cc47260c3a2
  18:     0x7fdc4a2adb7a - rustc_const_eval::_match::is_useful::h9052c30b8ec0f26e
  19:     0x7fdc4a2b0c34 - rustc_const_eval::_match::is_useful_specialized::hdb71f059cfe9dea5
  20:     0x7fdc4a2b03fe - rustc_const_eval::_match::is_useful::{{closure}}::ha30ce4b8498e1202
  21:     0x7fdc4a28e88f - <core::option::Option<T>>::map::ha82a0cc47260c3a2
  22:     0x7fdc4a2adb7a - rustc_const_eval::_match::is_useful::h9052c30b8ec0f26e
  23:     0x7fdc4a2b530d - <rustc_const_eval::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr::h6e23fe3a012213fd
  24:     0x7fdc4a2b496b - <rustc_const_eval::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr::h6e23fe3a012213fd
  25:     0x7fdc4a2b3ac6 - <rustc_const_eval::check_match::OuterVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_fn::h6c18c5eb9d1d2370
  26:     0x7fdc4a294ec7 - rustc::hir::intravisit::walk_impl_item::h8d26ab20edc8822c
  27:     0x7fdc4a2b41f7 - rustc_const_eval::check_match::check_crate::h53dfb4d18dc8c3c9
  28:     0x7fdc4c1b96f8 - rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::h68eccaf0b2f82b34
  29:     0x7fdc4c1ab2ef - rustc_driver::driver::phase_3_run_analysis_passes::hbb243e50bc4b822e
  30:     0x7fdc4c18d610 - rustc_driver::driver::compile_input::h6125b69645e50cce
  31:     0x7fdc4c1d8466 - rustc_driver::run_compiler::hc6d7ae0444eeb671
  32:     0x7fdc4c0fb9ab - std::sys_common::backtrace::__rust_begin_short_backtrace::hf40d79e5a79af0b6
  33:     0x7fdc4be33e8a - __rust_maybe_catch_panic
                               at /checkout/src/libpanic_unwind/lib.rs:98
  34:     0x7fdc4c1209a0 - <F as alloc::boxed::FnBox<A>>::call_box::hd023aca2401e451f
  35:     0x7fdc4be29455 - std::sys::imp::thread::Thread::new::thread_start::h9e7dc9c59c04ba25
                               at /checkout/src/liballoc/boxed.rs:658
                               at /checkout/src/libstd/sys_common/thread.rs:21
                               at /checkout/src/libstd/sys/unix/thread.rs:84
  36:     0x7fdc47355296 - start_thread
  37:     0x7fdc4bae325e - __clone
  38:                0x0 - <unknown>
@tirr-c
Copy link
Contributor

tirr-c commented Jun 17, 2017

Minimal testcase that I found: https://play.rust-lang.org/?gist=e5f4ef65f86afc84b1eca43ac545c3ec&version=nightly&backtrace=1


Matching like this is fine:

match (a, b) {
    (box Test::Foo(x), box Test::Bar(y)) => println!("Foo {}, Bar {}", x, y),
    _ => println!("Some other things"),
}

This is also fine:

match (a, b) {
    (a, box Test::Bar(y)) => println!("Some other {:?}, Bar {}", a, y),
    (box a, b) => println!("Some unboxed {:?}, some boxed {:?}", a, b),
}

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Jun 18, 2017
Use T as the subpattern type of Box<T>

The subpattern type of boxes being nil does not make sense because of box patterns. They should have their inner type as the subpattern type.

Fixes rust-lang#42679, which describes ICE caused by the bug.
frewsxcv added a commit to frewsxcv/rust that referenced this issue Jun 18, 2017
Use T as the subpattern type of Box<T>

The subpattern type of boxes being nil does not make sense because of box patterns. They should have their inner type as the subpattern type.

Fixes rust-lang#42679, which describes ICE caused by the bug.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants