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

Internal compiler error on nightly: 'index out of bounds' #48923

Closed
avl opened this issue Mar 10, 2018 · 36 comments
Closed

Internal compiler error on nightly: 'index out of bounds' #48923

avl opened this issue Mar 10, 2018 · 36 comments
Assignees
Labels
A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@avl
Copy link

avl commented Mar 10, 2018

I just got an internal compiler error. This happened after introducing a custom derive macro and using it on several structs. I'll try to narrow it down more, and will comment on this report if I make any progress.

Version

rustc 1.26.0-nightly (2789b067d 2018-03-06)
binary: rustc
commit-hash: 2789b067da2ac921b86199bde21dd231ace1da39
commit-date: 2018-03-06
host: x86_64-unknown-linux-gnu
release: 1.26.0-nightly
LLVM version: 6.0

Backtrace

thread 'rustc' panicked at 'index out of bounds: the len is 241450 but the index is 241450', /checkout/src/libcore/slice/mod.rs:871:14
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at libstd/sys_common/backtrace.rs:59
             at libstd/panicking.rs:207
   3: std::panicking::default_hook
             at libstd/panicking.rs:223
   4: core::ops::function::Fn::call
   5: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:403
   6: std::panicking::begin_panic_fmt
             at libstd/panicking.rs:349
   7: rust_begin_unwind
             at libstd/panicking.rs:325
   8: core::panicking::panic_fmt
             at libcore/panicking.rs:72
   9: core::panicking::panic_bounds_check
             at libcore/panicking.rs:58
  10: rustc::dep_graph::graph::DepGraph::with_task_impl
  11: rustc::ty::maps::<impl rustc::ty::maps::queries::crate_disambiguator<'tcx>>::force
  12: rustc::ty::maps::<impl rustc::ty::maps::queries::crate_disambiguator<'tcx>>::try_get
  13: rustc::ty::maps::TyCtxtAt::crate_disambiguator
  14: rustc::ty::maps::on_disk_cache::OnDiskCache::compute_cnum_map::{{closure}}::{{closure}}
  15: <std::collections::hash::map::HashMap<K, V, S> as core::iter::traits::Extend<(K, V)>>::extend
  16: rustc::dep_graph::graph::DepGraph::with_ignore
  17: rustc::ty::maps::on_disk_cache::OnDiskCache::load_diagnostics
  18: rustc::dep_graph::graph::DepGraph::try_mark_green
  19: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_mark_green_and_read
  20: rustc::ty::maps::<impl rustc::ty::maps::queries::target_features_enabled<'tcx>>::try_get
  21: rustc::ty::maps::TyCtxtAt::target_features_enabled
  22: <rustc::hir::check_attr::CheckAttrVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item
  23: rustc::hir::check_attr::check_crate
  24: rustc::ty::context::TyCtxt::create_and_enter
  25: rustc_driver::driver::compile_input
  26: rustc_driver::run_compiler

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.26.0-nightly (2789b067d 2018-03-06) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental -C target-cpu=native --crate-type lib

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `fractal`.

To learn more, run the command again with --verbose.
@cuviper cuviper added A-type-system Area: Type system 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. C-bug Category: This is a bug. labels Mar 10, 2018
@avl
Copy link
Author

avl commented Mar 10, 2018

Using:

CARGO_INCREMENTAL=0 cargo build

instead of just cargo build, seems to resolve the problem.

@avl
Copy link
Author

avl commented Mar 10, 2018

My program isn't correct, so I guess the problem is with some kind of diagnostics.

@avl
Copy link
Author

avl commented Mar 10, 2018

Ok, now that I've fixed the compilation errors, the program compiles ok with CARGO_INCREMENTAL=0 . It even appears to run correctly, but it still cannot be recompiled with CARGO_INCREMENTAL=1 .

It can be compiled with CARGO_INCREMENTAL=0
It can be compiled once (after "cargo clean"), with CARGO_INCREMENTAL=1
Subsequent compiles with CARGO_INCREMENTAL=1 crash, even after a whitespace-only change.

@avl
Copy link
Author

avl commented Mar 10, 2018

Ok, another lead: I was using my 'savefile' crate (which is on crates.io) with its custom-derive macro to derive an implementation of a trait called Serialize .I was also, in the crate which would not compile, using serde to derive its trait called Serialize. These are different traits. Perhaps the incremental compilation could not keep these two apart somehow? My immediate problem is solved, since I was trying out both serde and savefile, and never intended to actually use both simultaneously.

@Ameobea
Copy link

Ameobea commented Mar 13, 2018

I've got the same problem in a crate I'm developing. I'm also using serde and serde-derive. The error only seems to occur after a compilation fails due to type error or similar. Deleting the target/debug/incremental directory allow the crate to compile successfully.

@ExpHP
Copy link
Contributor

ExpHP commented Mar 15, 2018

This is tagged A-type-system, but #49065 shows another instance of this bug that crashed during trans. The common factor between the two is an index error in DepGraph, which can be resolved by disabling incremental compilation.

@michaelwoerister michaelwoerister added A-incr-comp Area: Incremental compilation and removed A-type-system Area: Type system labels Mar 16, 2018
@michaelwoerister
Copy link
Member

This looks indeed like a problem with incremental compilation.

@ExpHP
Copy link
Contributor

ExpHP commented Mar 16, 2018

@jjl @avl @Ameobea since the crash seems to at least be deterministic, can anyone share the code that reproduces the crash? (minimizing it would be a huge help as well, but simply having anything would be great at this point)

Barring that, you can also help by testing other nightlies to pinpoint when the problem first started occurring. (you can do rustup override set nightly-YYYY-MM-DD to use a nightly from a specific day)

@nikomatsakis
Copy link
Contributor

triage: P-high

@jjl
Copy link

jjl commented Mar 16, 2018

My code is not open source. I'm willing to share the code privately, but not publically on github, if we can come up with a way to do that.

@avl
Copy link
Author

avl commented Mar 16, 2018

I'm trying to minimize the program which causes the crash for me. I have come to where it seems to work if I remove a dependency I have upon another crate in the same workspace. Does the incremental compilation work "per crate", or is the cached intermediaries shared between crates? Is it reasonable that the bug could be triggered by code patterns in the combination of two crates where one depends on the other?

@avl
Copy link
Author

avl commented Mar 16, 2018

Hmm, minimizing is a bit tricky. After the error has been triggered once, almost any input will yield an ICE. For instance, completely clearing lib.rs in the offending crate would still trigger ICE. However, removing dependencies from Cargo.toml would make it work again. Maybe the intermediary state/cache is thrown away when changes are detected in Cargo.toml?

@avl
Copy link
Author

avl commented Mar 16, 2018

Ok, I'm making a lot of headway now :-) . Will have a minimal example here on github shortly.

@avl
Copy link
Author

avl commented Mar 16, 2018

Okay, actually, this program triggers the error:

#[macro_use]
extern crate serde_derive;

#[derive(Serialize)]
pub struct X {
pub x: f32,
}

#[derive(Serialize)]
pub struct Y {
pub y: f32,
}

If I use the following Cargo.toml:

[package]
name = "fractal"
version = "0.1.0"
authors = ["Anders Musikka [email protected]"]

[dependencies]
serde="1.0.28"
serde_derive="1.0.28"
savefile-derive="0.2.5"

But, to trigger an error, you need to:

1: cargo clean
2: cargo build
3: edit whitespace in lib.rs
4: cargo build # <- ICE here!

Sometimes, it seems I need to run steps 3 and 4 again to provoke ICE. Possibly non-deterministic, I'm not entirely sure.

@avl
Copy link
Author

avl commented Mar 16, 2018

Minimal example, including a convenient(?) crash.sh script:
https://github.com/avl/rust_ice_48923

@ExpHP
Copy link
Contributor

ExpHP commented Mar 16, 2018

How fascinating that even extern crate savefile_derive is not necessary! Indeed, I can confirm that it consistently crashes on recompile when savefile-derive is listed under [dependencies], and that it can be repeatedly compiled without issue if the dependency is removed.

It sounds to me like you are on to something about the derive_Serialize. I wonder if the other crashing projects might have multiple versions of serde_derive linked in?

@avl
Copy link
Author

avl commented Mar 17, 2018

Yeah, I thought that too! I (as a layperson) was also surprised that mentioning a crate in Cargo.toml could have an effect on compilation. Having multiple traits called Serialize is a bit suspicious, and having multiple serde versions seems like something that could the same situation to appear.

Hmm, but thinking about this a bit more: The savefile_derive crate is just a custom-derive macro crate. It doesn't actually define any traits, and it doesn't depend on the savefile crate which does define Serialize. So maybe it's actually proc_macro for a trait name that is the culprit, not the actual trait name itself (although these two are of course very related).

@avl
Copy link
Author

avl commented Mar 17, 2018

Ok, so I proceeded a bit further. If I reduce the savefile-derive crate 'lib.rs' into:

#![feature(proc_macro)]
extern crate proc_macro;

#[proc_macro_derive(Savefile, attributes(versions, versions_as, default_val, default_fn))]
pub fn savefile(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
panic!("Not implemented")
}

The problem still appears. So we can eliminate the theory of multiple Serialize-traits being the culprit. Instead it seems like simply linking to a custom-derive crate at all can trigger the problem.

@ExpHP
Copy link
Contributor

ExpHP commented Mar 17, 2018

Can you do that on the rust_issues_48923 repo? (you can put a minimized savefile-derive in that source tree and depend on it with savefile-derive = { path = "./savefile-derive" })

I tried repeating your experiment and am not able to reproduce it. Minimizing savefile_derive down to just that (with the Cargo.toml.orig from crates.io) and depending on it in rust_issues_48923 did not cause any crashes for me. (however, it also continued to build fine even if I changed the proc_macro_derive to Serialize, so your conclusion may still be correct)

(that said, serde_derive is of course also a procedural macro, and most people's projects are compiling fine, so there has got to be something more to it than merely "linking to a custom-derive" 🙂 )

@RandomInsano
Copy link
Contributor

RandomInsano commented Mar 17, 2018

I've hit a very similar problem on nightly while building the cc crate as a sub-dependency, but disabling incremental compilation makes no difference. Should this be filed in a different issue?

Notable oddities:

  • using no_std, in the main project
  • running on ARMv7

gcc version:

RandomInsano@chip-04:~/Documents/Code/pscontroller-rs/src$ cc --version
cc (Debian 4.9.2-10+deb8u1) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Full output

RandomInsano@chip-04:~/Documents/Code/pscontroller-rs/src$ rustc --version
rustc 1.26.0-nightly (55c984ee5 2018-03-16)
RandomInsano@chip-04:~/Documents/Code/pscontroller-rs/src$ cargo clean
RandomInsano@chip-04:~/Documents/Code/pscontroller-rs/src$ CARGO_INCREMENTAL=0 RUST_BACKTRACE=full cargo test --verbose
   Compiling unicode-xid v0.1.0
     Running `rustc --crate-name unicode_xid /home/RandomInsano/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/unicode-xid-0.1.0/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' -C metadata=1991908c4612c1c0 -C extra-filename=-1991908c4612c1c0 --out-dir /home/RandomInsano/Documents/Code/pscontroller-rs/target/debug/deps -L dependency=/home/RandomInsano/Documents/Code/pscontroller-rs/target/debug/deps --cap-lints allow`
   Compiling cc v1.0.8
     Running `rustc --crate-name cc /home/RandomInsano/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/cc-1.0.8/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=c045fdd855277bee -C extra-filename=-c045fdd855277bee --out-dir /home/RandomInsano/Documents/Code/pscontroller-rs/target/debug/deps -L dependency=/home/RandomInsano/Documents/Code/pscontroller-rs/target/debug/deps --cap-lints allow`
thread 'rustc' panicked at 'index out of bounds: the len is 4847291 but the index is 4847291', /checkout/src/libserialize/opaque.rs:259:21
stack backtrace:
   0: 0xb6c80667 - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h93b2fefcbf6912f6
                       at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: 0xb6c4f1eb - std::sys_common::backtrace::print::h8275cc4a0228025e
                       at libstd/sys_common/backtrace.rs:71
                       at libstd/sys_common/backtrace.rs:59
   2: 0xb6c6a457 - std::panicking::default_hook::{{closure}}::ha990f106491019b1
                       at libstd/panicking.rs:207
   3: 0xb6c6a0bf - std::panicking::default_hook::h1ab2d07a5322573d
                       at libstd/panicking.rs:223
   4: 0xb5a18137 - core::ops::function::Fn::call::hb910eaef0aecb065
   5: 0xb6c6a9cb - std::panicking::rust_panic_with_hook::h06fc1d87327d7e52
                       at libstd/panicking.rs:403
   6: 0xb6c6a7f3 - std::panicking::begin_panic_fmt::h1b61dff2ddab2600
                       at libstd/panicking.rs:349
   7: 0xb6c6a74b - rust_begin_unwind
                       at libstd/panicking.rs:325
   8: 0xb6cdab6f - core::panicking::panic_fmt::h67a7a8328d952f02
                       at libcore/panicking.rs:72
   9: 0xb6cdab23 - core::panicking::panic_bounds_check::h434bc36e56d90864
                       at libcore/panicking.rs:58
  10: 0xb6494b43 - serialize::serialize::Decoder::read_seq::hfd5771196e2a4d15
  11: 0xb6488767 - serialize::serialize::Decoder::read_struct::hf10cf5868951fa01
  12: 0xb64a8c63 - <rustc_metadata::decoder::DecodeContext<'a, 'tcx> as serialize::serialize::SpecializedDecoder<rustc::mir::interpret::AllocId>>::specialized_decode::h511731b3428098a3
  13: 0xb6477efb - serialize::serialize::Decoder::read_struct::h4ac607f9629c6909
  14: 0xb64a2463 - serialize::serialize::Decoder::read_enum::hbf203143f32403f7
  15: 0xb64a1757 - serialize::serialize::Decoder::read_enum::ha59c8e856fabf996
  16: 0xb649632f - serialize::serialize::Decoder::read_enum::h0ced95c27abbb786
  17: 0xb6497f9f - serialize::serialize::Decoder::read_enum::h349e7636a72a1bf6
  18: 0xb647508f - serialize::serialize::Decoder::read_struct::h2cc6da3b554b474e
  19: 0xb642eecf - <alloc::boxed::Box<T> as serialize::serialize::Decodable>::decode::h82bbbf14f32bf6fb
  20: 0xb64a4cbf - serialize::serialize::Decoder::read_enum::hdea19f36b5c31d62
  21: 0xb648eab3 - serialize::serialize::Decoder::read_seq::h42ae64e41bddab1e
  22: 0xb64a2f1f - serialize::serialize::Decoder::read_enum::hd21ad6388c600ca6
  23: 0xb6494ea7 - serialize::serialize::Decoder::read_enum::h04162e21b57d971a
  24: 0xb6483a7f - serialize::serialize::Decoder::read_struct::hc1701c750f0aab71
  25: 0xb648ee5b - serialize::serialize::Decoder::read_seq::h56e0898483a14ca7
  26: 0xb647bb1b - serialize::serialize::Decoder::read_struct::h75818a2537dc5cf5
  27: 0xb6494107 - serialize::serialize::Decoder::read_seq::heac0b0a9d8bae61b
  28: 0xb646d153 - <rustc::mir::Mir<'tcx> as serialize::serialize::Decodable>::decode::{{closure}}::h6a7f2382a57ec903
  29: 0xb6491cd7 - serialize::serialize::Decoder::read_seq::ha5867f7bfb039a0b
  30: 0xb646d253 - <rustc::mir::Mir<'tcx> as serialize::serialize::Decodable>::decode::{{closure}}::h6a7f2382a57ec903
  31: 0xb64f734b - rustc_metadata::decoder::<impl rustc_metadata::schema::Lazy<T>>::decode::h4478f672edc8a274
  32: 0xb63ea67f - rustc_metadata::cstore_impl::provide_extern::optimized_mir::hef17fb39368def9d
  33: 0xb593f76f - rustc::ty::maps::<impl rustc::ty::maps::queries::optimized_mir<'tcx>>::compute_result::hc8153a167fd2cc80
  34: 0xb563bf23 - rustc::dep_graph::graph::DepGraph::with_task_impl::h1f17613b988fb4f7
  35: 0xb56b817b - rustc_errors::Handler::track_diagnostics::h6f907ce7a064e0ae
  36: 0xb58b8557 - rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check::h89642d6b285a296b
  37: 0xb593f7f3 - rustc::ty::maps::<impl rustc::ty::maps::queries::optimized_mir<'tcx>>::force::hb839e3233a21d5c0
  38: 0xb593fd0f - rustc::ty::maps::<impl rustc::ty::maps::queries::optimized_mir<'tcx>>::try_get::h02048f96cd2d3418
  39: 0xb5900de7 - rustc::ty::maps::TyCtxtAt::optimized_mir::hefe786359add3d19
  40: 0xb58f1ae7 - rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::instance_mir::h1f2f8c01d42aa611
  41: 0xb5f573cf - rustc_mir::monomorphize::collector::collect_items_rec::ha798000c0ba6a115
  42: 0xb5f5703b - rustc_mir::monomorphize::collector::collect_items_rec::ha798000c0ba6a115
  43: 0xb5f5703b - rustc_mir::monomorphize::collector::collect_items_rec::ha798000c0ba6a115
  44: 0xb5f5703b - rustc_mir::monomorphize::collector::collect_items_rec::ha798000c0ba6a115
  45: 0xb5f5703b - rustc_mir::monomorphize::collector::collect_items_rec::ha798000c0ba6a115
  46: 0xb5f5703b - rustc_mir::monomorphize::collector::collect_items_rec::ha798000c0ba6a115
  47: 0xb5f5703b - rustc_mir::monomorphize::collector::collect_items_rec::ha798000c0ba6a115
  48: 0xb5f5703b - rustc_mir::monomorphize::collector::collect_items_rec::ha798000c0ba6a115
  49: 0xb5f5703b - rustc_mir::monomorphize::collector::collect_items_rec::ha798000c0ba6a115
  50: 0xb5f5703b - rustc_mir::monomorphize::collector::collect_items_rec::ha798000c0ba6a115
  51: 0xb5f5703b - rustc_mir::monomorphize::collector::collect_items_rec::ha798000c0ba6a115
  52: 0xb5f5703b - rustc_mir::monomorphize::collector::collect_items_rec::ha798000c0ba6a115
  53: 0xb5f5703b - rustc_mir::monomorphize::collector::collect_items_rec::ha798000c0ba6a115
  54: 0xb5f561fb - rustc_mir::monomorphize::collector::collect_crate_mono_items::h42ba49e83cce04e8
  55: 0xb160b1f3 - rustc::util::common::time::h36e2915d760802d3
  56: 0xb157d5f3 - rustc_trans::base::collect_and_partition_translation_items::hb00fda54eb793e4e
  57: 0xb5659243 - rustc::dep_graph::graph::DepGraph::with_task_impl::h8bf405f93ff5c5e3
  58: 0xb56b4b1b - rustc_errors::Handler::track_diagnostics::h60114bf68b72fde4
  59: 0xb58c5637 - rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check::hb32546aed983fc24
  60: 0xb59b0ccf - rustc::ty::maps::<impl rustc::ty::maps::queries::collect_and_partition_translation_items<'tcx>>::force::ha60bc632a0148e93
  61: 0xb59b134f - rustc::ty::maps::<impl rustc::ty::maps::queries::collect_and_partition_translation_items<'tcx>>::try_get::had2faba087de8a66
  62: 0xb5906137 - rustc::ty::maps::TyCtxtAt::collect_and_partition_translation_items::h68ae702fb87be5ef
  63: 0xb58ff5eb - rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::collect_and_partition_translation_items::h20d5713291984f0b
  64: 0xb157be8b - rustc_trans::base::trans_crate::h1a33bde112087c12
  65: 0xb1597a5f - <rustc_trans::LlvmTransCrate as rustc_trans_utils::trans_crate::TransCrate>::trans_crate::h635b3e99aaa549d9
  66: 0xb6de4f07 - rustc::util::common::time::h181240aad27d5e8a
  67: 0xb6dc9637 - rustc_driver::driver::phase_4_translate_to_llvm::hc89bfbd9ca36d741
  68: 0xb6e4a187 - rustc_driver::driver::compile_input::{{closure}}::hfa6b2fbd25427f03
  69: 0xb6e48513 - <std::thread::local::LocalKey<T>>::with::hfe1ad4c1ecfc61bf
  70: 0xb6e4477b - <std::thread::local::LocalKey<T>>::with::h9ec517b779397ffc
  71: 0xb6eac32f - rustc::ty::context::TyCtxt::create_and_enter::ha1426d1d12735577
  72: 0xb6dc417b - rustc_driver::driver::compile_input::h738177a00b975227
  73: 0xb6e6ad4f - rustc_driver::run_compiler_impl::ha84cb5f01fd0dd97
  74: 0xb6da15d7 - syntax::with_globals::h35a730735981f17e
  75: 0xb6dee2cb - std::sys_common::backtrace::__rust_begin_short_backtrace::h941f7d5fb16dafc2
  76: 0xb6c8e81f - __rust_maybe_catch_panic
                       at libpanic_unwind/lib.rs:102
  77: 0xb6df881f - <F as alloc::boxed::FnBox<A>>::call_box::hf3c580d870bbed4a
  78: 0xb6c83abf - std::sys_common::thread::start_thread::hc9c9c8bccde31424
                       at /checkout/src/liballoc/boxed.rs:793
                       at libstd/sys_common/thread.rs:24
  79: 0xb6c8a597 - std::sys::unix::thread::Thread::new::thread_start::h86817e665e0cb8a0
                       at libstd/sys/unix/thread.rs:90

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.26.0-nightly (55c984ee5 2018-03-16) running on armv7-unknown-linux-gnueabihf

note: compiler flags: -C debuginfo=2 --crate-type lib

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `cc`.

Caused by:
  process didn't exit successfully: `rustc --crate-name cc /home/RandomInsano/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/cc-1.0.8/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=c045fdd855277bee -C extra-filename=-c045fdd855277bee --out-dir /home/RandomInsano/Documents/Code/pscontroller-rs/target/debug/deps -L dependency=/home/RandomInsano/Documents/Code/pscontroller-rs/target/debug/deps --cap-lints allow` (exit code: 101)

@avl
Copy link
Author

avl commented Mar 18, 2018

@ExpHP I've now added the minimized savefile-derive crate into my github repro-project linked above. That is, to https://github.com/avl/rust_ice_48923 .

The crash.sh consistently provokes the crash for my computer, even with this minimized savefile-derive crate, even if I do like:

git clean -f -x -d
./crash.sh

Should be reproducible for you too, I think! Unless there's something else that differs between our systems and the issue is basically non-deterministic (affected by something like performance, file-system timestamps or whatnot :-) )

@avl
Copy link
Author

avl commented Mar 19, 2018

@RandomInsano I think your issue is something different. For one thing, the stack traces are not very similar, apart from the fact that both end up with an index out of range.

@michaelwoerister
Copy link
Member

michaelwoerister commented Mar 19, 2018

Thank you for all your work, @avl and @ExpHP! The small reproduction should make debugging this a lot easier. It's in my queue.

@michaelwoerister
Copy link
Member

OK, using @avl's repo I was able to reproduce something. With a compiler built with debug-assertions, building already crashes on the first try (that is, with an empty incr. comp. cache):

thread 'rustc' panicked at 'assertion failed: !tcx.dep_graph.dep_node_exists(&dep_node)', librustc/ty/maps/mod.rs:93:1
stack backtrace:
   0:     0x7f1997ac0a0b - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h31989477674ed8eb
                               at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1:     0x7f1997acd3a8 - std::sys_common::backtrace::print::h0aff9c2db7035d67
                               at libstd/sys_common/backtrace.rs:71
                               at libstd/sys_common/backtrace.rs:59
   2:     0x7f1997aac41d - std::panicking::default_hook::{{closure}}::h4782d445b75d926a
                               at libstd/panicking.rs:207
   3:     0x7f1997aac166 - std::panicking::default_hook::hdb4d35de831f50b6
                               at libstd/panicking.rs:223
   4:     0x7f1993b47920 - core::ops::function::Fn::call::h3f055c710819ffad
                               at librustc/util/common.rs:51
                               at /home/mw/0-rust/src/libcore/ops/function.rs:73
   5:     0x7f1997aacafa - std::panicking::rust_panic_with_hook::h03efd923e4481138
                               at libstd/panicking.rs:403
   6:     0x7f199402de87 - std::panicking::begin_panic::h2e93ee4e51787726
                               at /home/mw/0-rust/src/libstd/panicking.rs:365
   7:     0x7f199401c671 - rustc::ty::maps::<impl rustc::ty::maps::queries::dropck_outlives<'tcx>>::force::hcf588a057e7dfc15
                               at librustc/ty/maps/plumbing.rs:494
   8:     0x7f199401d106 - rustc::ty::maps::<impl rustc::ty::maps::queries::dropck_outlives<'tcx>>::try_get::h6d4b447907112cb7
                               at librustc/ty/maps/plumbing.rs:361
                               at librustc/ty/maps/plumbing.rs:539
   9:     0x7f1993b26559 - rustc::ty::maps::TyCtxtAt::dropck_outlives::hc79eae021e5ad3f1
                               at librustc/ty/maps/plumbing.rs:578
  10:     0x7f1993efd0c1 - rustc::traits::query::dropck_outlives::<impl rustc::infer::at::At<'cx, 'gcx, 'tcx>>::dropck_outlives::haa211ead3f1ef3fd
                               at librustc/ty/maps/plumbing.rs:571
                               at librustc/traits/query/dropck_outlives.rs:55
  11:     0x7f19962a4d38 - rustc_typeck::check::dropck::check_safety_of_destructor_if_necessary::h16fa59e7c5632e1e
  12:     0x7f1996379747 - rustc_typeck::check::regionck::RegionCtxt::check_safety_of_rvalue_destructor_if_necessary::h289ec60ae2053c50
  13:     0x7f1996375480 - <rustc_typeck::check::regionck::RegionCtxt<'a, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_expr::ha2234207548bccea
  14:     0x7f1996374430 - rustc_typeck::check::regionck::RegionCtxt::visit_fn_body::he60f80517525fac9
  15:     0x7f19962276fd - rustc_typeck::check::regionck::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::regionck_fn::h1c56e7bc971b7493
  16:     0x7f1996288e8a - rustc::ty::context::tls::enter::he1549a7dbb565f38
  17:     0x7f19961f7f07 - rustc::infer::InferCtxtBuilder::enter::h31dba36dd2a59536
  18:     0x7f19962421e1 - rustc_typeck::check::typeck_tables_of::hf5b1548ebcfe3766
  19:     0x7f1993f63bbb - rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::compute_result::h181c3bba84dd23e7
                               at librustc/ty/maps/plumbing.rs:396
  20:     0x7f1993a0c9c0 - rustc::dep_graph::graph::DepGraph::with_task_impl::h7024f65b1611aca8
                               at librustc/dep_graph/graph.rs:230
  21:     0x7f19940f61f7 - rustc_errors::Handler::track_diagnostics::h854d94ebfa19a0bb
                               at librustc/dep_graph/graph.rs:200
                               at librustc/ty/maps/plumbing.rs:505
                               at /home/mw/0-rust/src/librustc_errors/lib.rs:637
  22:     0x7f1993c4a3f6 - rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check::h8bc4420f6950773d
                               at librustc/ty/maps/plumbing.rs:498
                               at librustc/ty/maps/plumbing.rs:121
  23:     0x7f1993f63cd3 - rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::force::h7863739a808a43c4
                               at librustc/ty/maps/plumbing.rs:497
  24:     0x7f1993f64742 - rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::try_get::he75b775638ad6435
                               at librustc/ty/maps/plumbing.rs:361
                               at librustc/ty/maps/plumbing.rs:539
  25:     0x7f1993b1dc00 - rustc::ty::maps::TyCtxtAt::typeck_tables_of::h68de7e885d32e066
                               at librustc/ty/maps/plumbing.rs:578
  26:     0x7f1993f63b40 - rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::ensure::h78aac60f3b569d09
                               at librustc/ty/maps/plumbing.rs:571
                               at librustc/ty/maps/plumbing.rs:390
  27:     0x7f1996368bb1 - rustc::session::Session::track_errors::h90088f2022f85233
  28:     0x7f1996241d8e - rustc_typeck::check::typeck_item_bodies::hb05f767c92c1fa54
  29:     0x7f1993a2f7b0 - rustc::dep_graph::graph::DepGraph::with_task_impl::hcea9f4d39a5bcfd5
                               at librustc/dep_graph/graph.rs:230
  30:     0x7f19940e5313 - rustc_errors::Handler::track_diagnostics::h2e26319d038e4464
                               at librustc/dep_graph/graph.rs:200
                               at librustc/ty/maps/plumbing.rs:505
                               at /home/mw/0-rust/src/librustc_errors/lib.rs:637
  31:     0x7f1993c309a6 - rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check::h572b8968938fa16b
                               at librustc/ty/maps/plumbing.rs:498
                               at librustc/ty/maps/plumbing.rs:121
  32:     0x7f1993f622bc - rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::force::h91e81b1d86c71b44
                               at librustc/ty/maps/plumbing.rs:497
  33:     0x7f1993f62c7a - rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::try_get::h4921611a8a2d333a
                               at librustc/ty/maps/plumbing.rs:361
                               at librustc/ty/maps/plumbing.rs:539
  34:     0x7f1993b1dad9 - rustc::ty::maps::TyCtxtAt::typeck_item_bodies::hb8608ceb14741f12
                               at librustc/ty/maps/plumbing.rs:578
  35:     0x7f1993c9c551 - rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_item_bodies::h750620761ac8531b
                               at librustc/ty/maps/plumbing.rs:571
  36:     0x7f199639172e - rustc_typeck::check_crate::h818efe4efd2e8228
  37:     0x7f1997e98382 - rustc::ty::context::tls::enter_global::hdabbc8f603c57034
  38:     0x7f1997f5fa88 - rustc::ty::context::TyCtxt::create_and_enter::h9dc1c7ae44c9c683
  39:     0x7f1997eb12c7 - rustc_driver::driver::compile_input::h57481c89ea5db323
  40:     0x7f1997f2edd2 - rustc_driver::run_compiler_impl::h87832c1791e7dfc0
  41:     0x7f1997e9adb8 - syntax::with_globals::h159f70f74dc74b1a
  42:     0x7f1997ed2762 - std::sys_common::backtrace::__rust_begin_short_backtrace::h2eb0bf59b4be5e91
  43:     0x7f1997aea1ae - __rust_maybe_catch_panic
                               at libpanic_unwind/lib.rs:102
  44:     0x7f1997ed3804 - std::panicking::try::hd2667e266321a08e
  45:     0x7f1997ee6cf2 - <F as alloc::boxed::FnBox<A>>::call_box::h95d70f3fd084ce4b
  46:     0x7f1997ac1d3d - std::sys::unix::thread::Thread::new::thread_start::h82597e85006aac29
                               at /home/mw/0-rust/src/liballoc/boxed.rs:793
                               at libstd/sys_common/thread.rs:24
                               at libstd/sys/unix/thread.rs:90
  47:     0x7f1991c2e6b9 - start_thread
  48:     0x7f199778441c - clone
  49:                0x0 - <unknown>

It seems that the compiler is trying to force a query that already has a dep-node. A possible reason for this is that multiple query keys map to the same dep-node.

@michaelwoerister
Copy link
Member

It seems that something around CanonicalTyGoal is broken. In the example above, the compiler calls dropck_outlives::try_get() two times with the following key:

Canonical { 
    variables: Slice([]),
    value: ParamEnvAnd { 
        param_env: ParamEnv { 
            caller_bounds: Slice([Binder(TraitPredicate(<__S as _IMPL_SERIALIZE_FOR_X::_serde::Serializer>)),
                                  Binder(TraitPredicate(<__S as std::marker::Sized>))]),
            reveal: UserFacing,
            universe: UniverseIndex(0) 
        },
        value: std::result::Result<<__S as _IMPL_SERIALIZE_FOR_X::_serde::Serializer>::Ok,
        <__S as _IMPL_SERIALIZE_FOR_X::_serde::Serializer>::Error> 
    } 
}

Both keys have the same stable hash and the same Debug representation, but different std::hash values. I suspect that we are hashing pointers for std::hash and something is not interned right?

cc @eddyb @nikomatsakis

@michaelwoerister
Copy link
Member

OK, I can confirm that something is wrong with interning: The caller_bounds slices in the two cases have different addresses although they seem to have the same content.

@avl
Copy link
Author

avl commented Mar 20, 2018

Interesting! I know serde uses a clever trick to be able to use extern types in the generated trait implementation. That trick creates a symbol named _IMPL_SERIALIZE_FOR_ < struct-name > .

@michaelwoerister
Copy link
Member

The Substs within the various TraitRefs already have a different address:

// Version 1
Canonical {
    variables: [] (addr=1, len=0),
    value: ParamEnvAnd {
        param_env: ParamEnv {
            caller_bounds: [Binder(TraitPredicate(TraitRef { def_id: DefId(12/0:230 ~ serde[43ba]::ser[0]::Serializer[0]),
                                                             substs: [__S] (addr=7f0b0e434820, len=1) })), 
                            Binder(TraitPredicate(TraitRef { def_id: DefId(2/0:886 ~ core[3da8]::marker[0]::Sized[0]),
                                                             substs: [__S] (addr=7f0b0e434820, len=1) }))] (addr=7f0b03e35410, len=2),
            reveal: UserFacing,
            universe: UniverseIndex(0) 
        },
        value: std::result::Result<TraitRef { def_id: DefId(12/0:230 ~ serde[43ba]::ser[0]::Serializer[0]), 
                                              substs: [__S] (addr=7f0b0e434820, len=1) }::Ok,
                                   TraitRef { def_id: DefId(12/0:230 ~ serde[43ba]::ser[0]::Serializer[0]),
                                              substs: [__S] (addr=7f0b0e434820, len=1) }::Error>
    }
}

// Version 2
Canonical {
    variables: [] (addr=1, len=0),
    value: ParamEnvAnd {
        param_env: ParamEnv {
            caller_bounds: [Binder(TraitPredicate(TraitRef { def_id: DefId(12/0:230 ~ serde[43ba]::ser[0]::Serializer[0]),
                                                             substs: [__S] (addr=7f0b0e434588, len=1) })), 
                            Binder(TraitPredicate(TraitRef { def_id: DefId(2/0:886 ~ core[3da8]::marker[0]::Sized[0]),
                                                             substs: [__S] (addr=7f0b0e434588, len=1) }))] (addr=7f0b03e33c28, len=2),
            reveal: UserFacing,
            universe: UniverseIndex(0) 
        },
        value: std::result::Result<TraitRef { def_id: DefId(12/0:230 ~ serde[43ba]::ser[0]::Serializer[0]), 
                                              substs: [__S] (addr=7f0b0e434588, len=1) }::Ok,
                                   TraitRef { def_id: DefId(12/0:230 ~ serde[43ba]::ser[0]::Serializer[0]),
                                              substs: [__S] (addr=7f0b0e434588, len=1) }::Error>
    }
}

@nikomatsakis
Copy link
Contributor

@michaelwoerister hmm. That sounds bad, yes. That interning-slices code can be subtle, I guess I messed it up somehow perhaps.

@nikomatsakis
Copy link
Contributor

Although, that .. doesn't necessarily look related to canonicalization. But it seems likely to be the fault of that code.

@michaelwoerister
Copy link
Member

It turns out that __S is a TyParam (with index #0) in both cases. I'm now looking into whether the Symbol used for storing the name has a different interning key in both cases.

@nikomatsakis
Copy link
Contributor

@michaelwoerister ok let me know if I can help

@michaelwoerister
Copy link
Member

I think that's the problem: serde probably uses Symbol::gensym() (for hygiene?) and we end up with two different Symbol keys. HashStable, on the other hand, only hashes the string contents of the symbol. It does not make a difference between the two versions. The question is: how do we deal with this? What does it even mean that the names are gensymed? Do we need to find a stable way for hashing gensymed symbols?

@jasondavies
Copy link

Just ran into this issue when compiling stdsimd (incrementally) on Linux with nightly. CARGO_INCREMENTAL=0 cargo build fixed the issue for me.

@avl
Copy link
Author

avl commented Apr 16, 2018

I just re-ran my test case using rustc 1.27.0-nightly (ad610be 2018-04-11) , and the problem seems to be resolved!

I can't reproduce the problem with this newer rustc version.

Yay for progress! :-)

@michaelwoerister
Copy link
Member

Thanks for confirming, @avl!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority 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

10 participants