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

Type inference ICE: assertion failed: !self.obligations_in_snapshot.get() #36053

Closed
Stebalien opened this issue Aug 27, 2016 · 12 comments
Closed
Assignees
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Stebalien
Copy link
Contributor

Stebalien commented Aug 27, 2016

Type inference is barfing on:

use std::iter::once;
fn main() {
    once::<&str>("str").fuse().filter(|a: &str| true).count();
}

This only happens to iterators over &strs types with lifetime parameters and only happens when fused, mapped or filtered, than "operated" on (e.g., counted).

The following works:

use std::iter::once;
use std::marker::PhantomData;

struct Test(&'static str);

fn main() {
    once(Test("asdf")).fuse().filter(|_| true).count();
}

Trace:

error: internal compiler error: unexpected panic

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: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'assertion failed: !self.obligations_in_snapshot.get()', ../src/librustc/infer/mod.rs:892
stack backtrace:
   1:      0x385616e5833 - std::sys::backtrace::tracing::imp::write::h482d45d91246faa2
   2:      0x385616f611d - std::panicking::default_hook::_{{closure}}::h89158f66286b674e
   3:      0x385616f466d - std::panicking::default_hook::h9e30d428ee3b0c43
   4:      0x385616f4d68 - std::panicking::rust_panic_with_hook::h2224f33fb7bf2f4c
   5:      0x3855e7daf2f - std::panicking::begin_panic::h6da27a7ee15843ce
   6:      0x3855e9365e2 - rustc::infer::InferCtxt::rollback_to::ha2f21524af8937ee
   7:      0x3855fea7ca3 - rustc_typeck::check::method::probe::ProbeContext::consider_candidates::_{{closure}}::hd73cab1de5c62a79
   8:      0x3855fdebe5c - rustc_typeck::check::method::probe::ProbeContext::consider_candidates::hc4fd590b3d2a253e
   9:      0x3855fdebb77 - rustc_typeck::check::method::probe::ProbeContext::pick_method::ha1525cf018083b3f
  10:      0x3855fdeb0ca - rustc_typeck::check::method::probe::ProbeContext::pick_core::h8fe845d303e00275
  11:      0x3855fea4ecc - rustc_typeck::check::method::probe::_<impl rustc_typeck..check..FnCtxt<'a, 'gcx, 'tcx>>::probe_method::_{{closure}}::h4cc364b0888ee90b
  12:      0x3855fde7fda - rustc_typeck::check::method::probe::_<impl rustc_typeck..check..FnCtxt<'a, 'gcx, 'tcx>>::probe_method::h5bcb89eaeb8b15c2
  13:      0x3855fdf278c - rustc_typeck::check::method::_<impl rustc_typeck..check..FnCtxt<'a, 'gcx, 'tcx>>::lookup_method::ha4b60fa1e48e18d1
  14:      0x3855fe4c2df - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref::h057aec20877fc49f
  15:      0x3855fe4ed90 - rustc_typeck::check::FnCtxt::check_stmt::h0a693585a954d704
  16:      0x3855fe4f177 - rustc_typeck::check::FnCtxt::check_block_with_expected::he043b17dca8afd62
  17:      0x3855fe2245f - rustc_typeck::check::check_fn::hd55e09cd766201af
  18:      0x3855fe20c1d - rustc_typeck::check::check_bare_fn::h56d8f43b26a6d362
  19:      0x3855fe240a9 - rustc_typeck::check::check_item_body::h7d7e664619f18e7f
  20:      0x3855fe1e088 - rustc_typeck::check::check_item_bodies::h7d884d53a15202d6
  21:      0x3855fe89f53 - rustc_typeck::check_crate::h8ec8b2f490f5dc28
  22:      0x38561ad739e - rustc_driver::driver::phase_3_run_analysis_passes::_{{closure}}::h45e03cee16dcf298
  23:      0x38561a2ca9f - rustc::ty::context::TyCtxt::create_and_enter::h0021bc4caf3a2e06
  24:      0x38561a9dfb4 - rustc_driver::driver::compile_input::hd9ecc57abd3cba85
  25:      0x38561ac40ad - rustc_driver::run_compiler::h184264500271cc39
  26:      0x38561a05b63 - std::panicking::try::do_call::h17a7a17ad7240c5c
  27:      0x38561704336 - __rust_maybe_catch_panic
  28:      0x38561a22f59 - _<F as alloc..boxed..FnBox<A>>::call_box::h95ef76c8d48c6f60
  29:      0x385616f2ba0 - std::sys::thread::Thread::new::thread_start::he0bf102845911132
  30:      0x38559b60453 - start_thread
  31:      0x385613437de - __GI___clone
  32:                0x0 - <unknown>
@apasel422 apasel422 added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Aug 27, 2016
@jonas-schievink
Copy link
Contributor

What Rust version is that? Can't reproduce on the Playpen

@Stebalien
Copy link
Contributor Author

linux, x86_64, rustc 1.13.0-nightly (e9bc1ba 2016-08-24)

@Stebalien
Copy link
Contributor Author

Same on 1.13.0-nightly (1987131 2016-08-26)

@Stebalien
Copy link
Contributor Author

Also happens on http://play.integer32.com/

@jonas-schievink
Copy link
Contributor

jonas-schievink commented Aug 27, 2016

Ah I see. Does not reproduce on rustc 1.13.0-nightly (f883b0b 2016-08-19)

EDIT: Nor on rustc 1.13.0-nightly (3c5a0fa 2016-08-22)

@Stebalien
Copy link
Contributor Author

Note: This was is probably related to specialization. It's definitely not at all related to #35656, I don't even know why you would suggest that. Any suggestion that uncommenting the commented line below is at all related to this problem will be met with derision:

#![feature(fused)]
use std::iter::FusedIterator;

struct Thing<'a>(&'a str);
impl<'a> Iterator for Thing<'a> {
    type Item = &'a str;
    fn next(&mut self) -> Option<&'a str> {
        None
    }
}

//impl<'a> FusedIterator for Thing<'a> {}

fn main() {
    Thing("test").fuse().filter(|_| true).count();
}

/cc @alexcrichton @aturon

@alexcrichton alexcrichton added I-nominated regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 28, 2016
@nikomatsakis
Copy link
Contributor

triage: P-high

Regression, seems bad. @arielb1 says he'll take a look at it.

@rust-highfive rust-highfive added P-high High priority and removed I-nominated labels Sep 1, 2016
@arielb1
Copy link
Contributor

arielb1 commented Sep 1, 2016

The problem is that rustc::traits::specialize::translate_substs, which is called during normalization, is registering obligations into the global fulfillcx creating its own internal fulfillcx, and accidentally setting a flag during method probing.

@nikomatsakis nikomatsakis self-assigned this Sep 13, 2016
@nikomatsakis
Copy link
Contributor

I'll try to gin up a patch, since I think @arielb1 is busy.

@nikomatsakis
Copy link
Contributor

@arielb1 do you agree that this is basically a "false positive" of the problem that this check was designed to prevent?

@nikomatsakis
Copy link
Contributor

(and hence an ok fix is just to save/restore the flag?)

@nikomatsakis
Copy link
Contributor

maybe a better fix is to have fulfillment cx be parameterized by whether to set the flag

Manishearth added a commit to Manishearth/rust that referenced this issue Sep 15, 2016
clear obligations-added flag with nested fulfillcx

This flag is a debugging measure designed to detect cases where we start
a snapshot, create type variables, register obligations involving those
type variables in the fulfillment cx, and then have to unroll the
snapshot, leaving "dangling type variables" behind.  HOWEVER, in some
cases the flag is wrong. In particular, we sometimes create a
"mini-fulfilment-cx" in which we enroll obligations. As long as this
fulfillment cx is fully drained before we return, this is not a problem,
as there won't be any escaping obligations in the main cx. So we add a
fn to save/restore the flag.

Fixes rust-lang#36053.

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) ❄️ P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants