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

error when updating rustc #147

Closed
ehuss opened this issue Jun 4, 2019 · 2 comments · Fixed by #150
Closed

error when updating rustc #147

ehuss opened this issue Jun 4, 2019 · 2 comments · Fixed by #150

Comments

@ehuss
Copy link
Contributor

ehuss commented Jun 4, 2019

I'm trying to update rust-lang/rust to the latest smallvec (0.6.7 ➙ 0.6.9), and an running into an issue where rustc fails to compile:

error: internal compiler error: src/librustc/ty/relate.rs:773: impossible case reached: can't relate: '_#0r with Type(RustaceansAreAwesome)

I have narrowed down the change that breaks this to #137.

I don't know anything about smallvec and very little about rustc, so if anyone can help figure out what's wrong, I'd appreciate it. I'll keep digging a little, but it is unlikely that I'll be able to do more. This can be reproduced with cargo update -p smallvec; ./x.py build (on master, 021a5033098ff0e3f7126acc7ac35149d325f16d).

backtrace
thread 'rustc' panicked at 'Box', src/librustc_errors/lib.rs:637:9
stack backtrace:
   0: std::sys_common::backtrace::print
   1: std::panicking::default_hook::{{closure}}
   2: std::panicking::default_hook
   3: rustc::util::common::panic_hook
   4: std::panicking::rust_panic_with_hook
   5: std::panicking::begin_panic
   6: rustc_errors::Handler::bug
   7: rustc::util::bug::opt_span_bug_fmt::{{closure}}
   8: rustc::ty::context::tls::with_opt::{{closure}}
   9: rustc::ty::context::tls::with_context_opt
  10: rustc::ty::context::tls::with_opt
  11: rustc::util::bug::opt_span_bug_fmt
  12: rustc::util::bug::bug_fmt
  13: ::relate
  14: <&mut I as core::iter::traits::iterator::Iterator>::next
  15:  as core::iter::traits::collect::FromIterator<::Item>>::from_iter
  16:  as rustc::ty::context::InternIteratorElement>::intern_with
  17: rustc::ty::relate::relate_substs
  18: ::relate
  19: rustc::infer::higher_ranked::::higher_ranked_sub
  20: rustc::infer::InferCtxt::commit_if_ok
  21: rustc::traits::select::SelectionContext::match_poly_trait_ref
  22: rustc::infer::InferCtxt::probe
  23: rustc::traits::select::SelectionContext::assemble_candidates
  24: rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache
  25: rustc::dep_graph::graph::DepGraph::with_anon_task
  26: rustc::traits::select::SelectionContext::candidate_from_obligation
  27: rustc::traits::select::SelectionContext::evaluate_stack
  28: rustc::dep_graph::graph::DepGraph::with_anon_task
  29: rustc::traits::select::SelectionContext::evaluate_predicate_recursively
  30: rustc::traits::select::SelectionContext::evaluate_predicates_recursively
  31: rustc::infer::InferCtxt::probe
  32: rustc::traits::select::SelectionContext::evaluate_stack
  33: rustc::dep_graph::graph::DepGraph::with_anon_task
  34: rustc::traits::select::SelectionContext::evaluate_predicate_recursively
  35: rustc::infer::InferCtxt::probe
  36: rustc::traits::select::SelectionContext::evaluate_obligation_recursively
  37: rustc::ty::context::GlobalCtxt::enter_local
  38: rustc_traits::evaluate_obligation::evaluate_obligation
  39: rustc::ty::query::__query_compute::evaluate_obligation
  40: rustc::ty::query::::compute
  41: rustc::dep_graph::graph::DepGraph::with_task_impl
  42: rustc::ty::query::plumbing::::get_query
  43: rustc::traits::query::evaluate_obligation::::evaluate_obligation
  44: rustc::traits::query::evaluate_obligation::::evaluate_obligation_no_overflow
  45: rustc::ty::context::GlobalCtxt::enter_local
  46: rustc::traits::object_safety::::virtual_call_violation_for_method
  47:  as core::iter::traits::iterator::Iterator>::next
  48:  as alloc::vec::SpecExtend>::from_iter
  49: rustc::traits::object_safety::::object_safety_violations_for_trait
  50:  as core::iter::traits::iterator::Iterator>::next
  51:  as alloc::vec::SpecExtend>::from_iter
  52: rustc::traits::object_safety::is_object_safe_provider
  53: rustc::ty::query::::compute
  54: rustc::dep_graph::graph::DepGraph::with_task_impl
  55: rustc::ty::query::plumbing::::get_query
  56: rustc_data_structures::obligation_forest::ObligationForest::process_obligations
  57: ::select_where_possible
  58: ::select_all_or_error
  59: rustc_typeck::check::FnCtxt::select_all_obligations_or_error
  60: rustc::ty::context::GlobalCtxt::enter_local
  61: rustc_typeck::check::wfcheck::check_item_well_formed
  62: rustc::ty::query::__query_compute::check_item_well_formed
  63: rustc::ty::query::::compute
  64: rustc::dep_graph::graph::DepGraph::with_task_impl
  65: rustc::ty::query::plumbing::::get_query
  66: ::visit_item
  67: __rust_maybe_catch_panic
  68: rustc_data_structures::sync::par_for_each_in
  69: __rust_maybe_catch_panic
  70: rustc::hir::Crate::par_visit_all_item_likes
  71: rustc::util::common::time
  72: rustc_typeck::check_crate
  73: rustc_interface::passes::analysis
  74: rustc::ty::query::__query_compute::analysis
  75: rustc::dep_graph::graph::DepGraph::with_task_impl
  76: rustc::ty::query::plumbing::::get_query
  77: rustc::ty::context::tls::enter_global
  78: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  79: rustc_interface::passes::create_global_ctxt::{{closure}}
  80: rustc_interface::interface::run_compiler_in_existing_thread_pool
  81: std::thread::local::LocalKey::with
  82: scoped_tls::ScopedKey::set
  83: syntax::with_globals
@emilio
Copy link
Member

emilio commented Jun 4, 2019

This looks like a rust bug that should be reported upstream.

@ehuss
Copy link
Contributor Author

ehuss commented Jun 5, 2019

Reported upstream: rust-lang/rust#61549

bors-servo pushed a commit that referenced this issue Jun 8, 2019
Fix `extend` from assuming a fused iterator.

Iterators may resume after returning None.  I think it is generally expected that `extend` should stop on the first None.

Fixes #147.  Specifically, in rustc, there are some situations where an iterator of Results are collected into a `Result<SmallVec, _>` (such as [here](https://github.com/rust-lang/rust/blob/c1c60d292e2dd2deff7084208274f9a02f750d43/src/librustc/ty/relate.rs#L139-L142) which ends up in [this call to `collect`](https://github.com/rust-lang/rust/blob/c1c60d292e2dd2deff7084208274f9a02f750d43/src/librustc/ty/context.rs#L3002)).  The [Result adapter](https://github.com/rust-lang/rust/blob/c1c60d292e2dd2deff7084208274f9a02f750d43/src/libcore/result.rs#L1245-L1258) returns None for the first `Err` in the sequence.  However, it is possible for an iterator to have additional elements after the first Err.  With this bug, SmallVec was falling through to the slow-path `for` loop, and resuming the iterator grabbing too many elements.  I believe this was having some bad interactions with the type interner where the additional elements after the `Err` were getting processed (via a `map()`) and interned when they shouldn't be (or otherwise having some side effects from the `map`).

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-smallvec/150)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants