Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

save-analysis with cgmath leads to ICE #41478

Closed
ishitatsuyuki opened this issue Apr 23, 2017 · 5 comments
Closed

save-analysis with cgmath leads to ICE #41478

ishitatsuyuki opened this issue Apr 23, 2017 · 5 comments
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@ishitatsuyuki
Copy link
Contributor

$ rustc -vV
rustc 1.18.0-dev (252d3da8a 2017-04-22)
binary: rustc
commit-hash: 252d3da8a6c715ccafcf77d83b826f6fb899cfe5
commit-date: 2017-04-22
host: x86_64-unknown-linux-gnu
release: 1.18.0-dev
LLVM version: 4.0
rustc --crate-name cgmath ~/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/cgmath-0.13.0/src/lib.rs --color never --crate-type lib --emit=dep-info,metadata -C debuginfo=2 --cfg feature=\"rustc-serialize\" --cfg feature=\"default\" -C metadata=d3371898a27ffcd7 -C extra-filename=-d3371898a27ffcd7 --out-dir target/rls/debug/deps -L dependency=target/rls/debug/deps --extern rustc_serialize=target/rls/debug/deps/librustc_serialize-11a16e191609bcdb.rmeta --extern approx=target/rls/debug/deps/libapprox-b3f7cf616ce926ae.rmeta --extern num_traits=target/rls/debug/deps/libnum_traits-4c2dc66d8816610d.rmeta --extern rand=target/rls/debug/deps/librand-d22275320cd9f6c2.rmeta --cap-lints allow -Zunstable-options -Zsave-analysis --error-format=json -Zcontinue-parse-after-error
error: internal compiler error: unexpected panic
... (omitted)
note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:329
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::_print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: std::panicking::rust_panic_with_hook
   5: std::panicking::begin_panic
   6: std::panicking::begin_panic_fmt
   7: rust_begin_unwind
   8: core::panicking::panic_fmt
   9: core::panicking::panic
  10: rustc_save_analysis::SaveContext::get_item_data
  11: <rustc_save_analysis::dump_visitor::DumpVisitor<'l, 'tcx, 'll, D> as syntax::visit::Visitor<'l>>::visit_item
  12: <rustc_save_analysis::dump_visitor::DumpVisitor<'l, 'tcx, 'll, D> as syntax::visit::Visitor<'l>>::visit_item
  13: <rustc_save_analysis::DumpHandler<'a> as rustc_save_analysis::SaveHandler>::save
  14: <rustc_driver::RustcDefaultCalls as rustc_driver::CompilerCalls<'a>>::build_controller::{{closure}}::{{closure}}
  15: <rustc_driver::RustcDefaultCalls as rustc_driver::CompilerCalls<'a>>::build_controller::{{closure}}
  16: rustc_driver::driver::compile_input::{{closure}}
  17: rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}
  18: rustc_driver::driver::phase_3_run_analysis_passes
  19: rustc_driver::driver::compile_input
  20: rustc_driver::run_compiler
  21: std::panicking::try::do_call
  22: __rust_maybe_catch_panic
  23: <F as alloc::boxed::FnBox<A>>::call_box
  24: std::sys::imp::thread::Thread::new::thread_start
  25: start_thread
  26: clone
@Mark-Simulacrum Mark-Simulacrum added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Apr 27, 2017
@ishitatsuyuki
Copy link
Contributor Author

@nrc would you like to take a look?

@ozkriff
Copy link

ozkriff commented Apr 29, 2017

+1

This stops me from using https://github.com/editor-rs/vscode-rust for ZoC's development:

image

@kennytm
Copy link
Member

kennytm commented May 1, 2017

Reduced, but not sure if it's the same bug, since it is a compile-fail case, but cgmath certainly is not.

// rustc -Zsave-analysis 1.rs
struct B<S> {
}
fn f<S>() -> B<S> {
    B{}
}
fn main() {
}

@kennytm
Copy link
Member

kennytm commented May 1, 2017

OK this should be the actual code causing the error.

Reduced case:

struct V<S>(S);
trait An {
    type U;
}
trait F<A> {
}
impl<A: An> F<A> for V<<A as An>::U> {
}

These are reduced from https://github.com/brendanzab/cgmath/blob/bfd9fc1e66dfa27713fbb7890159b2499826c4db/src/matrix.rs#L1136-L1149.

The panic comes from

span: sub_span.unwrap(),

The ICE no longer happens if V<<A as An>::U> is replaced by V<A::U>. So, rustgd/cgmath#410.

@kennytm
Copy link
Member

kennytm commented Aug 12, 2017

The ICE is changed to an error output like #43796 some time between 1.19 and 1.20. The output at the current nightly (1.21) for my reduced test case is:

$ rustc +nightly -Zsave-analysis --crate-type=lib -Adead_code 1.rs
ERROR:rustc_save_analysis::dump_visitor: Mis-calculated spans for path 'An::U'. Found 1 spans, expected 2. Found spans:
ERROR:rustc_save_analysis::dump_visitor:     'U' in 1.rs, line 7
ERROR:rustc_save_analysis::dump_visitor:     master span: 1.rs:7:24: 7:36: `<A as An>::U`

I think this bug should be turned into E-needstest, or be closed and the reduced test case be transferred to #43796.

kennytm added a commit to kennytm/rust that referenced this issue Aug 14, 2017
Use the `span` field in PathSegment and TyParam instead.

Fix rust-lang#43796. Close rust-lang#41478.
bors added a commit that referenced this issue Aug 14, 2017
…ochenkov

Fix "Mis-calculated spans" errors from `-Z save-analysis` + refactoring

Removed the path span extraction methods from `SpanUtils`:

* spans_with_brackets
* spans_for_path_segments
* spans_for_ty_params

Use the `span` fields in `PathSegment` and `TyParam` instead.

(Note that since it processes `ast::Path` not a qualified path (`hir::QPath` / `ast::QSelf`), UFCS path will be flattened: `<Foo as a::b::c::Trait>::D::E::F::g` will be seen as `a::b::c::Trait::D::E::F::g`.)

Fix #43796. Close #41478.

r? @nrc
# for free to join this conversation on GitHub. Already have an account? # 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

4 participants