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 in region inference #32323

Closed
sapphire-arches opened this issue Mar 17, 2016 · 5 comments
Closed

ICE in region inference #32323

sapphire-arches opened this issue Mar 17, 2016 · 5 comments
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@sapphire-arches
Copy link
Contributor

Hello, I have a found an ICE. The code is malformed (no return from a function that should return a value) but I don't think the compiler should be crashing in this case =P

use std::path::Path;

pub trait AnalysisStage<'input_lifetime>: PartialEq {
    type Input: ?Sized; 
    type Output;

    fn stage_name() -> String; 

    fn analyze(&self, input: &'input_lifetime Self::Input) -> Self::Output;
}

pub fn run_cached_stage<'a, T: AnalysisStage<'a>>(
        cache_dir: &Path,
        stage: &T,
        input: &'a <T as AnalysisStage<'a>>::Input) -> <T as AnalysisStage<'a>>::Output {
    assert!(cache_dir.is_dir());
}

pub fn main() {
}

Returning a value run_cached_stage allows the code to compile successfully.
Stack trace:

error: internal compiler error: cannot relate bound region: ReFree(CodeExtent(13/CallSiteScope { fn_id: 27, body_id: 51 }), BrNamed(DefId { krate: 0, node: DefIndex(19) => run_cached_stage::'a }, 'a(77))) <= ReEarlyBound(FnSpace, 0, 'a)
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
thread 'rustc' panicked at 'Box<Any>', ../src/libsyntax/errors/mod.rs:530
stack backtrace:
   1:     0x7f3978902240 - sys::backtrace::tracing::imp::write::h3bbb320d569781f92cv
   2:     0x7f397890c43f - panicking::default_handler::_$u7b$$u7b$closure$u7d$$u7d$::closure.44520
   3:     0x7f397890bfb3 - panicking::default_handler::hf1209fec3f963ae7H0z
   4:     0x7f39788d442c - sys_common::unwind::begin_unwind_inner::h2ff9ae045f111c6dg2t
   5:     0x7f3975b04138 - sys_common::unwind::begin_unwind::h14144787524125971391
   6:     0x7f3975b040db - errors::Handler::span_bug::h15395824936343975365
   7:     0x7f3975bc06f9 - middle::infer::region_inference::RegionVarBindings<'a, 'tcx>::make_subregion::h7f3bb27940126b6cQrz
   8:     0x7f3975bed867 - middle::infer::region_inference::RegionVarBindings<'a, 'tcx>::make_eqregion::h564a0fc4f5b6b7821qz
   9:     0x7f3975bc7f1f - middle::infer::equate::Equate<'a, 'tcx>.TypeRelation<'a, 'tcx>::regions::h056e51c9a2b47ea92hu
  10:     0x7f3975bcdcad - middle::infer::sub::Sub<'a, 'tcx>.TypeRelation<'a, 'tcx>::relate_with_variance::h16084476242674243829
  11:     0x7f3975bcda7f - iter::_&'a mut I.Iterator::next::h492841943347951705
  12:     0x7f3975bcc6dd - middle::ty::relate::relate_substs::h2175710387140620551
  13:     0x7f3975bcbddb - middle::ty::relate::relate_item_substs::h5133697730217601403
  14:     0x7f3975bcbb63 - middle::ty::relate::ty..TraitRef<'tcx>.Relate<'a, 'tcx>::relate::h15531786425531683161
  15:     0x7f3975bc9303 - middle::infer::higher_ranked::CombineFields<'a, 'tcx>.HigherRankedRelations<'a, 'tcx>::higher_ranked_sub::_$u7b$$u7b$closure$u7d$$u7d$::closure.87339
  16:     0x7f3975bc12a0 - middle::infer::InferCtxt<'a, 'tcx>::sub_poly_trait_refs::h38716118db114552sqD
  17:     0x7f3975ccb3ab - vec::Vec<T>::extend_desugared::h6748634469442663400
  18:     0x7f3975cc9823 - middle::traits::select::SelectionContext<'cx, 'tcx>::assemble_candidates::hc79fe626cc8f2447GJX
  19:     0x7f3975cbe361 - middle::traits::select::SelectionContext<'cx, 'tcx>::candidate_from_obligation::he1a867beeb5c08d8ynX
  20:     0x7f3975b8e5b7 - middle::traits::select::SelectionContext<'cx, 'tcx>::select::hec21f8105af275d4lTW
  21:     0x7f3975cb4e0a - middle::traits::project::assemble_candidates_from_impls::h50fbb432cce6c3cfCtV
  22:     0x7f3975cb11fb - middle::traits::project::opt_normalize_projection_type::hac249e56767be130BSU
  23:     0x7f3975c9e356 - middle::traits::project::normalize_projection_type::h5c927accb52af237qRU
  24:     0x7f3975bdb6fb - middle::traits::project::AssociatedTypeNormalizer<'a, 'b, 'tcx>.TypeFolder<'tcx>::fold_ty::h023fb72f91feb19c7OU
  25:     0x7f3975c4ac2b - middle::traits::project::normalize_with_depth::h10247183156909553401
  26:     0x7f3975c40d39 - middle::liveness::visit_fn::h36d110105e9b0ae90sG
  27:     0x7f3975c430dd - middle::liveness::check_crate::h0720a363ef7389bcYbG
  28:     0x7f3978e32fe1 - driver::phase_3_run_analysis_passes::_$u7b$$u7b$closure$u7d$$u7d$::closure.30392
  29:     0x7f3978e2fc64 - middle::ty::context::TyCtxt<'tcx>::create_and_enter::h9147142471428683876
  30:     0x7f3978e2c842 - driver::phase_3_run_analysis_passes::h401012091542974636
  31:     0x7f3978dff03f - driver::compile_input::h5061645098a52196Pca
  32:     0x7f3978dec90c - run_compiler::hf1a385ebc338137cJPc
  33:     0x7f3978de9f91 - sys_common::unwind::try::try_fn::h13370330027690439195
  34:     0x7f39788ffacb - __rust_try
  35:     0x7f39788ffa5d - sys_common::unwind::inner_try::h87a6865a03ff0831iZt
  36:     0x7f3978dea7da - boxed::F.FnBox<A>::call_box::h11886714385289713998
  37:     0x7f397890a549 - sys::thread::Thread::new::thread_start::haca995caeb3b74699Xy
  38:     0x7f3971010423 - start_thread
  39:     0x7f3978587cbc - clone
  40:                0x0 - <unknown>

Rustc version:

rustc 1.9.0-nightly (6e0f2f2f0 2016-03-16)
binary: rustc
commit-hash: 6e0f2f2f050443f2aec4e9c7d25618a6a6639b83
commit-date: 2016-03-16
host: x86_64-unknown-linux-gnu
release: 1.9.0-nightly
@jonas-schievink
Copy link
Contributor

Pretty sure that was me.

@jonas-schievink
Copy link
Contributor

Minified:

pub trait Tr<'a> {
    type Out;
}

pub fn f<'a, T: Tr<'a>>() -> <T as Tr<'a>>::Out {}

pub fn main() {}

Note that the Playpen doesn't yet run the latest nightly, so it's not reproducible there.

@jonas-schievink
Copy link
Contributor

The issue is of course the use of the "bound region" aka lifetime parameter 'a (ReEarlyBound(FnSpace, 0, 'a)) in the projection. It needs to be handled differently. What "differently" entails I'll try to figure out tomorrow.

@sanxiyn sanxiyn added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Mar 18, 2016
@arielb1
Copy link
Contributor

arielb1 commented Mar 18, 2016

Yeah I forgot about that. You need to .subst(param_env.free_substs).

@jonas-schievink
Copy link
Contributor

PR opened. @bobtwinkles thanks for the quick report!

eddyb added a commit to eddyb/rust that referenced this issue Mar 19, 2016
liveness: substitute bound regions with free ones before normalizing the return type

Fixes rust-lang#32323

r? @arielb1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

4 participants