Skip to content

Incremental build panic running cargo test #74890

Closed
@sethp

Description

@sethp

Code

I don't think it's specific to any code per se, but I'm seeing this just after modifying a (now) 245 line file and hitting "run test" in vscode, maybe at about the same time I hotkey'd "save"? See below for more info.

This issue looks very similar to #73967 and maybe #73108. I suspect all three could be addressed by adopting a strategy as described in rust-lang/cargo#6529.

Meta

rustc --version --verbose:

rustc 1.44.1 (c7087fe00 2020-06-17)
binary: rustc
commit-hash: c7087fe00d2ba919df1d813c040a5d47e43b0fe7
commit-date: 2020-06-17
host: x86_64-apple-darwin
release: 1.44.1
LLVM version: 9.0

rustup upgrade did make the error "go away," I believe this is just because it invalidated the cache.

Error output

thread 'rustc' panicked at 'index out of bounds: the len is 245 but the index is 246', src/librustc_middle/ty/query/on_disk_cache.rs:583:18
Backtrace

stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: rustc_driver::report_ice
   6: std::panicking::rust_panic_with_hook
   7: rust_begin_unwind
   8: core::panicking::panic_fmt
   9: core::panicking::panic_bounds_check
  10: <rustc_middle::ty::query::on_disk_cache::CacheDecoder as serialize::serialize::SpecializedDecoder<rustc_span::span_encoding::Span>>::specialized_decode
  11: <rustc_middle::mir::SourceInfo as serialize::serialize::Decodable>::decode
  12: <rustc_middle::mir::Statement as serialize::serialize::Decodable>::decode
  13: serialize::serialize::Decoder::read_seq
  14: <rustc_middle::mir::BasicBlockData as serialize::serialize::Decodable>::decode
  15: serialize::serialize::Decoder::read_seq
  16: <rustc_middle::mir::Body as serialize::serialize::Decodable>::decode::{{closure}}
  17: rustc_middle::ty::query::on_disk_cache::OnDiskCache::try_load_query_result
  18: rustc_query_system::query::plumbing::get_query
  19: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::instance_mir
  20: rustc_mir::monomorphize::collector::collect_items_rec
  21: rustc_mir::monomorphize::collector::collect_items_rec
  22: rustc_mir::monomorphize::collector::collect_crate_mono_items
  23: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
  24: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::collect_and_partition_mono_items>::compute
  25: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  26: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  27: rustc_query_system::query::plumbing::get_query
  28: rustc_codegen_ssa::base::codegen_crate
  29: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  30: rustc_session::utils::<impl rustc_session::session::Session>::time
  31: rustc_interface::passes::start_codegen
  32: rustc_middle::ty::context::tls::enter_global
  33: rustc_interface::queries::Queries::ongoing_codegen
  34: rustc_interface::interface::run_compiler_in_existing_thread_pool
  35: scoped_tls::ScopedKey<T>::set
  36: rustc_ast::attr::with_globals

Reproducibility and Theory

So far I've reduced the state down to this project: out-of-bounds.tar.gz. tar xvzf out-of-bounds.tar.gz; cd out-of-bounds; cargo test has so far reproduced the error 100% of the time for me, but it's highly sensitive to the fingerprint mechanism so changes to anything in there produces a project that builds just fine.

Here's what I think is happening:

  1. cargo test kicks off an incremental compile, and starts checking fingerprints.
  2. In order to build the dependency graph, it runs a "query" to determine
  3. As part of executing that query, it loads a cached incremental compilation unit for tests/config.rs that is out of sync with the current file (it refers to a point in time where the file was a few lines longer), which panics

Since this appears to be happening in the "check what work to do" phase, rustc never produces a new artifact that's in sync with the current state of the file, and either cargo clean or forcing a full rebuild is necessary to get back into sync.

The two questions I haven't gotten a good idea about are:

  1. How does rustc determine the last incremental build is valid to run queries against? It seems that in this case, it should prefer to look through the new file than treat the last session as the file is indeed changed.
  2. What did I do to get the compiler into this state in the first place? Some details that I suspect may be relevant:
    • I hit the "run test" inline helper in vscode, at about the same time as making other edits and re-saving the file
    • I have vscode configured to format on save, which does something to modify the file either just before or just after saving
    • I'm running on HFS on macOS, so my mtime timestamps are no more granular than 1 second apart

Metadata

Metadata

Assignees

Labels

A-incr-compArea: Incremental compilationC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions