rust-lang / rust

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

rayon type inference regression #49062

Open cuviper opened 6 years ago

cuviper commented 6 years ago

The rayon tests are encountering a new type inference failure, and with the latest nightly, an ICE.

$ git describe HEAD
v1.0.0-14-g68aabe9e460f

$ rustc +nightly-2018-03-15 -Vv
rustc 1.26.0-nightly (521d91c6b 2018-03-14)
binary: rustc
commit-hash: 521d91c6be76367d966df419677dd187f799b116
commit-date: 2018-03-14
host: x86_64-unknown-linux-gnu
release: 1.26.0-nightly
LLVM version: 6.0

$ cargo +nightly-2018-03-15 test --lib --no-run
   Compiling [deps...]
   Compiling rayon v1.0.0 (file:///home/jistone/rust/rayon)
error[E0283]: type annotations required: cannot resolve `_: std::iter::Sum<&usize>`
   --> src/iter/test.rs:283:54
    |
283 |     assert_eq!(num.load(Ordering::Relaxed), a.iter().sum());
    |                                                      ^^^

error: internal compiler error: librustc/ich/impls_ty.rs:907: ty::TypeVariants::hash_stable() - Unexpected variant TyInfer(?0).

thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:540:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at libstd/sys_common/backtrace.rs:59
             at libstd/panicking.rs:207
   3: std::panicking::default_hook
             at libstd/panicking.rs:223
   4: core::ops::function::Fn::call
   5: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:403
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::bug
   8: rustc::session::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: <std::thread::local::LocalKey<T>>::try_with
  11: <std::thread::local::LocalKey<T>>::with
  12: rustc::ty::context::tls::with
  13: rustc::ty::context::tls::with_opt
  14: rustc::session::opt_span_bug_fmt
  15: rustc::session::bug_fmt
  16: rustc::ich::impls_ty::<impl rustc_data_structures::stable_hasher::HashStable<rustc::ich::hcx::StableHashingContext<'a>> for rustc::ty::sty::TypeVariants<'gcx>>::hash_stable
  17: rustc::dep_graph::dep_node::DepNode::new
  18: rustc::ty::maps::<impl rustc::ty::maps::queries::dropck_outlives<'tcx>>::try_get
  19: rustc::ty::maps::TyCtxtAt::dropck_outlives
  20: rustc::traits::query::dropck_outlives::<impl rustc::infer::at::At<'cx, 'gcx, 'tcx>>::dropck_outlives
  21: rustc_typeck::check::dropck::check_safety_of_destructor_if_necessary
  22: rustc::hir::Pat::walk_
  23: <rustc_typeck::check::regionck::RegionCtxt<'a, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_local
  24: rustc::hir::intravisit::walk_expr
  25: <rustc_typeck::check::regionck::RegionCtxt<'a, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_expr
  26: rustc_typeck::check::regionck::RegionCtxt::visit_fn_body
  27: rustc_typeck::check::typeck_tables_of::{{closure}}
  28: rustc_typeck::check::typeck_tables_of
  29: rustc::dep_graph::graph::DepGraph::with_task_impl
  30: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::force
  31: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::try_get
  32: rustc::ty::maps::TyCtxtAt::typeck_tables_of
  33: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::ensure
  34: rustc_typeck::check::typeck_item_bodies
  35: rustc::dep_graph::graph::DepGraph::with_task_impl
  36: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::force
  37: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::try_get
  38: rustc::ty::maps::TyCtxtAt::typeck_item_bodies
  39: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_item_bodies
  40: rustc_typeck::check_crate
  41: rustc::ty::context::TyCtxt::create_and_enter
  42: rustc_driver::driver::compile_input
  43: rustc_driver::run_compiler

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.26.0-nightly (521d91c6b 2018-03-14) running on x86_64-unknown-linux-gnu

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

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

error: Could not compile `rayon`.

With nightly-2018-03-07, it reports the same "type annotations required" error, but no ICE.

The error itself is new to us, as just a few days ago we had no problem in CI. I narrowed this down to an update to compilertest_rs, from 0.3.7 to 0.3.8, even though that crate is not directly involved in the test that has the error. With 0.3.7, even the currently nightly is fine. With 0.3.8, nightly-2018-03-15 has the error and ICE, and nightly-2018-03-07 back to 2018-01-28 just have the error. (Earlier than that, 0.3.8 doesn't compile at all due to differences in the test crate.)

michaelwoerister commented 6 years ago

Same problem as https://github.com/rust-lang/rust/issues/49043.

nikomatsakis commented 6 years ago

triage: P-high

nikomatsakis commented 6 years ago

So, the ICE should be fixed, but the type inference failure perhaps not.

cuviper commented 6 years ago

Confirmed, no ICE with rustc 1.26.0-nightly (75af15ee6 2018-03-20).

It still would be nice to root-cause the inference failure from afar, effected by the dependency update. But FWIW I did commit the necessary type annotations to rayon master already. For reproducing the issue, the prior branch head was rayon-rs/rayon@68aabe9e460f.

nikomatsakis commented 6 years ago

@cuviper hmm, i'm not able to reproduce this from that commit. I tried with a recent build and with nightly:

lunch-box. cargo +nightly build
   Compiling cfg-if v0.1.2
   Compiling nodrop v0.1.12
   Compiling scopeguard v0.3.3
   Compiling lazy_static v1.0.0
   Compiling memoffset v0.2.1
   Compiling rayon-core v1.4.0 (file:///home/nmatsakis/versioned/rust-1/regr/rayon/rayon-core)
   Compiling libc v0.2.40
   Compiling either v1.5.0
   Compiling crossbeam-utils v0.2.2
   Compiling arrayvec v0.4.7
   Compiling crossbeam-epoch v0.3.1
   Compiling rand v0.4.2
   Compiling num_cpus v1.8.0
   Compiling crossbeam-deque v0.2.0
   Compiling rayon v1.0.0 (file:///home/nmatsakis/versioned/rust-1/regr/rayon)
    Finished dev [unoptimized + debuginfo] target(s) in 8.18 secs
lunch-box. git show HEAD | head -1
commit 68aabe9e460f11d5ed936a3db6101a334df426a9
nikomatsakis commented 6 years ago

Oh, maybe it's testing.

cuviper commented 6 years ago

Yeah, it's with cargo test --lib. Still fails with rustc 1.27.0-nightly (fb44b4c0e 2018-04-04).

Although I'm not sure anymore if it's correct to call this a regression, or just a mysterious type ambiguity introduced by the dependency updates. Could the compiler give hints with cannot resolve `_: std::iter::Sum<&usize>`, maybe listing some of the possible types it knows? At a glance, it seems like this could only be a usize, but I guess some crate may have another Sum<&usize>.

nikomatsakis commented 6 years ago

OK after some investigation I have successfully reproduced what @cuviper told me the whole time: that is, this is a very long-standing error, but the confusing thing is why the change to compiletest is triggering it.

pnkfelix commented 6 years ago

triage: P-medium

downgrading since ICE has been addressed. The type inference change is potentially interesting and niko wouldlike to track it down, but its not P-high.