rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.29k stars 1.61k forks source link

Chalk panic on out of bound index when analyzsis-stats on rustc #3945

Closed edwin0cheng closed 4 years ago

edwin0cheng commented 4 years ago

cc @flodiebold

cargo run --release -p rust-analyzer -- analysis-stats D:\sandbox\rust-root\rust-src
Stack Traces ``` env RUST_BACKTRACE=full cargo run --release -p rust-analyzer -- analysis-stats D:\sandbox\rust-root\rust-src Finished release [optimized] target(s) in 0.51s Running `target\release\rust-analyzer.exe analysis-stats D:\sandbox\rust-root\rust-src` [ERROR ra_project_model] cyclic dependency cargo -> cargo-test-support [ERROR ra_project_model] cyclic dependency core -> rand [ERROR ra_project_model] cyclic dependency getrandom -> wasi Database loaded, 520 roots, 4.6309733s Crates in this dir: 163 Total modules found: 2544 Total declarations: 54460 Total functions: 41283 Item Collection: 65.5696109s, 0b allocated 0b resident 8894/41283 21% processing: box_region::newthread 'main' panicked at 'index out of bounds: the len is 1 but the index is 1', C:\Users\Edwin\.cargo\git\checkouts\chalk-7b02fa8caa2cec94\039fc90\chalk-ir\src\fold\subst.rs:56:19 stack backtrace: 0: backtrace::backtrace::trace_unsynchronized at C:\Users\VssAdministrator\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.40\src\backtrace\mod.rs:66 1: std::sys_common::backtrace::_print_fmt at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\sys_common\backtrace.rs:77 2: std::sys_common::backtrace::_print::{{impl}}::fmt at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\sys_common\backtrace.rs:59 3: core::fmt::write at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libcore\fmt\mod.rs:1052 4: std::io::Write::write_fmt at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\io\mod.rs:1426 5: std::sys_common::backtrace::_print at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\sys_common\backtrace.rs:62 6: std::sys_common::backtrace::print at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\sys_common\backtrace.rs:49 7: std::panicking::default_hook::{{closure}} at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:204 8: std::panicking::default_hook at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:224 9: std::panicking::rust_panic_with_hook at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:472 10: std::panicking::begin_panic_handler at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:380 11: core::panicking::panic_fmt at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libcore\panicking.rs:85 12: core::panicking::panic_bounds_check at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libcore\panicking.rs:63 13: core::ptr::drop_in_place 14: as chalk_ir::fold::SuperFold>::super_fold_with 15: chalk_ir::fold::boring_impls:: for chalk_ir::Parameter>::fold_with 16: as alloc::vec::SpecExtend>::from_iter 17: core::iter::adapters::process_results 18: as chalk_ir::fold::SuperFold>::super_fold_with 19: as chalk_ir::fold::Fold>::fold_with 20: chalk_ir::fold::binder_impls:: for chalk_ir::Binders>::fold_with 21: as core::iter::traits::iterator::Iterator>::next 22: as alloc::vec::SpecExtend>::from_iter 23: chalk_ir::fold::subst::Subst::apply 24: chalk_solve::infer::instantiate::>::instantiate_binders_universally 25: as chalk_ir::zip::Zipper>::zip_binders 26: chalk_solve::infer::unify::Unifier::unify_ty_ty 27: as chalk_ir::zip::Zip>::zip_with 28: chalk_solve::infer::unify::Unifier::unify 29: chalk_solve::infer::unify::>::unify 30: chalk_solve::solve::slg::resolvent::> for chalk_solve::solve::slg::TruncatingInferenceTable>::resolvent_clause 31: chalk_engine::logic::>::get_or_create_table_for_ucanonical_goal 32: chalk_engine::logic::>::get_or_create_table_for_subgoal 33: chalk_engine::logic::SolveState::ensure_root_answer 34: as chalk_engine::context::AnswerStream>::any_future_answer 35: as chalk_engine::context::AnswerStream>::next_answer 36: chalk_solve::solve::slg::aggregate::> for chalk_solve::solve::slg::SlgContextOps>::make_solution 37: chalk_engine::forest::Forest::solve 38: ra_hir_ty::traits::trait_solve_query 39: salsa::runtime::Runtime::execute_query_implementation 40: salsa::derived::slot::Slot::database_key 41: salsa::derived::slot::Slot::read 42: as salsa::plumbing::QueryStorageOps>::try_fetch 43: salsa::QueryTable::get 44: ::trait_solve 45: ra_hir_ty::infer::pat::::infer_pat 46: core::ptr::drop_in_place 47: core::ptr::drop_in_place 48: core::ptr::drop_in_place 49: core::ptr::drop_in_place 50: core::ptr::drop_in_place 51: core::ptr::drop_in_place 52: ra_hir_ty::infer::infer_query 53: salsa::runtime::Runtime::execute_query_implementation 54: salsa::derived::slot::Slot::database_key 55: salsa::derived::slot::Slot::read 56: as salsa::plumbing::QueryStorageOps>::try_fetch 57: ::infer_query 58: ra_hir_ty::db::infer_wait 59: rust_analyzer::cli::analysis_stats::analysis_stats 60: ::deserialize_any 61: as alloc::vec::SpecExtend>::from_iter 62: std::rt::lang_start_internal::{{closure}} at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\rt.rs:52 63: std::panicking::try::do_call at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:305 64: panic_unwind::__rust_maybe_catch_panic at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libpanic_unwind\lib.rs:86 65: std::panicking::try at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:281 66: std::panic::catch_unwind at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panic.rs:394 67: std::rt::lang_start_internal at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\rt.rs:51 68: main 69: invoke_main at f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:78 70: __scrt_common_main_seh at f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:283 71: BaseThreadInitThunk 72: RtlUserThreadStart note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. error: process didn't exit successfully: `target\release\rust-analyzer.exe analysis-stats D:\sandbox\rust-root\rust-src` (exit code: 101) ```
JoshMcguigan commented 4 years ago

We recently added a check in CI to be sure rust-analyzer doesn't panic when running analysis-stats in the rust-analyzer repository. I wonder if we should expand that check to cover the rustc repository as well.

edwin0cheng commented 4 years ago

But rustc is so big to fetch from github and there are some others project which are more challenging to analyze too. So I don't see why rustc are so special for us to check explicitly.

However, I think it is a good idea to have external tools to check a bunch of projects analysis-stats. :)

matklad commented 4 years ago

yeah, I think we probably should not block on rustc, both becuase that would take ages, and because rustc is kind of an ultimately horrible code base, so it's OK if we break on it.

But adding a corpus of some other challenging crates might be good idea!

edwin0cheng commented 4 years ago

Updated: there is a new panic:

`DotDotPat` requires special handling and should not be mapped to a Pat.', crates\ra_hir_def\src\body\lower.rs:669:39
Stack trace ``` stack backtrace: 0: backtrace::backtrace::trace_unsynchronized at C:\Users\VssAdministrator\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.40\src\ba 1: std::sys_common::backtrace::_print_fmt at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\sys_common\backtrace.rs:77 2: std::sys_common::backtrace::_print::{{impl}}::fmt at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\sys_common\backtrace.rs:59 3: core::fmt::write at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libcore\fmt\mod.rs:1052 4: std::io::Write::write_fmt at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\io\mod.rs:1426 5: std::sys_common::backtrace::_print at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\sys_common\backtrace.rs:62 6: std::sys_common::backtrace::print at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\sys_common\backtrace.rs:49 7: std::panicking::default_hook::{{closure}} at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:204 8: std::panicking::default_hook at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:224 9: std::panicking::rust_panic_with_hook at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:472 10: std::panicking::begin_panic_handler at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:380 11: std::panicking::begin_panic_fmt at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:334 12: ra_hir_def::body::lower::ExprCollector::collect_pat 13: ra_hir_def::body::lower::ExprCollector::collect_pat 14: ra_hir_def::body::lower::ExprCollector::collect_pat 15: ra_hir_def::body::lower::ExprCollector::collect_pat_opt 16: core::ops::function::impls:: for &mut F>::call_once 17: as alloc::vec::SpecExtend>::from_iter 18: ra_hir_def::body::lower::ExprCollector::collect_expr 19: ra_hir_def::body::lower::ExprCollector::collect_expr_opt 20: ra_hir_def::body::lower::ExprCollector::collect_expr 21: ra_hir_def::body::lower::ExprCollector::collect_expr_opt 22: ra_hir_def::body::lower::lower 23: ra_hir_def::body::Body::body_with_source_map_query 24: salsa::runtime::Runtime::execute_query_implementation 25: salsa::derived::slot::Slot::database_key 26: salsa::derived::slot::Slot::read 27: as salsa::plumbing::QueryStorageOps>::try_fetch 28: ::body_with_source_map 29: ra_hir_def::body::Body::body_query 30: salsa::runtime::Runtime::execute_query_implementation 31: salsa::derived::slot::Slot::database_key 32: salsa::derived::slot::Slot::read 33: as salsa::plumbing::QueryStorageOps>::try_fetch 34: ::body 35: rust_analyzer::cli::analysis_stats::analysis_stats 36: ::fmt 37: <&T as core::fmt::Display>::fmt 38: std::rt::lang_start_internal::{{closure}} at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\rt.rs:52 39: std::panicking::try::do_call at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:305 40: panic_unwind::__rust_maybe_catch_panic at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libpanic_unwind\lib.rs:86 41: std::panicking::try at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:281 42: std::panic::catch_unwind at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panic.rs:394 43: std::rt::lang_start_internal at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\rt.rs:51 44: main 45: invoke_main at d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78 46: __scrt_common_main_seh at d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288 47: BaseThreadInitThunk 48: RtlUserThreadStart note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. ```

Submitted #3999 for details

flodiebold commented 4 years ago

I think these are fixed.