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 normalize_erasing_regions with mir-opt-level=2 #77564

Closed
leonardo-m opened this issue Oct 5, 2020 · 4 comments · Fixed by #77568
Closed

[ICE] in normalize_erasing_regions with mir-opt-level=2 #77564

leonardo-m opened this issue Oct 5, 2020 · 4 comments · Fixed by #77568
Labels
A-mir-opt Area: MIR optimizations A-mir-opt-inlining Area: MIR inlining C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@leonardo-m
Copy link

use std::mem::MaybeUninit;
const N: usize = 2;

trait CollectArray<A>: Iterator<Item=A> {
    fn inner_array(&mut self) -> [A; N];
    fn collect_array(&mut self) -> [A; N] {
        let result = self.inner_array();
        assert!(self.next().is_none());
        result
    }
}

impl<A, I: ?Sized> CollectArray<A> for I where I: Iterator<Item=A>  {
    fn inner_array(&mut self) -> [A; N] {
        let mut result: [MaybeUninit<A>; N] = unsafe {
            MaybeUninit::uninit().assume_init()
        };
        for (dest, item) in result.iter_mut().zip(self) {
            *dest = MaybeUninit::new(item);
        }
        let temp_ptr: *const [MaybeUninit<A>; N] = &result;
        unsafe { std::ptr::read(temp_ptr as *const [A; N]) }
    }
}

fn main() {
     [[1, 2], [3, 4]]
     .iter()
     .map(|row| row.iter().collect_array())
     .collect_array();
}

Compiled with: rustc -Z mir-opt-level=2

Gives:

error: internal compiler error: compiler\rustc_traits\src\normalize_erasing_regions.rs:37:32: could not fully normalize `<&mut I as std::iter::IntoIterator>::IntoIter`

thread 'rustc' panicked at 'Box<Any>', compiler\rustc_errors\src\lib.rs:945:9
stack backtrace:
   0: std::panicking::begin_panic
   1: rustc_errors::HandlerInner::bug
   2: rustc_errors::Handler::bug
   3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
   4: rustc_middle::ty::context::tls::with_opt::{{closure}}
   5: rustc_middle::ty::context::tls::with_opt
   6: rustc_middle::util::bug::opt_span_bug_fmt
   7: rustc_middle::util::bug::bug_fmt
   8: rustc_infer::infer::InferCtxtBuilder::enter
   9: rustc_traits::normalize_erasing_regions::normalize_generic_arg_after_erasing_regions
  10: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  11: rustc_data_structures::stack::ensure_sufficient_stack
  12: rustc_query_system::query::plumbing::get_query_impl
  13: rustc_middle::ty::normalize_erasing_regions::<impl rustc_middle::ty::context::TyCtxt>::normalize_erasing_regions
  14: <rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt> as rustc_target::abi::LayoutOf>::layout_of
  15: rustc_mir::transform::inline::Inliner::run_pass
  16: <rustc_mir::transform::inline::Inline as rustc_mir::transform::MirPass>::run_pass
  17: rustc_mir::transform::run_passes
  18: rustc_mir::transform::run_optimization_passes
  19: rustc_mir::transform::optimized_mir
  20: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  21: rustc_data_structures::stack::ensure_sufficient_stack
  22: rustc_query_system::query::plumbing::get_query_impl
  23: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::instance_mir
  24: rustc_mir::monomorphize::collector::collect_neighbours
  25: rustc_mir::monomorphize::collector::collect_items_rec
  26: rustc_mir::monomorphize::collector::collect_items_rec
  27: rustc_mir::monomorphize::collector::collect_items_rec
  28: rustc_session::utils::<impl rustc_session::session::Session>::time
  29: rustc_mir::monomorphize::collector::collect_crate_mono_items
  30: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
  31: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::collect_and_partition_mono_items>::compute
  32: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  33: rustc_data_structures::stack::ensure_sufficient_stack
  34: rustc_query_system::query::plumbing::get_query_impl
  35: rustc_codegen_ssa::base::codegen_crate
  36: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  37: rustc_interface::passes::QueryContext::enter
  38: rustc_interface::queries::Queries::ongoing_codegen
  39: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  40: rustc_span::with_source_map
  41: rustc_interface::interface::create_compiler_and_run
  42: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.49.0-nightly (beb5ae474 2020-10-04) running on x86_64-pc-windows-gnu

note: compiler flags: -Z mir-opt-level=2

query stack during panic:
#0 [normalize_generic_arg_after_erasing_regions] normalizing `<&mut I as std::iter::IntoIterator>::IntoIter`
#1 [optimized_mir] optimizing MIR for `<I as CollectArray<A>>::inner_array`
#2 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to previous error
@leonardo-m leonardo-m added the C-bug Category: This is a bug. label Oct 5, 2020
@RalfJung
Copy link
Member

RalfJung commented Oct 5, 2020

This is a recent regression that also affects Miri. The regression was introduced somewhere in a835b48...4ccf5f7.

@RalfJung RalfJung added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Oct 5, 2020
@RalfJung
Copy link
Member

RalfJung commented Oct 5, 2020

Cc @rust-lang/wg-mir-opt

@RalfJung
Copy link
Member

RalfJung commented Oct 5, 2020

Cc @ecstatic-morse @lcnr I bisected this regression to #77430.

bors added a commit to rust-lang/miri that referenced this issue Oct 5, 2020
rustup; disable opt level >=2 tests due to ICE

Cc rust-lang/rust#77564 for the ICE
@lcnr
Copy link
Contributor

lcnr commented Oct 5, 2020

looking into this

@jonas-schievink jonas-schievink added A-mir-opt Area: MIR optimizations A-mir-opt-inlining Area: MIR inlining requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 5, 2020
@bors bors closed this as completed in 83c58d6 Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt Area: MIR optimizations A-mir-opt-inlining Area: MIR inlining C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. 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.

4 participants