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: Region parameter out of range when substituting in region #47309

Closed
ipetkov opened this issue Jan 10, 2018 · 14 comments · Fixed by exul/matrix-rocketchat#61
Closed

ICE: Region parameter out of range when substituting in region #47309

ipetkov opened this issue Jan 10, 2018 · 14 comments · Fixed by exul/matrix-rocketchat#61
Assignees
Labels
A-GATs Area: Generic associated types (GATs) C-bug Category: This is a bug. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone

Comments

@ipetkov
Copy link
Contributor

ipetkov commented Jan 10, 2018

ICE: librustc/ty/subst.rs:424: Region parameter out of range when substituting in region 'a (root type=None) (index=2)

Started getting an ICE on nightly linux builds in travis for my crate while building various integration tests (I've seen builds fail on different integration tests each time). The ICE has reliably occurred on travis during each restart, however, I've been unable to reproduce it locally via travis docker image (so I can't even begin to attempt to minify my source to something that triggers the error). As far as I can tell, this started with rustc 1.24.0-nightly (8e7a609 2018-01-04).

Sample build log can be found here.

Happy to provide more logs build info as needed!

Meta

rustc 1.25.0-nightly (61452e5 2018-01-09)

Backtrace:

thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:455: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:68
             at libstd/sys_common/backtrace.rs:57
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:381
   3: std::panicking::default_hook
             at libstd/panicking.rs:391
   4: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:577
   5: std::panicking::begin_panic
   6: rustc_errors::Handler::span_bug
   7: <std::thread::local::LocalKey<T>>::with
   8: rustc::ty::context::tls::with_opt
   9: rustc::session::opt_span_bug_fmt
  10: rustc::session::span_bug_fmt
  11: <rustc::ty::subst::SubstFolder<'a, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_region
  12: rustc::ty::fold::TypeFoldable::fold_with
  13: rustc::ty::fold::TypeFoldable::fold_with
  14: rustc::traits::substitute_normalize_and_test_predicates
  15: rustc::ty::maps::<impl rustc::ty::maps::queries::substitute_normalize_and_test_predicates<'tcx>>::compute_result
  16: rustc::dep_graph::graph::DepGraph::with_task_impl
  17: rustc_errors::Handler::track_diagnostics
  18: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  19: rustc::ty::maps::<impl rustc::ty::maps::queries::substitute_normalize_and_test_predicates<'tcx>>::force
  20: rustc::ty::maps::<impl rustc::ty::maps::queries::substitute_normalize_and_test_predicates<'tcx>>::try_get
  21: rustc::ty::maps::TyCtxtAt::substitute_normalize_and_test_predicates
  22: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::substitute_normalize_and_test_predicates
  23: <rustc_mir::monomorphize::collector::RootCollector<'b, 'a, 'v> as rustc::hir::itemlikevisit::ItemLikeVisitor<'v>>::visit_item
  24: rustc::hir::Crate::visit_all_item_likes
  25: rustc_mir::monomorphize::collector::collect_crate_mono_items
  26: rustc::util::common::time
  27: rustc_trans::base::collect_and_partition_translation_items
  28: rustc::dep_graph::graph::DepGraph::with_task_impl
  29: rustc_errors::Handler::track_diagnostics
  30: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  31: rustc::ty::maps::<impl rustc::ty::maps::queries::collect_and_partition_translation_items<'tcx>>::force
  32: rustc::ty::maps::<impl rustc::ty::maps::queries::collect_and_partition_translation_items<'tcx>>::try_get
  33: rustc::ty::maps::TyCtxtAt::collect_and_partition_translation_items
  34: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::collect_and_partition_translation_items
  35: rustc_trans::base::trans_crate
  36: <rustc_trans::LlvmTransCrate as rustc_trans_utils::trans_crate::TransCrate>::trans_crate
  37: rustc::util::common::time
  38: rustc_driver::driver::phase_4_translate_to_llvm
  39: rustc_driver::driver::compile_input::{{closure}}
  40: <std::thread::local::LocalKey<T>>::with
  41: <std::thread::local::LocalKey<T>>::with
  42: rustc::ty::context::TyCtxt::create_and_enter
  43: rustc_driver::driver::compile_input
  44: rustc_driver::run_compiler
@ipetkov
Copy link
Contributor Author

ipetkov commented Jan 14, 2018

Managed to extract rustc debug logs when the ICE is triggered. Specifically, the ICE occurs when an integration-style test is being built against the main crate, and not while the crate/lib itself is being built and tested.

Debug logs can be found here.
Full travis log context can be found here

@Mrmaxmeier
Copy link
Contributor

Mrmaxmeier commented Jan 20, 2018

I've encountered this issue while trying to use cargo-kcov. It looks like it's easily triggered by building openssl v0.10.2 with RUSTFLAGS='-C link-dead-code'.

Build log
⋊> /t/r/openssl on master  env RUSTFLAGS='-C link-dead-code' cargo build
   Compiling openssl v0.10.2 (file:///tmp/rust-openssl/openssl)
error: internal compiler error: librustc/ty/subst.rs:424: Region parameter out of range when substituting in region 'a (root type=Some(unsafe fn(*mut <Self as foreign_types::ForeignTypeRef>::CType) -> &'a mut Self {<Self as foreign_types::ForeignTypeRef>::from_ptr_mut::<'a>})) (index=1)

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.25.0-nightly (5965b7901 2018-01-19) running on x86_64-unknown-linux-gnu

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

thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:456: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:68
             at libstd/sys_common/backtrace.rs:57
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:380
   3: std::panicking::default_hook
             at libstd/panicking.rs:390
   4: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:576
   5: std::panicking::begin_panic
   6: rustc_errors::Handler::span_bug
   7: <std::thread::local::LocalKey<T>>::with
   8: rustc::ty::context::tls::with_opt
   9: rustc::session::opt_span_bug_fmt
  10: rustc::session::span_bug_fmt
  11: <rustc::ty::subst::SubstFolder<'a, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_region
  12: rustc::ty::fold::TypeFoldable::fold_with
  13: <rustc_data_structures::accumulate_vec::AccumulateVec<A> as core::iter::traits::FromIterator<<A as rustc_data_structures::array_vec::Array>::Element>>::from_iter
  14: rustc::ty::fold::TypeFoldable::fold_with
  15: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable<'tcx> for &'tcx rustc::ty::TyS<'tcx>>::super_fold_with
  16: <rustc::ty::subst::SubstFolder<'a, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  17: rustc::traits::trans::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'tcx>>::trans_apply_param_substs
  18: rustc::ty::instance::Instance::ty
  19: rustc_trans::trans_item::predefine_fn
  20: rustc_trans::trans_item::MonoItemExt::predefine
  21: rustc_trans::base::compile_codegen_unit
  22: rustc::ty::maps::<impl rustc::ty::maps::queries::compile_codegen_unit<'tcx>>::compute_result
  23: rustc::dep_graph::graph::DepGraph::with_task_impl
  24: rustc_errors::Handler::track_diagnostics
  25: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  26: rustc::ty::maps::<impl rustc::ty::maps::queries::compile_codegen_unit<'tcx>>::force
  27: rustc::ty::maps::<impl rustc::ty::maps::queries::compile_codegen_unit<'tcx>>::try_get
  28: rustc::ty::maps::TyCtxtAt::compile_codegen_unit
  29: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::compile_codegen_unit
  30: rustc_trans::base::trans_crate
  31: <rustc_trans::LlvmTransCrate as rustc_trans_utils::trans_crate::TransCrate>::trans_crate
  32: rustc::util::common::time
  33: rustc_driver::driver::phase_4_translate_to_llvm
  34: rustc_driver::driver::compile_input::{{closure}}
  35: <std::thread::local::LocalKey<T>>::with
  36: <std::thread::local::LocalKey<T>>::with
  37: rustc::ty::context::TyCtxt::create_and_enter
  38: rustc_driver::driver::compile_input
  39: rustc_driver::run_compiler

error: Could not compile `openssl`.

@ipetkov
Copy link
Contributor Author

ipetkov commented Jan 20, 2018

Thanks for the insight @Mrmaxmeier! I've confirmed that removing the -C link-dead-code flag avoids the ICE, and I can consistently reproduce the issue locally with the flag enabled.

@ipetkov
Copy link
Contributor Author

ipetkov commented Jan 22, 2018

After several false starts, I was able to boil down the ICE to the following case:

pub trait EnvFuture {
    type Item;

    fn boxed_result<'a>(self) where Self: Sized, Self::Item: 'a, {
    }
}

struct Foo;

impl<'a> EnvFuture for &'a Foo {
    type Item = ();
}

This will ICE on nightly when run with the -C link-dead-code flag passed to rustc. Same invocation on stable exits with no error, so this is definitely a regression.

ipetkov added a commit to ipetkov/conch-runtime that referenced this issue Jan 22, 2018
* Currently nightly will ICE when run with `-C link-dead-code`:
see rust-lang/rust#47309 for more info
* Workaround is to run kcov on stable instead until a fix is in place
@estebank estebank added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jan 24, 2018
@ghost
Copy link

ghost commented Jan 24, 2018

another repro that might be related:
on rust playground nightly:
note: rustc 1.25.0-nightly (4e3901d 2018-01-23) running on x86_64-unknown-linux-gnu

#![feature(generic_associated_types)]

pub trait Foo<'a> {}
pub trait Bar {
  type Foo<'a> : Foo<'a>;    
  fn foo<'a>(&'a self) -> Self::Foo;
}

fn main() {}

EDIT: sorry unrelated theres's another ticket about it #46793

@ipetkov
Copy link
Contributor Author

ipetkov commented Feb 18, 2018

This bug has now regressed into stable 1.24: https://travis-ci.org/ipetkov/conch-runtime/jobs/342033538

ipetkov added a commit to ipetkov/conch-runtime that referenced this issue Feb 18, 2018
* It appears that the ICE reported in rust-lang/rust#47309 as regressed
into the latest stable version. This change moves coverage collection to
use stable 1.20.0 instead
* Also run code coverage in a dedicated VM instead of a Docker container
as a workaround for travis-ci/travis-ci#9061
ipetkov added a commit to ipetkov/conch-runtime that referenced this issue Feb 18, 2018
* It appears that the ICE reported in rust-lang/rust#47309 as regressed
into the latest stable version. This change moves coverage collection to
use stable 1.20.0 instead
* Also run code coverage in a dedicated VM instead of a Docker container
as a workaround for travis-ci/travis-ci#9061
zrzka added a commit to zrzka/rust-circleci that referenced this issue Feb 19, 2018
@alexcrichton alexcrichton added I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. labels Feb 19, 2018
@nikomatsakis
Copy link
Contributor

triage: P-high

This slipped under the radar. @rust-lang/release -- do you think somebody could bisect this example to get a sense for when the error was introduced? Note that it requires -Clink-dead-code

@rust-highfive rust-highfive added P-high High priority and removed I-nominated labels Feb 22, 2018
@pnkfelix
Copy link
Member

pnkfelix commented Feb 22, 2018

I bisected across rust-nightly channel. Here is result:

tl;dr: bug appears injected somewhere between commits 0a3761e and 8e7a609

% rustc +nightly-2018-01-03 --crate-type lib issue-47309.rs  -C link-dead-code
% rustc +nightly-2018-01-04 --crate-type lib issue-47309.rs  -C link-dead-code
% rustc +nightly-2018-01-05 --crate-type lib issue-47309.rs  -C link-dead-code
error: internal compiler error: /checkout/src/librustc/ty/subst.rs:424: Region parameter out of range when substituting in region 'a (root type=None) (index=1)

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.24.0-nightly (8e7a609e6 2018-01-04) running on x86_64-unknown-linux-gnu

thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc_errors/lib.rs:451:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.

% rustc +nightly-2018-01-04 --version
rustc 1.24.0-nightly (0a3761e63 2018-01-03)
% rustc +nightly-2018-01-05 --version
rustc 1.24.0-nightly (8e7a609e6 2018-01-04)
%

@pnkfelix
Copy link
Member

pnkfelix commented Feb 22, 2018

i guess at least 8e7a609 (#46916) appears relevant ... (and it was backported to beta even...)

@pietroalbini
Copy link
Member

That PR fixed another regression (#46467), so I don't think we can just revert it...

@nikomatsakis
Copy link
Contributor

@pnkfelix yes I remember that change

@alexcrichton
Copy link
Member

I've confirmed @pnkfelix's suspicion for sure in that this ICE is caused by #46916

@pnkfelix
Copy link
Member

pnkfelix commented Mar 1, 2018

triage: assigning to @michaelwoerister to figure out more.

@michaelwoerister
Copy link
Member

#48818 implements a tentative fix for this. The problem is that the monomorphization collector does not account for method lifetime parameters in create_mono_items_for_default_impls().

bors added a commit that referenced this issue Mar 16, 2018
Properly handle collecting default impls of methods with lifetime parameters.

r? @eddyb

Fixes #47309.
@jkordish jkordish added the C-bug Category: This is a bug. label Apr 25, 2018
Mrmaxmeier pushed a commit to Mrmaxmeier/tectonic that referenced this issue Sep 17, 2018
@Centril Centril added the F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs label Aug 5, 2019
@fmease fmease added the A-GATs Area: Generic associated types (GATs) label Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-GATs Area: Generic associated types (GATs) C-bug Category: This is a bug. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.