rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.15k stars 12.69k forks source link

ICE bootstrapping rustc with incremental cache #93823

Closed jyn514 closed 1 year ago

jyn514 commented 2 years ago

Code

https://github.com/jyn514/rust/commit/0fa56d77280a959f6cd2a9c07942b8a3223dec1f with this diff applied:

```diff diff --git a/compiler/rustc_typeck/src/check/op.rs b/compiler/rustc_typeck/src/check/op.rs index 74516acbfcf..6aa7f96d800 100644 --- a/compiler/rustc_typeck/src/check/op.rs +++ b/compiler/rustc_typeck/src/check/op.rs @@ -10,7 +10,7 @@ Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, }; use rustc_middle::ty::fold::TypeFolder; -use rustc_middle::ty::TyKind::{Adt, Array, Char, FnDef, Never, Ref, Str, Tuple, Uint}; +use rustc_middle::ty::TyKind::{Array, Char, FnDef, Never, Ref, Str, Tuple, Uint}; use rustc_middle::ty::{ self, suggest_constraining_type_param, Ty, TyCtxt, TypeFoldable, TypeVisitor, }; @@ -426,15 +426,7 @@ fn check_overloaded_binop( let mut visitor = TypeParamVisitor(vec![]); visitor.visit_ty(lhs_ty); - if op.node == hir::BinOpKind::Add - && self.check_str_addition( - lhs_expr, rhs_expr, lhs_ty, rhs_ty, &mut err, is_assign, op, - ) - { - // This has nothing here because it means we did string - // concatenation (e.g., "Hello " + "World!"). This means - // we don't want the note in the else clause to be emitted - } else if let [ty] = &visitor.0[..] { + if let [ty] = &visitor.0[..] { if let ty::Param(p) = *ty.kind() { // Check if the method would be found if the type param wasn't // involved. If so, it means that adding a trait bound to the param is @@ -534,96 +526,6 @@ fn add_type_neq_err_label( false } - /// Provide actionable suggestions when trying to add two strings with incorrect types, - /// like `&str + &str`, `String + String` and `&str + &String`. - /// - /// If this function returns `true` it means a note was printed, so we don't need - /// to print the normal "implementation of `std::ops::Add` might be missing" note - fn check_str_addition( - &self, - lhs_expr: &'tcx hir::Expr<'tcx>, - rhs_expr: &'tcx hir::Expr<'tcx>, - lhs_ty: Ty<'tcx>, - rhs_ty: Ty<'tcx>, - err: &mut rustc_errors::DiagnosticBuilder<'_>, - is_assign: IsAssign, - op: hir::BinOp, - ) -> bool { - let str_concat_note = "string concatenation requires an owned `String` on the left"; - let rm_borrow_msg = "remove the borrow to obtain an owned `String`"; - let to_owned_msg = "create an owned `String` from a string reference"; - - let string_type = self.tcx.get_diagnostic_item(sym::String); - let is_std_string = |ty: Ty<'tcx>| match ty.ty_adt_def() { - Some(ty_def) => Some(ty_def.did) == string_type, - None => false, - }; - - match (lhs_ty.kind(), rhs_ty.kind()) { - (&Ref(_, l_ty, _), &Ref(_, r_ty, _)) // &str or &String + &str, &String or &&str - if (*l_ty.kind() == Str || is_std_string(l_ty)) && ( - *r_ty.kind() == Str || is_std_string(r_ty) || - &format!("{:?}", rhs_ty) == "&&str" - ) => - { - if let IsAssign::No = is_assign { // Do not supply this message if `&str += &str` - err.span_label(op.span, "`+` cannot be used to concatenate two `&str` strings"); - err.note(str_concat_note); - if let hir::ExprKind::AddrOf(_, _, lhs_inner_expr) = lhs_expr.kind { - err.span_suggestion_verbose( - lhs_expr.span.until(lhs_inner_expr.span), - rm_borrow_msg, - "".to_owned(), - Applicability::MachineApplicable - ); - } else { - err.span_suggestion_verbose( - lhs_expr.span.shrink_to_hi(), - to_owned_msg, - ".to_owned()".to_owned(), - Applicability::MachineApplicable - ); - } - } - true - } - (&Ref(_, l_ty, _), &Adt(..)) // Handle `&str` & `&String` + `String` - if (*l_ty.kind() == Str || is_std_string(l_ty)) && is_std_string(rhs_ty) => - { - err.span_label( - op.span, - "`+` cannot be used to concatenate a `&str` with a `String`", - ); - match is_assign { - IsAssign::No => { - let sugg_msg; - let lhs_sugg = if let hir::ExprKind::AddrOf(_, _, lhs_inner_expr) = lhs_expr.kind { - sugg_msg = "remove the borrow on the left and add one on the right"; - (lhs_expr.span.until(lhs_inner_expr.span), "".to_owned()) - } else { - sugg_msg = "create an owned `String` on the left and add a borrow on the right"; - (lhs_expr.span.shrink_to_hi(), ".to_owned()".to_owned()) - }; - let suggestions = vec![ - lhs_sugg, - (rhs_expr.span.shrink_to_lo(), "&".to_owned()), - ]; - err.multipart_suggestion_verbose( - sugg_msg, - suggestions, - Applicability::MachineApplicable, - ); - } - IsAssign::Yes => { - err.note(str_concat_note); - } - } - true - } - _ => false, - } - } - pub fn check_user_unop( &self, ex: &'tcx hir::Expr<'tcx>, ```

Meta

rustc --version --verbose:

note: rustc 1.59.0-beta.5 (28c8a34e1 2022-01-27) running on x86_64-unknown-linux-gnu

Error output

thread 'rustc' panicked at 'index out of bounds: the len is 906 but the index is 976', compiler/rustc_query_impl/src/on_disk_cache.rs:726:18
Backtrace

``` Building stage0 compiler artifacts (x86_64-unknown-linux-gnu(x86_64-unknown-linux-gnu) -> x86_64-unknown-linux-gnu(x86_64-unknown-linux-gnu)) Compiling rustc_typeck v0.0.0 (/home/jnelson/rust-lang/rust/compiler/rustc_typeck) Compiling rustc_privacy v0.0.0 (/home/jnelson/rust-lang/rust/compiler/rustc_privacy) Compiling rustc_interface v0.0.0 (/home/jnelson/rust-lang/rust/compiler/rustc_interface) stack backtrace: 0: rust_begin_unwind at /rustc/28c8a34e18fc05277c81328d1bbf5ed931f4d22e/library/std/src/panicking.rs:498:5 1: core::panicking::panic_fmt at /rustc/28c8a34e18fc05277c81328d1bbf5ed931f4d22e/library/core/src/panicking.rs:107:14 2: core::panicking::panic_bounds_check at /rustc/28c8a34e18fc05277c81328d1bbf5ed931f4d22e/library/core/src/panicking.rs:75:5 3: >::decode 4: >::decode 5: ::read_seq::, as rustc_serialize::serialize::Decodable>::decode::{closure#0}> 6: >::decode 7: >::decode 8: <&rustc_middle::ty::TyS as rustc_serialize::serialize::Decodable>::decode 9: <&rustc_middle::ty::TyS as rustc_serialize::serialize::Decodable>::decode 10: as core::iter::traits::collect::Extend>::extend::, <&rustc_middle::ty::list::List as rustc_serialize::serialize::Decodable>::decode::{closure#0}>, alloc::string::String>> 11: core::iter::adapters::process_results::, <&rustc_middle::ty::list::List as rustc_serialize::serialize::Decodable>::decode::{closure#0}>, rustc_middle::ty::subst::GenericArg, alloc::string::String, , alloc::string::String> as core::iter::traits::collect::FromIterator>>::from_iter, <&rustc_middle::ty::list::List as rustc_serialize::serialize::Decodable>::decode::{closure#0}>>::{closure#0}, smallvec::SmallVec<[rustc_middle::ty::subst::GenericArg; 8]>> 12: as rustc_middle::ty::context::InternIteratorElement>>::intern_with::, <&rustc_middle::ty::list::List as rustc_serialize::serialize::Decodable>::decode::{closure#0}>, ::mk_substs, <&rustc_middle::ty::list::List as rustc_serialize::serialize::Decodable>::decode::{closure#0}>>::{closure#0}> 13: >::decode 14: <&rustc_middle::ty::TyS as rustc_serialize::serialize::Decodable>::decode 15: as core::iter::traits::collect::Extend>::extend::, <&rustc_middle::ty::list::List as rustc_serialize::serialize::Decodable>::decode::{closure#0}>, alloc::string::String>> 16: core::iter::adapters::process_results::, <&rustc_middle::ty::list::List as rustc_serialize::serialize::Decodable>::decode::{closure#0}>, rustc_middle::ty::subst::GenericArg, alloc::string::String, , alloc::string::String> as core::iter::traits::collect::FromIterator>>::from_iter, <&rustc_middle::ty::list::List as rustc_serialize::serialize::Decodable>::decode::{closure#0}>>::{closure#0}, smallvec::SmallVec<[rustc_middle::ty::subst::GenericArg; 8]>> 17: as rustc_middle::ty::context::InternIteratorElement>>::intern_with::, <&rustc_middle::ty::list::List as rustc_serialize::serialize::Decodable>::decode::{closure#0}>, ::mk_substs, <&rustc_middle::ty::list::List as rustc_serialize::serialize::Decodable>::decode::{closure#0}>>::{closure#0}> 18: >::decode 19: <&rustc_middle::ty::TyS as rustc_serialize::serialize::Decodable>::decode 20: as core::iter::traits::collect::Extend>::extend::, <&rustc_middle::ty::list::List as rustc_serialize::serialize::Decodable>::decode::{closure#0}>, alloc::string::String>> 21: core::iter::adapters::process_results::, <&rustc_middle::ty::list::List as rustc_serialize::serialize::Decodable>::decode::{closure#0}>, rustc_middle::ty::subst::GenericArg, alloc::string::String, , alloc::string::String> as core::iter::traits::collect::FromIterator>>::from_iter, <&rustc_middle::ty::list::List as rustc_serialize::serialize::Decodable>::decode::{closure#0}>>::{closure#0}, smallvec::SmallVec<[rustc_middle::ty::subst::GenericArg; 8]>> 22: ::mk_substs::, <&rustc_middle::ty::list::List as rustc_serialize::serialize::Decodable>::decode::{closure#0}>> 23: as rustc_serialize::serialize::Decodable>::decode 24: , rustc_errors::ErrorReported> as rustc_serialize::serialize::Decodable>::decode 25: ::try_load_query_result::, rustc_errors::ErrorReported>> 26: <>::TRY_LOAD_FROM_DISK::{closure#0} as core::ops::function::FnOnce<(rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::dep_graph::serialized::SerializedDepNodeIndex)>>::call_once 27: rustc_query_system::query::plumbing::try_load_from_disk_and_cache_in_memory::), core::result::Result, rustc_errors::ErrorReported>> 28: rustc_query_system::query::plumbing::try_execute_query::), core::result::Result, rustc_errors::ErrorReported>>> 29: ::codegen_fulfill_obligation 30: rustc_ty_utils::instance::inner_resolve_instance 31: rustc_ty_utils::instance::resolve_instance 32: rustc_query_system::query::plumbing::try_load_from_disk_and_cache_in_memory::)>, core::result::Result, rustc_errors::ErrorReported>> 33: rustc_query_system::query::plumbing::get_query:: 34: ::resolve_instance 35: ::resolve 36: rustc_monomorphize::collector::collect_neighbours 37: rustc_monomorphize::collector::collect_items_rec 38: rustc_monomorphize::collector::collect_items_rec 39: rustc_monomorphize::collector::collect_items_rec 40: rustc_monomorphize::collector::collect_items_rec 41: rustc_monomorphize::collector::collect_items_rec 42: rustc_monomorphize::collector::collect_items_rec 43: rustc_monomorphize::collector::collect_items_rec 44: rustc_monomorphize::collector::collect_items_rec 45: rustc_monomorphize::collector::collect_items_rec 46: rustc_monomorphize::collector::collect_items_rec 47: rustc_monomorphize::collector::collect_items_rec 48: rustc_monomorphize::collector::collect_items_rec 49: rustc_monomorphize::collector::collect_items_rec 50: rustc_monomorphize::collector::collect_items_rec 51: rustc_monomorphize::collector::collect_items_rec 52: rustc_monomorphize::collector::collect_items_rec 53: rustc_monomorphize::collector::collect_items_rec 54: rustc_monomorphize::collector::collect_items_rec 55: rustc_monomorphize::collector::collect_items_rec 56: rustc_monomorphize::collector::collect_items_rec 57: rustc_monomorphize::collector::collect_items_rec 58: rustc_monomorphize::collector::collect_items_rec 59: rustc_monomorphize::collector::collect_items_rec 60: rustc_monomorphize::collector::collect_items_rec 61: rustc_monomorphize::collector::collect_items_rec 62: ::time::<(), rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}> 63: rustc_monomorphize::collector::collect_crate_mono_items 64: rustc_monomorphize::partitioning::collect_and_partition_mono_items 65: ::with_deps::<>::with_task_impl>, &[rustc_middle::mir::mono::CodegenUnit])>::{closure#0}, (&std::collections::hash::set::HashSet>, &[rustc_middle::mir::mono::CodegenUnit])> 66: >::with_task::>, &[rustc_middle::mir::mono::CodegenUnit])> 67: rustc_data_structures::stack::ensure_sufficient_stack::<((&std::collections::hash::set::HashSet>, &[rustc_middle::mir::mono::CodegenUnit]), rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job>, &[rustc_middle::mir::mono::CodegenUnit])>::{closure#3}> 68: rustc_query_system::query::plumbing::try_execute_query::>, &[rustc_middle::mir::mono::CodegenUnit])>> 69: rustc_query_system::query::plumbing::get_query:: 70: ::collect_and_partition_mono_items 71: ::codegen_crate 72: ::time::, rustc_interface::passes::start_codegen::{closure#0}> 73: ::ongoing_codegen 74: ::enter::, rustc_errors::ErrorReported>> 75: rustc_span::with_source_map::, rustc_interface::interface::create_compiler_and_run, rustc_driver::run_compiler::{closure#1}>::{closure#1}> 76: rustc_interface::interface::create_compiler_and_run::, rustc_driver::run_compiler::{closure#1}> 77: >::set::, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>> note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md note: rustc 1.59.0-beta.5 (28c8a34e1 2022-01-27) running on x86_64-unknown-linux-gnu note: compiler flags: -Z macro-backtrace -Z tls-model=initial-exec -Z unstable-options -Z binary-dep-depinfo -Z force-unstable-if-unmarked -C opt-level=3 -C embed-bitcode=no -C debuginfo=0 -C incremental -C symbol-mangling-version=v0 -C link-args=-Wl,-z,origin -C link-args=-Wl,-rpath,$ORIGIN/../lib -C prefer-dynamic -C llvm-args=-import-instr-limit=10 --crate-type lib note: some of the compiler flags provided by cargo are hidden query stack during panic: #0 [codegen_fulfill_obligation] checking if `core::ops::function::FnMut` fulfills its obligations #1 [resolve_instance] resolving instance `<[closure@core::iter::adapters::copied::copy_try_fold, [closure@core::iter::traits::iterator::Iterator::try_for_each::call, [closure@rustc_middle::ty::subst::>::super_visit_with::{closure#0}]>::{closure#0}]>::{closure#0}] as core::ops::function::FnMut<((), &rustc_middle::ty::subst::GenericArg)>>::call_mut` #2 [collect_and_partition_mono_items] collect_and_partition_mono_items end of query stack error: could not compile `rustc_typeck` ```

compiler-errors commented 2 years ago

+1, I've been getting these all the time when bootstrapping rust. Basically always have to ./x.py clean before building after a nontrivial change.

I think this might be related to the the issues that @Aaron1011 was fixing like last month about incremental compilation bugs on nightly (e.g. #92534) but which aren't on beta yet, which we use to bootstrap?

jyn514 commented 2 years ago

@compiler-errors you can make it much faster to rebuild by running rm -r target/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/incremental/ instead of a full x.py clean

compiler-errors commented 2 years ago

Maybe we could add a flag to x to bootstrap with a custom compiler artifact, like nightly-2022-02-09? Is that a bad idea? If not, I might look into it.

This is obviously a bandaid for when beta is particularly ICE-prone, but maybe it could be useful for other things...

Mark-Simulacrum commented 2 years ago

rustc = ... in config.toml is something that's already supported -- you can point it at a nightly toolchain and things should largely just work (presuming it's recent enough etc).

workingjubilee commented 1 year ago

Closing as (a duplicate|resolved|a resolved duplicate).