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

Rust 2018/macro imports/incremental compilation ICE: "thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 3'" #53097

Closed
akiselev opened this issue Aug 5, 2018 · 2 comments
Assignees
Labels
A-incr-comp Area: Incremental compilation A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-rust-2018-preview Area: The 2018 edition preview C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@akiselev
Copy link
Contributor

akiselev commented Aug 5, 2018

Unfortunately, I do not have a clean repro for this bug because it has something to do with macro import conflicts in a small library: two macros named hlist!, one in frunk and another in funky. I've created a branch with the repro. This crash only happens on incremental compilations. Compilations right after cargo clean compile just fine.

Repro branch: https://github.com/akiselev/vtable-rs/tree/rustc-index-panic

Reproduce using: cargo clean && cargo +nightly test, then change a line of code in the repro (such as commenting out a println! in mod tests) and run cargo +nightly test again. The ICE will happen on the second one

Offending code: core/src/lib.rs modules tests and tests2 with module macros

Expected result: The code should compile, funky::hlist! is only imported in the tests2 module which isn't visible.

Error:

thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 3', C:\projects\rust\src\libcore\slice\mod.rs:2049:10
stack backtrace:
   0: <std::sync::mpsc::RecvTimeoutError as core::fmt::Debug>::fmt
   1: <std::sys::windows::dynamic_lib::DynamicLibrary as core::ops::drop::Drop>::drop
   2: std::panicking::take_hook
   3: std::panicking::take_hook
   4: <rustc::ty::sty::Binder<rustc::ty::ProjectionPredicate<'tcx>> as rustc::ty::ToPredicate<'tcx>>::to_predicate
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::begin_panic_fmt
   7: rust_begin_unwind
   8: core::panicking::panic_fmt
   9: core::panicking::panic_bounds_check
  10: <rustc::ty::query::on_disk_cache::CacheDecoder<'a, 'tcx, 'x> as serialize::serialize::SpecializedDecoder<syntax_pos::span_encoding::Span>>::specialized_decode
  11: <rustc::middle::reachable::CollectPrivateImplItemsVisitor<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_impl_item
  12: <rustc::middle::reachable::CollectPrivateImplItemsVisitor<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_impl_item
  13: <rustc::middle::reachable::CollectPrivateImplItemsVisitor<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_impl_item
  14: <rustc::middle::reachable::CollectPrivateImplItemsVisitor<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_impl_item
  15: <rustc::mir::mono::Visibility as core::fmt::Debug>::fmt
  16: rustc::ty::query::on_disk_cache::OnDiskCache::store_diagnostics
  17: <rustc::ty::query::queries::optimized_mir<'tcx> as rustc::ty::query::config::QueryDescription<'tcx>>::try_load_from_disk
  18: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  19: rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::instance_mir
  20: rustc_mir::monomorphize::collector::collect_crate_mono_items
  21: rustc_mir::monomorphize::collector::collect_crate_mono_items
  22: rustc_mir::monomorphize::collector::collect_crate_mono_items
  23: rustc_mir::monomorphize::collector::collect_crate_mono_items
  24: rustc_mir::transform::optimized_mir
  25: <rustc_mir::borrow_check::nll::region_infer::values::PlaceholderIndex as core::iter::range::Step>::replace_one
  26: rustc_mir::monomorphize::collector::collect_crate_mono_items
  27: <rustc_codegen_llvm::llvm::SectionIter<'a> as core::ops::drop::Drop>::drop
  28: <rustc_codegen_llvm::base::ValueIter<'ll> as core::iter::iterator::Iterator>::next
  29: <rustc::traits::object_safety::MethodViolationCode as core::fmt::Debug>::fmt
  30: rustc::ty::context::tls::track_diagnostic
  31: rustc::dep_graph::graph::DepGraph::assert_ignored
  32: rustc::ty::context::tls::track_diagnostic
  33: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  35: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  36: rustc_driver::target_features::add_configuration
  37: rustc_driver::driver::phase_4_codegen
  38: rustc_driver::profile::dump
  39: <rustc_driver::pretty::IdentifiedAnnotation<'hir> as rustc_driver::pretty::PrinterSupport>::sess
  40: <env_logger::Logger as log::Log>::flush
  41: <rustc_driver::CompilationFailure as core::fmt::Debug>::fmt
  42: rustc_driver::driver::compile_input
  43: rustc_driver::run_compiler
  44: <rustc_driver::profile::trace::Query as core::fmt::Debug>::fmt
  45: <env_logger::filter::inner::Filter as core::fmt::Display>::fmt
  46: <rustc_driver::derive_registrar::Finder as rustc::hir::itemlikevisit::ItemLikeVisitor<'v>>::visit_item
  47: _rust_maybe_catch_panic
  48: rustc_driver::profile::dump
  49: rustc_driver::main
  50: <unknown>
  51: std::panicking::update_panic_count
  52: _rust_maybe_catch_panic
  53: std::rt::lang_start_internal
  54: <unknown>
  55: <unknown>
  56: BaseThreadInitThunk
  57: RtlUserThreadStart
query stack during panic:
#0 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack

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.30.0-nightly (3edb355b7 2018-08-03) running on x86_64-pc-windows-msvc

note: compiler flags: -C debuginfo=2 -C incremental

note: some of the compiler flags provided by cargo are hidden
@Mark-Simulacrum Mark-Simulacrum added the A-rust-2018-preview Area: The 2018 edition preview label Aug 5, 2018
@orium
Copy link
Member

orium commented Aug 21, 2018

I think I have hit the same bug, and I have a minified example. I'm not 100% sure it is the same, but it likely is. It also has two macros with the same name, it seems to ICE in CacheDecoder, and it only happens in the second iteration when incremental compilation kicks-in.

Cargo.toml:

cargo-features = ["edition"]

[package]
name = "rustc-ice"
version = "0.0.0"
authors = []

edition = '2018'

[dependencies]
pretty_assertions = "0.5"

src/lib.rs:

extern crate pretty_assertions;

use pretty_assertions::assert_eq;

fn a() {
    assert_eq!(0, 0);
}

mod m {
    fn b() {
        assert_eq!(0, 0);
    }

    mod m1 {
        use pretty_assertions::assert_eq;

        #[test]
        fn c() {
            assert_eq!(0, 0, "");
        }
    }
}

This bug is non-deterministic. It sometimes takes me a few tries to make the compiler ICE. To automate this run the following script, which will loop until the ICE:

try.sh:

#!/bin/bash

set -e

while true; do
    cargo +nightly clean
    cargo +nightly build --all-targets
    echo >> src/lib.rs
    RUST_BACKTRACE=1 cargo +nightly build --all-targets
done

After a few iterations (in my machine it rarely is more than 5 iterations) you should see this:

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                                                                      
             at libstd/sys_common/backtrace.rs:59                                                                      
   2: std::panicking::default_hook::{{closure}}                                                                        
             at libstd/panicking.rs:211                                                                                
   3: std::panicking::default_hook                                                                                     
             at libstd/panicking.rs:227                                                                                
   4: rustc::util::common::panic_hook                                                                                  
   5: std::panicking::rust_panic_with_hook                                                                             
             at libstd/panicking.rs:479                                                                                
   6: std::panicking::continue_panic_fmt                                                                               
             at libstd/panicking.rs:390                                                                                
   7: rust_begin_unwind                                                                                                
             at libstd/panicking.rs:325                                                                                
   8: core::panicking::panic_fmt                                                                                       
             at libcore/panicking.rs:77                                                                                
   9: core::panicking::panic_bounds_check                                                                              
             at libcore/panicking.rs:59                                                                                
  10: <rustc::ty::query::on_disk_cache::CacheDecoder<'a, 'tcx, 'x> as serialize::serialize::SpecializedDecoder<syntax_p
os::span_encoding::Span>>::specialized_decode                                                                          
  11: serialize::serialize::Decoder::read_struct                                                                       
  12: serialize::serialize::Decoder::read_seq                                                                          
  13: serialize::serialize::Decoder::read_struct                                                                       
  14: serialize::serialize::Decoder::read_seq                                                                          
  15: <rustc::mir::Mir<'tcx> as serialize::serialize::Decodable>::decode::{{closure}}                                  
  16: rustc::ty::query::on_disk_cache::OnDiskCache::try_load_query_result                                              
  17: <rustc::ty::query::queries::optimized_mir<'tcx> as rustc::ty::query::config::QueryDescription<'tcx>>::try_load_fr
om_disk                                                                                                                
  18: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_query                     
  19: rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::instance_mir                                       
  20: rustc_mir::monomorphize::collector::collect_items_rec                                                            
  21: rustc_mir::monomorphize::collector::collect_items_rec                                                            
  22: rustc_mir::monomorphize::collector::collect_items_rec
  23: rustc_mir::monomorphize::collector::collect_items_rec
  24: rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}                                       
  25: rustc::util::common::time
  26: rustc_mir::monomorphize::collector::collect_crate_mono_items
  27: rustc::util::common::time
  28: rustc_codegen_llvm::base::collect_and_partition_mono_items
  29: rustc::ty::context::tls::with_context
  30: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
  31: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  32: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  33: rustc::util::common::time
  34: rustc_driver::driver::phase_4_codegen
  35: rustc_driver::driver::compile_input::{{closure}}
  36: rustc::ty::context::tls::enter_context
  37: <std::thread::local::LocalKey<T>>::with
  38: rustc::ty::context::TyCtxt::create_and_enter
  39: rustc_driver::driver::compile_input
  40: rustc_driver::run_compiler_with_pool
  41: syntax::with_globals
  42: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  43: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:102
  44: rustc_driver::run
  45: rustc_driver::main
  46: std::rt::lang_start::{{closure}}
  47: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  48: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:102
  49: std::rt::lang_start_internal
             at libstd/panicking.rs:289
             at libstd/panic.rs:392
             at libstd/rt.rs:58
  50: main
  51: __libc_start_main
  52: <unknown>
query stack during panic:
#0 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack

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.30.0-nightly (33b923fd4 2018-08-18) running on x86_64-unknown-linux-gnu                                 

note: compiler flags: -C debuginfo=2 -C incremental

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

Note that this bug is also present if you select edition 2015!

@estebank estebank added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Aug 23, 2018
@orium orium modified the milestone: Rust 2018 RC Sep 11, 2018
@orium orium added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. labels Sep 16, 2018
@orium orium self-assigned this Sep 16, 2018
@orium
Copy link
Member

orium commented Sep 17, 2018

I have a fix for this. Just needs some small changes and then I will open a PR.

orium added a commit to orium/rust that referenced this issue Sep 19, 2018
Before this two macros with same name would be indistinguishable inside a
`FileName`.  This caused a bug in incremental compilation (see rust-lang#53097) since
two different macros would map out to the same `StableFilemapId`.

Fixes rust-lang#53097.
@orium orium added this to the Edition 2018 RC 2 milestone Sep 20, 2018
bors added a commit that referenced this issue Sep 28, 2018
Use full name to identify a macro in a `FileName`.

Before this two macros with same name would be indistinguishable inside a `FileName`.  This caused a bug in incremental compilation (see #53097) since two different macros would map out to the same `StableFilemapId`.

Fixes #53097.

r? @nrc
pietroalbini pushed a commit to pietroalbini/rust that referenced this issue Oct 2, 2018
Before this two macros with same name would be indistinguishable inside a
`FileName`.  This caused a bug in incremental compilation (see rust-lang#53097) since
two different macros would map out to the same `StableFilemapId`.

Fixes rust-lang#53097.
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 A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-rust-2018-preview Area: The 2018 edition preview 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