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

ICE on sized-chunks crate #4121

Closed
ehuss opened this issue May 20, 2019 · 11 comments · Fixed by #4245
Closed

ICE on sized-chunks crate #4121

ehuss opened this issue May 20, 2019 · 11 comments · Fixed by #4245
Labels
E-needs-test Call for participation: writing tests I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@ehuss
Copy link
Contributor

ehuss commented May 20, 2019

The sized-chunks v0.3.0 crate is causing an ICE in latest clippy. I do not know where to start debugging this.

clippy 0.0.212 (60a609a 2019-05-17)
error: internal compiler error: src/librustc/ty/subst.rs:569: type parameter `T/#1` (T/1) out of range when substituting (root type=Some(T)) substs=[T]

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:572: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 src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:59
             at src/libstd/panicking.rs:197
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:211
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:478
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::span_bug
   8: rustc::util::bug::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::util::bug::opt_span_bug_fmt
  13: rustc::util::bug::span_bug_fmt
  14: <rustc::ty::subst::SubstFolder as rustc::ty::fold::TypeFolder>::fold_ty
  15: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
  16: <smallvec::SmallVec<A> as core::iter::traits::collect::FromIterator<<A as smallvec::Array>::Item>>::from_iter
  17: rustc::ty::fold::TypeFoldable::fold_with
  18: rustc::traits::codegen::<impl rustc::ty::context::TyCtxt>::subst_and_normalize_erasing_regions
  19: rustc_mir::interpret::eval_context::InterpretCx<M>::resolve
  20: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpretCx<M>>::run
  21: rustc_mir::const_eval::eval_body_using_ecx
  22: rustc_mir::const_eval::const_eval_raw_provider
  23: rustc::ty::query::__query_compute::const_eval_raw
  24: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_raw>::compute
  25: rustc::dep_graph::graph::DepGraph::with_task_impl
  26: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  27: rustc_mir::const_eval::const_eval_provider
  28: rustc::ty::query::__query_compute::const_eval
  29: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval>::compute
  30: rustc::dep_graph::graph::DepGraph::with_task_impl
  31: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  32: clippy_lints::consts::ConstEvalLateContext::expr
  33: clippy_lints::consts::ConstEvalLateContext::expr
  34: clippy_lints::consts::constant_simple
  35: clippy_lints::utils::hir_utils::SpanlessEq::eq_expr
  36: <clippy_lints::eq_op::EqOp as rustc::lint::LateLintPass>::check_expr
  37: <rustc::lint::context::LateLintPassObjects as rustc::lint::LateLintPass>::check_expr
  38: <rustc::lint::context::LateContextAndPass<T> as rustc::hir::intravisit::Visitor>::visit_expr
  39: <rustc::lint::context::LateContextAndPass<T> as rustc::hir::intravisit::Visitor>::visit_nested_body
  40: rustc::hir::intravisit::Visitor::visit_nested_impl_item
  41: rustc::hir::intravisit::walk_item
  42: rustc::hir::intravisit::Visitor::visit_nested_item
  43: rustc::hir::intravisit::walk_item
  44: rustc::hir::intravisit::Visitor::visit_nested_item
  45: rustc::hir::intravisit::walk_crate
  46: rustc::lint::context::late_lint_pass_crate
  47: rustc::lint::context::late_lint_crate
  48: rustc::util::common::time
  49: rustc::util::common::time
  50: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:85
  51: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  52: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:85
  53: rustc_interface::passes::analysis::{{closure}}
  54: rustc::util::common::time
  55: rustc_interface::passes::analysis
  56: rustc::ty::query::__query_compute::analysis
  57: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::analysis>::compute
  58: rustc::dep_graph::graph::DepGraph::with_task_impl
  59: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  60: rustc::ty::context::tls::enter_global
  61: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  62: rustc_interface::passes::create_global_ctxt::{{closure}}
  63: rustc_interface::interface::run_compiler_in_existing_thread_pool
  64: std::thread::local::LocalKey<T>::with
  65: scoped_tls::ScopedKey<T>::set
  66: syntax::with_globals
query stack during panic:
#0 [const_eval_raw] const-evaluating `inline_array::InlineArray::<A, T>::HOST_SIZE`
#1 [const_eval] const-evaluating + checking `inline_array::InlineArray::<A, T>::HOST_SIZE`
#2 [analysis] running analysis passes on this crate
end of query stack
@phansch phansch added the I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ label May 20, 2019
@phansch phansch self-assigned this May 20, 2019
@phansch
Copy link
Member

phansch commented May 20, 2019

Going to investigate this now and try to get a minimal repro case.

@phansch
Copy link
Member

phansch commented May 20, 2019

Minimal repro:

use std::mem::{self};

pub struct Foo<A, B>(A, B);

impl<A, B> Foo<A, B> {
    const HOST_SIZE: usize = mem::size_of::<B>();

    pub fn crash() -> bool {
        Self::HOST_SIZE == 0
    }
}

The conditional triggers the crash. It crashes here, called from the eq_op lint:

let result = self.lcx.tcx.const_eval(self.param_env.and(gid)).ok()?;

Unfortunately I ran out of time for today, so if someone want's to continue with this, feel free.

@Manishearth
Copy link
Member

cc @oli-obk

@phansch phansch removed their assignment May 20, 2019
@phansch
Copy link
Member

phansch commented May 21, 2019

Managed to further reduce the example (updated above) and got some initial debug output of the data that causes the crash. Unfortunately there's nothing that stands out as outright wrong so far:

[clippy_lints/src/eq_op.rs:58] left = expr(HirId { owner: DefIndex(24), local_id: 4 }: <Self>::HOST_SIZE)
[clippy_lints/src/eq_op.rs:59] right = expr(HirId { owner: DefIndex(24), local_id: 5 }: 1)
[clippy_lints/src/consts.rs:342] self.param_env = ParamEnv {
    caller_bounds: [
        Binder(
            TraitPredicate(<B as std::marker::Sized>),
        ),
        Binder(
            TraitPredicate(<A as std::marker::Sized>),
        ),
    ],
    reveal: UserFacing,
    def_id: None,
}
[clippy_lints/src/consts.rs:343] substs = [
    A,
    B,
]

Perhaps we should just skip generics in eq_op?

@oli-obk
Copy link
Contributor

oli-obk commented May 21, 2019

Perhaps we should just skip generics in eq_op?

tcx.const_eval should be returning TooGeneric if it can't solve it. I'll investigate why it doesn't.

One thing that I see that's odd is

let substs = if self.substs.is_empty() {

This will always be true.

@oli-obk
Copy link
Contributor

oli-obk commented May 22, 2019

I've found the problem, it is in rustc. Currently trying to create a rustc-only ICE

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jul 1, 2019

Can anyone confirm that the bug is no longer present? (clippy 0.0.212 (e3cb40e 2019-06-25))

@mati865
Copy link
Contributor

mati865 commented Jul 1, 2019

#4121 (comment) doesn't crash with nightly-2019-07-01.

@matthiaskrgr
Copy link
Member

I checked both the reduced code and the sized-chunks crate and neither crashed clippy.

@matthiaskrgr matthiaskrgr added the E-needs-test Call for participation: writing tests label Jul 1, 2019
@flip1995
Copy link
Member

flip1995 commented Jul 1, 2019

I'll add a test in a minute 👍

flip1995 added a commit to flip1995/rust-clippy that referenced this issue Jul 1, 2019
bors added a commit that referenced this issue Jul 1, 2019
Test for melted ICE #4121

resolves #4121

r? @matthiaskrgr

changelog: none
@bors bors closed this as completed in #4245 Jul 1, 2019
@oli-obk
Copy link
Contributor

oli-obk commented Aug 20, 2019

Uh... how was this fixed without rust-lang/rust#63497 ? Did we accidentally add a workaround in clippy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: writing tests I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants