Skip to content

Compiler panic with generic-typed nested closures #59494

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
bturner-bw opened this issue Mar 28, 2019 · 7 comments · Fixed by #78295
Closed

Compiler panic with generic-typed nested closures #59494

bturner-bw opened this issue Mar 28, 2019 · 7 comments · Fixed by #78295
Assignees
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium 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.

Comments

@bturner-bw
Copy link

bturner-bw commented Mar 28, 2019

Discovered a compiler panic, thought it might relate to #58840, but was told to post a new issue.

In minimizing, it seems the generic types are required to trigger the panic, I was unable to reproduce when inlining t7p or t8n.


This code panics on 1.33 - 1.35, but does not panic on 1.32 (playpen):

fn t7p<A,B,C>( f:impl Fn(B) -> C, g:impl Fn(A) -> B ) -> impl Fn(A) -> C
{
  move |a:A| -> C { f(g(a)) }
}

fn t8n<A,B,C>( f:impl Fn(A) -> B, g:impl Fn(A) -> C ) -> impl Fn(A) -> (B,C)
  where
    A: Copy
{
  move |a:A| -> (B,C) {
    let b = a;
    let fa = f(a);
    let ga = g(b);
    (fa, ga)
  }
}

fn main() {

  let f = |(_,_)| {  };
  let g = |(a,_)| { a };
  let t7 = |env| { |a| { |b| {  t7p(f, g)(((env,a),b))  }}};
  let t8 = t8n(t7, t7p(f, g));
}

On 1.32:

error[E0277]: expected a `std::ops::Fn<(_,)>` closure, found `impl std::ops::Fn<(((_, _), _),)>`
  --> src/main.rs:32:12
   |
32 |   let t8 = pair_panic(t7, o_panic(f, g));
   |            ^^^^^^^^^^ expected an `Fn<(_,)>` closure, found `impl std::ops::Fn<(((_, _), _),)>`
   |
   = help: the trait `std::ops::Fn<(_,)>` is not implemented for `impl std::ops::Fn<(((_, _), _),)>`
note: required by `pair_panic`
  --> src/main.rs:9:1
   |
9  | / fn pair_panic<A,B,C>( f:impl Fn(A) -> B, g:impl Fn(A) -> C ) -> impl Fn(A) -> (B,C)
10 | |   where
11 | |     A: Copy
12 | | {
...  |
18 | |   }
19 | | }
   | |_^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: Could not compile `panic`.

To learn more, run the command again with --verbose.

On 1.35 nightly:

thread 'rustc' panicked at 'assertion failed: result', src/librustc/traits/select.rs:2779:13
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
   1: std::sys_common::backtrace::_print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::begin_panic
   7: rustc::infer::InferCtxt::in_snapshot
   8: rustc::traits::select::SelectionContext::confirm_candidate
   9: rustc::traits::select::SelectionContext::select
  10: rustc_data_structures::obligation_forest::ObligationForest<O>::process_obligations
  11: <rustc::traits::fulfill::FulfillmentContext as rustc::traits::engine::TraitEngine>::select_where_possible
  12: rustc_typeck::check::FnCtxt::select_obligations_where_possible
  13: rustc_typeck::check::FnCtxt::check_argument_types
  14: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::confirm_builtin_call
  15: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::check_call
  16: rustc_typeck::check::FnCtxt::check_expr_kind
  17: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs
  18: rustc_typeck::check::FnCtxt::check_decl_initializer
  19: rustc_typeck::check::FnCtxt::check_decl_local
  20: rustc_typeck::check::FnCtxt::check_stmt
  21: rustc_typeck::check::FnCtxt::check_block_with_expected
  22: rustc_typeck::check::FnCtxt::check_expr_kind
  23: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs
  24: rustc_typeck::check::FnCtxt::check_return_expr
  25: rustc_typeck::check::check_fn
  26: rustc::ty::context::GlobalCtxt::enter_local
  27: rustc_typeck::check::typeck_tables_of
  28: rustc::ty::query::__query_compute::typeck_tables_of
  29: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::typeck_tables_of>::compute
  30: rustc::dep_graph::graph::DepGraph::with_task_impl
  31: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  32: rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners
  33: rustc_typeck::check::typeck_item_bodies
  34: rustc::ty::query::__query_compute::typeck_item_bodies
  35: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::typeck_item_bodies>::compute
  36: rustc::dep_graph::graph::DepGraph::with_task_impl
  37: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  38: rustc::util::common::time
  39: rustc_typeck::check_crate
  40: rustc_interface::passes::analysis
  41: rustc::ty::query::__query_compute::analysis
  42: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::analysis>::compute
  43: rustc::dep_graph::graph::DepGraph::with_task_impl
  44: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  45: rustc::ty::context::tls::enter_global
  46: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  47: rustc_interface::passes::create_global_ctxt::{{closure}}
  48: rustc_interface::passes::BoxedGlobalCtxt::enter
  49: rustc_interface::interface::run_compiler_in_existing_thread_pool
  50: std::thread::local::LocalKey<T>::with
  51: scoped_tls::ScopedKey<T>::set
  52: syntax::with_globals
query stack during panic:
#0 [typeck_tables_of] processing `main`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack

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: rustc 1.35.0-nightly (fbd34efb3 2019-03-26) running on x86_64-apple-darwin
note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin
note: some of the compiler flags provided by cargo are hidden
error: Could not compile `rust`.
To learn more, run the command again with --verbose.

--Bryan

@jonas-schievink jonas-schievink added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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. C-bug Category: This is a bug. labels Mar 28, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Apr 4, 2019

triage: P-high. Removing nominated tag since there's little to discuss beyond its P-highness. (The fact its unassigned will be discussed regardless of nomination state.)

@pnkfelix pnkfelix added P-high High priority and removed I-nominated labels Apr 4, 2019
@Deewiant
Copy link
Contributor

Bisection points to 1827d52 i.e. #55986 as the culprit. The backtrace in that commit looks very similar to the one reported here, and the parent commit (6de9c13) gives the same compiler error.

@pnkfelix
Copy link
Member

I spent some time looking at this a few weeks ago but did not manage to find anything conclusive.

At this point I'm going to be taking a break for a few months, so I am unassigning myself from this issue.

@pnkfelix pnkfelix removed their assignment Jul 12, 2019
@pnkfelix
Copy link
Member

triage: assigning self.

@pnkfelix pnkfelix self-assigned this Sep 19, 2019
@pnkfelix
Copy link
Member

triage: downgrading to P-medium; this does not warrant revisiting every week.

@pnkfelix pnkfelix added P-medium Medium priority and removed P-high High priority labels Oct 10, 2019
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Oct 15, 2019
@orium
Copy link
Member

orium commented Sep 27, 2020

I was able to minify it a bit further:

fn t7p<A,B>(g: impl Fn(A) -> B) -> impl Fn(A) -> B {
    g
}

fn unify<A,B,C>(f: impl Fn(A) -> B, g: impl Fn(A) -> C) {}

fn unify2<A,B,C>(f:impl Fn(B) -> C, g: impl Fn(A) -> B) {}

fn main() {
    let f = |(_, _)| {  };
    let g = |(a, _)| { a };

    unify2(f, g);

    let t = |env| { |a| { |b| { t7p(g)(((env, a), b)) }}};

    unify(t, t7p(g));
}

@JohnTitor
Copy link
Member

Triage: It's no longer ICE with the latest nightly.

@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 23, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Oct 26, 2020
@bors bors closed this as completed in 75bbd80 Oct 26, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium 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.

7 participants