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

size_of of associated type ICEs #43357

Closed
kennytm opened this issue Jul 20, 2017 · 7 comments
Closed

size_of of associated type ICEs #43357

kennytm opened this issue Jul 20, 2017 · 7 comments
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.

Comments

@kennytm
Copy link
Member

kennytm commented Jul 20, 2017

Originally reported in #43355, which should be a different bug from the main report.

trait Trait1 {
    type Output;
}
fn f<T: Trait1>() {
    ::std::mem::size_of::<T::Output>();
}
fn main() {}

On nightly, crashes with:

$ RUST_BACKTRACE=1 rustc 1.rs
error: internal compiler error: src/librustc/infer/mod.rs:573: Encountered errors `[FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<T as Trait1>)),depth=0),Unimplemented)]` resolving bounds after type-checking

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.20.0-nightly (582af6e1a 2017-07-19) running on x86_64-apple-darwin

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:437:8
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   8: rustc::session::span_bug_fmt
   9: <&'gcx rustc::ty::TyS<'gcx> as rustc::infer::TransNormalize<'gcx>>::trans_normalize
  10: rustc::infer::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'tcx>>::normalize_associated_type_in_env
  11: rustc::ty::layout::Layout::compute_uncached
  12: rustc::ty::util::layout_raw
  13: rustc::ty::maps::<impl rustc::ty::maps::queries::layout_raw<'tcx>>::try_get
  14: rustc::ty::maps::TyCtxtAt::layout_raw
  15: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::layout_raw
  16: rustc_const_eval::eval::eval_const_expr_partial::{{closure}}
  17: rustc_const_eval::eval::eval_const_expr_partial
  18: rustc_const_eval::eval::eval_const_expr_partial
  19: rustc_const_eval::eval::eval_const_expr_partial
  20: rustc_const_eval::eval::eval_const_expr_partial
  21: rustc_const_eval::eval::ConstContext::eval
  22: <rustc_passes::consts::CheckCrateVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  23: <rustc_passes::consts::CheckCrateVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  24: <rustc_passes::consts::CheckCrateVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_nested_body
  25: rustc_passes::consts::check_crate
  26: rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}
  27: rustc_driver::driver::phase_3_run_analysis_passes
  28: rustc_driver::driver::compile_input
  29: rustc_driver::run_compiler

Does not crash with 1.20.0-beta.1 (e93aa3aa8 2017-07-18).

cc @eddyb #42859, which is relevant and is inside the commit range e93aa3a...582af6e.

@eddyb
Copy link
Member

eddyb commented Jul 20, 2017

Hmm, the fact normalize_projections_in uses drain_fulfillment_cx_or_panic which panics, is unfortunate. What I would want to happen is to get the unmodified value if there are any errors.

cc @arielb1 Was the layout code always going to ICE like that? Or did it get changed? Transmute checking uses it and that shouldn't ever ICE.

@eddyb
Copy link
Member

eddyb commented Jul 20, 2017

The snippet below gives the right error, so likely I used the wrong way to get the layout.

fn f<T: ::std::ops::Neg>(x: T) -> T::Output {
    ::std::mem::transmute(x)
}

@qnighy
Copy link
Contributor

qnighy commented Jul 22, 2017

Duplicate of #43394?

@eddyb
Copy link
Member

eddyb commented Jul 22, 2017

@qnighy Yes, but the other way around, #43394 is a (more recent) duplicate of this issue.

@arielb1
Copy link
Contributor

arielb1 commented Jul 24, 2017

The problem is that const_eval is calling for layout while throwing the param-env on the floor, so the types are not known to be WF:

let layout_of = |ty: Ty<'tcx>| {

            let layout_of = |ty: Ty<'tcx>| {
                ty.layout(tcx, ty::ParamEnv::empty(traits::Reveal::All))
                    .map_err(|err| {
                        ConstEvalErr { span: e.span, kind: LayoutError(err) }
                    })
            };

It should either use the "correct" param env (so that the types will still be WF) or it should bail out when it sees a generic type.

@eddyb
Copy link
Member

eddyb commented Jul 24, 2017

Ah, I see, I'll try to plumb the ParamEnv through it (this is the rustc_passes::consts code triggering evaluation in regular functions to emit certain warnings).

@timxor
Copy link

timxor commented Jul 27, 2017

+1

my rust cargo bench error using nightly build

=>cargo bench
   Compiling ethcore v1.7.0 (file:///Users/timsiwula/Desktop/metropolis_testing/testing_hub/clients/parity/ethcore)
error: internal compiler error: src/librustc/infer/mod.rs:573: Encountered errors [FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<K as verification::queue::kind::Kind>)),depth=0),Unimplemented)]  resolving bounds after type-checking
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.21.0-nightly (599be0d18 2017-07-26) running on x86_64-apple-darwin
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:438:8
note: Run with RUST_BACKTRACE=1 for a backtrace.
error: Could not compile ethcore.
warning: build failed, waiting for other jobs to finish...
error: internal compiler error: src/librustc/infer/mod.rs:573: Encountered errors [FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<K as verification::queue::kind::Kind>)),depth=0),Unimplemented)] resolving bounds after type-checking
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.21.0-nightly (599be0d18 2017-07-26) running on x86_64-apple-darwin
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:438:8
note: Run with RUST_BACKTRACE=1 for a backtrace.
error: Could not compile `ethcore`.
To learn more, run the command again with --verbose.
=>

bors added a commit that referenced this issue Jul 28, 2017
rustc_const_eval: always require Substs and a ParamEnv.

Fixes #43357 by tracking the `Substs` and `ParamEnv` for const-evaluation in generic contexts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.
Projects
None yet
Development

No branches or pull requests

7 participants