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 when iterating over string literal with manual newline insertions #59954

Closed
snOm3ad opened this issue Apr 14, 2019 · 2 comments · Fixed by #76256
Closed

ICE when iterating over string literal with manual newline insertions #59954

snOm3ad opened this issue Apr 14, 2019 · 2 comments · Fixed by #76256
Labels
C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example 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.

Comments

@snOm3ad
Copy link

snOm3ad commented Apr 14, 2019

The error message by the compiler was, thread 'rustc' panicked at 'index out of bounds: the len is 73 but the index is 74', /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf/src/libcore/slice/mod.rs:2539:10.

The code:

pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> {
    let mut results = Vec::new();
    for line in contents.lines() {
        if line.contains(query) {
            results.push(line);
        }
    }
    results
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn one_result() {
        let query = "duct";
        let contents = "Rust:\nsafe, fast, productive.\nPick three.";
        assert_eq!(vec!["safe, fast, productive."], search(query, contents));
    }
}

Changing the contents string literal to be formatted in the conventional way, i.e. without the manually inserted newline characters makes the code compile again (see below).

        let contents = "\
Rust:
safe, fast, productive.
Pick three.";

Meta

The complete error message

$ cargo test
   Compiling minigrep v0.1.0 (/Users/snOm3ad/Desktop/rust/minigrep)
thread 'rustc' panicked at 'index out of bounds: the len is 73 but the index is 74', /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf/src/libcore/slice/mod.rs:2539:10                                    
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

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.34.0 (91856ed52 2019-04-10) running on x86_64-apple-darwin

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

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

error: Could not compile `minigrep`.
warning: build failed, waiting for other jobs to finish...
error: build failed

The backtrace:

stack backtrace:                                                                                                                                                                                          
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace                                                                                                                                           
   1: std::sys_common::backtrace::_print                                                                                                                                                                  
   2: std::panicking::default_hook::{{closure}}                                                                                                                                                           
   3: std::panicking::default_hook                                                                                                                                                                        
   4: rustc::util::common::panic_hook                                                                                                                                                                     
   5: std::panicking::rust_panic_with_hook                                                                                                                                                                
   6: std::panicking::continue_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: 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_from_disk                                                                            
  18: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query                                                                                                            
  19: rustc_mir::monomorphize::collector::collect_items_rec                                                                                                                                               
  20: rustc_mir::monomorphize::collector::collect_items_rec                                                                                                                                               
  21: rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}                                                                                                                           
  22: rustc::util::common::time                                                                                                                                                                           
  23: rustc_mir::monomorphize::collector::collect_crate_mono_items                                                                                                                                        
  24: rustc::util::common::time                                                                                                                                                                           
  25: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items                                                                                                                             
  26: rustc::ty::query::__query_compute::collect_and_partition_mono_items                                                                                                                                 
  27: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::collect_and_partition_mono_items<'tcx>>::compute                                              
  28: rustc::dep_graph::graph::DepGraph::with_task_impl                                                                                                                                                   
  29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query                                                                                                            
  30: rustc_codegen_ssa::base::codegen_crate                                                                                                                                                              
  31: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate                                                                                     
  32: rustc::util::common::time                                                                                                                                                                           
  33: rustc_driver::driver::phase_4_codegen                                                                                                                                                               
  34: rustc_driver::driver::compile_input::{{closure}}                                                                                                                                                    
  35: <std::thread::local::LocalKey<T>>::with                                                                                                                                                             
  36: rustc::ty::context::TyCtxt::create_and_enter                                                                                                                                                        
  37: rustc_driver::driver::compile_input                                                                                                                                                                 
  38: rustc_driver::run_compiler_with_pool                                                                                                                                                                
  39: <scoped_tls::ScopedKey<T>>::set                                                                                                                                                                     
  40: rustc_driver::run_compiler                                                                                                                                                                          
  41: syntax::with_globals                                                                                                                                                                                
  42: __rust_maybe_catch_panic                                                                                                                                                                            
  43: <F as alloc::boxed::FnBox<A>>::call_box                                                                                                                                                             
  44: std::sys::unix::thread::Thread::new::thread_start                                                                                                                                                   
  45: _pthread_body                                                                                                                                                                                       
  46: _pthread_start                                                                                                                                                                                      
query stack during panic:                                                                                                                                                                                 
#0 [optimized_mir] processing `tests::one_result::{{closure}}`                                                                                                                                           
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items                                                                                                                                   
end of query stack
@jonas-schievink jonas-schievink added C-bug Category: This is a bug. 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. labels Apr 14, 2019
@hellow554
Copy link
Contributor

hellow554 commented Apr 15, 2019

Your code does not ICE on the playground (https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=4fc8a8a837a1a737409559e2cb57f6ea). Does it has something to do with your OS? Can you reprocude the error even after doing cargo clean?

@snOm3ad
Copy link
Author

snOm3ad commented Apr 15, 2019

No, I am not able to reproduce the issue after running cargo clean! The code runs correctly after doing so.

@estebank estebank added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Dec 15, 2019
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 12, 2020
incr-comp: hash and serialize span end line/column

Hash both the length and the end location (line/column) of a span. If we
hash only the length, for example, then two otherwise equal spans with
different end locations will have the same hash. This can cause a
problem during incremental compilation wherein a previous result for a
query that depends on the end location of a span will be incorrectly
reused when the end location of the span it depends on has changed. A
similar analysis applies if some query depends specifically on the
length of the span, but we only hash the end location. So hash both.

Fix rust-lang#46744, fix rust-lang#59954, fix rust-lang#63161, fix rust-lang#73640, fix rust-lang#73967, fix rust-lang#74890, fix rust-lang#75900

---

See rust-lang#74890 for a more in-depth analysis.

I haven't thought about what other problems this root cause could be responsible for. Please let me know if anything springs to mind. I believe the issue has existed since the inception of incremental compilation.
@bors bors closed this as completed in b71e627 Nov 12, 2020
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. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants