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

GATs and min_type_alias_impl_trait cause ICE #87258

Closed
uzytkownik opened this issue Jul 18, 2021 · 14 comments · Fixed by #90305
Closed

GATs and min_type_alias_impl_trait cause ICE #87258

uzytkownik opened this issue Jul 18, 2021 · 14 comments · Fixed by #90305
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. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs GATs-triaged Issues using the `generic_associated_types` feature that have been triaged glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@uzytkownik
Copy link

Code

#![feature(min_type_alias_impl_trait)]
#![feature(generic_associated_types)]
use std::future::Future;

pub trait Trait1
{
    type Error: Clone;
    type Assoc2<'a>
    where
        Self: 'a;
}

pub trait Trait2: Trait1 {
    type FooFuture<'a, 'b>: Future<Output = Result<(), Self::Error>>;
    fn foo<'a: 'b, 'b>(assoc2: &'b mut Self::Assoc2<'a>) -> Self::FooFuture<'a, 'b>
    where
        Self: 'a;
}

impl<'c, S : Trait1> Trait1 for &'c mut S {
    type Error = S::Error;

    type Assoc2<'a> where 'c: 'a = S::Assoc2<'a>;
}

impl<'c, S : Trait2> Trait2 for &'c mut S {
    type FooFuture<'a, 'b> = impl Future<Output = Result<(), Self::Error>>;
    fn foo<'a: 'b, 'b>(assoc2: &'b mut Self::Assoc2<'a>) -> Self::FooFuture<'a, 'b>
    where
        Self: 'a
    {
        async move {
            unimplemented!();
        }
    }
}

Meta

rustc --version --verbose:

rustc 1.55.0-nightly (c7331d65b 2021-07-17)
binary: rustc
commit-hash: c7331d65bdbab1187f5a9b8f5b918248678ebdb9
commit-date: 2021-07-17
host: x86_64-pc-windows-msvc
release: 1.55.0-nightly
LLVM version: 12.0.1

(Also https://play.rust-lang.org/)

Error output

thread 'rustc' panicked at 'assertion failed: self.is_free_or_static(r_a) && self.is_free_or_static(r_b)', compiler/rustc_infer/src/infer/free_regions.rs:77:9
Backtrace

thread 'rustc' panicked at 'assertion failed: self.is_free_or_static(r_a) && self.is_free_or_static(r_b)', compiler/rustc_infer/src/infer/free_regions.rs:77:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/c7331d65bdbab1187f5a9b8f5b918248678ebdb9/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/c7331d65bdbab1187f5a9b8f5b918248678ebdb9/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/c7331d65bdbab1187f5a9b8f5b918248678ebdb9/library/core/src/panicking.rs:50:5
   3: <rustc_infer::infer::free_regions::FreeRegionMap as rustc_infer::infer::free_regions::FreeRegionRelations>::sub_free_regions
   4: <rustc_infer::infer::InferCtxt as rustc_trait_selection::opaque_types::InferCtxtExt>::constrain_opaque_types
   5: rustc_typeck::check::regionck::RegionCtxt::visit_fn_body
   6: rustc_hir::intravisit::walk_expr
   7: <rustc_typeck::check::regionck::RegionCtxt as rustc_hir::intravisit::Visitor>::visit_expr
   8: rustc_hir::intravisit::walk_expr
   9: <rustc_typeck::check::regionck::RegionCtxt as rustc_hir::intravisit::Visitor>::visit_expr
  10: <rustc_typeck::check::regionck::RegionCtxt as rustc_hir::intravisit::Visitor>::visit_expr
  11: rustc_typeck::check::regionck::RegionCtxt::visit_fn_body
  12: rustc_typeck::check::regionck::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::regionck_fn
  13: rustc_infer::infer::InferCtxtBuilder::enter
  14: rustc_typeck::check::typeck
  15: rustc_query_system::query::plumbing::get_query_impl
  16: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  17: rustc_typeck::collect::type_of::find_opaque_ty_constraints::ConstraintLocator::check
  18: <rustc_typeck::collect::type_of::find_opaque_ty_constraints::ConstraintLocator as rustc_hir::intravisit::Visitor>::visit_impl_item
  19: rustc_hir::intravisit::Visitor::visit_nested_impl_item
  20: rustc_hir::intravisit::walk_impl_item_ref
  21: rustc_hir::intravisit::walk_item
  22: rustc_typeck::collect::type_of::type_of
  23: rustc_query_system::query::plumbing::get_query_impl
  24: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::type_of
  25: rustc_typeck::check::check::check_item_type
  26: rustc_middle::hir::map::Map::visit_item_likes_in_module
  27: rustc_typeck::check::check::check_mod_item_types
  28: rustc_query_system::query::plumbing::get_query_impl
  29: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_mod_item_types
  30: rustc_session::utils::<impl rustc_session::session::Session>::time
  31: rustc_typeck::check_crate
  32: rustc_interface::passes::analysis
  33: rustc_query_system::query::plumbing::get_query_impl
  34: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  35: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  36: rustc_span::with_source_map
  37: rustc_interface::interface::create_compiler_and_run
  38: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.55.0-nightly (c7331d65b 2021-07-17) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [typeck] type-checking `<impl at src/lib.rs:26:1: 36:2>::foo`
#1 [type_of] computing type of `<impl at src/lib.rs:26:1: 36:2>::FooFuture::{opaque#0}`
#2 [check_mod_item_types] checking item types in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `playground`

@uzytkownik uzytkownik added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 18, 2021
@jonas-schievink jonas-schievink added F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs F-min_type_alias_impl_trait labels Jul 18, 2021
@uzytkownik
Copy link
Author

Issue #87218 might be related (or this may be a duplicate of it).

@b-naber
Copy link
Contributor

b-naber commented Jul 19, 2021

This seems to be caused by #87200. Re-inserting fixup_opaque_types gets rid of the ICE.

@oli-obk What was the rationale for deleting that function?

@oli-obk oli-obk self-assigned this Jul 19, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Jul 19, 2021

What was the rationale for deleting that function?

It was replacing inference lifetimes with concrete ones (but wrong ones, as it was using lifetimes from a completely different item). This avoided certain ICEs and was even correct by accident for the example in the doc comment, but it was just papering over the ICEs causing other examples (where the impl trait is outside the current impl block) to fail.

I am looking into this new ICE now

@oli-obk
Copy link
Contributor

oli-obk commented Jul 19, 2021

I am getting

error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found keyword `move`
  --> /local/home/oscherer/rust4/src/test/ui/type-alias-impl-trait/issue-87258.rs:32:15
   |
LL |         async move {
   |               ^^^^ expected one of 8 possible tokens

locally before the ICE, so likely the ICE just hides actual errors. Should still fix that of course, but needs more looking into it

@uzytkownik
Copy link
Author

I am getting

error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found keyword `move`
  --> /local/home/oscherer/rust4/src/test/ui/type-alias-impl-trait/issue-87258.rs:32:15
   |
LL |         async move {
   |               ^^^^ expected one of 8 possible tokens

locally before the ICE, so likely the ICE just hides actual errors. Should still fix that of course, but needs more looking into it

I think you need to use 2018 or 2021 edition.

@oli-obk
Copy link
Contributor

oli-obk commented Jul 20, 2021

minimized and edition-free:

#![feature(min_type_alias_impl_trait)]
#![feature(generic_associated_types)]

trait Trait1 {}

struct Struct<'b>(&'b ());

impl<'d> Trait1 for Struct<'d> {}

pub trait Trait2 {
    type FooFuture<'a>: Trait1;
    fn foo<'a>() -> Self::FooFuture<'a>;
}

impl<'c, S: Trait2> Trait2 for &'c mut S {
    type FooFuture<'a> = impl Trait1;
    fn foo<'a>() -> Self::FooFuture<'a> {
        Struct(unimplemented!())
    }
}

fn main() {}

The problem is that typeck runs some of old borrowck/regionck and that just can't handle GAT and associated TAIT being used together. While fixup_opaque_types worked in this specific case, that function won't work if the TAIT were declared outside the impl block and only used, so the following would just hit a different ICE, even though it should be equivalent (except that the defining use scope is the surrounding module instead of just the impl block).

#![feature(min_type_alias_impl_trait)]
#![feature(generic_associated_types)]

trait Trait1 {}

struct Struct<'b>(&'b ());

impl<'d> Trait1 for Struct<'d> {}

pub trait Trait2 {
    type FooFuture<'a>: Trait1;
    fn foo<'a>() -> Self::FooFuture<'a>;
}

type Helper<'xenon, 'yttrium, KABOOM: Trait2> = impl Trait1;

impl<'c, S: Trait2> Trait2 for &'c mut S {
    type FooFuture<'a> = Helper<'c, 'a, S>;
    fn foo<'a>() -> Self::FooFuture<'a> {
        Struct(unimplemented!())
    }
}

fn main() {}

@oli-obk oli-obk added the NLL-fixed-by-NLL Bugs fixed, but only when NLL is enabled. label Jul 20, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Jul 20, 2021

So... turns out this works just fine with nll... I'd say we just wait for that, nll is only blocked on diagnostics, and those are actively being worked on: #86700

@Dirbaio
Copy link
Contributor

Dirbaio commented Aug 4, 2021

I've found this does work if adding a + 'a bound on the TAIT: type FooFuture<'a> = impl Trait1 + 'a;. Playground

It seems to me that + 'a should be required, so accepting code without it was actually a bug?

Also, how does this work with NLL? I add #![feature(nll)] and it still ICEs. (see the playground). Is there anything else needed for enabling NLL?

@lqd
Copy link
Member

lqd commented Aug 4, 2021

It seems the linked example on the playground does not ICE on the 2021-08-03 nightly.

@Dirbaio
Copy link
Contributor

Dirbaio commented Aug 4, 2021

@lqd that's with the + 'a fixed added. Without it it ICEs, both with and without NLL

@lqd
Copy link
Member

lqd commented Aug 4, 2021

Hum, indeed, the 2 minimized examples Oli mentioned in this comment do ICE with or without #![feature(nll)].

@oli-obk oli-obk removed the NLL-fixed-by-NLL Bugs fixed, but only when NLL is enabled. label Aug 5, 2021
@oli-obk oli-obk self-assigned this Aug 5, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Aug 5, 2021

oof, not sure what I tested here -.- I'll investigate again. But yea, we can just error out instead of ICEing.

@Alexendoo
Copy link
Member

This, #78561 and #88595 no longer ICE since #89229

@Alexendoo Alexendoo 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 20, 2021
@jackh726
Copy link
Member

GATs issue triage: not blocking. Fixed; needs test.

@jackh726 jackh726 added the GATs-triaged Issues using the `generic_associated_types` feature that have been triaged label Oct 23, 2021
vandenheuvel added a commit to vandenheuvel/rust that referenced this issue Oct 26, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 26, 2021
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 26, 2021
…askrgr

Rollup of 4 pull requests

Successful merges:

 - rust-lang#90296 (Remove fNN::lerp)
 - rust-lang#90302 (Remove unneeded into_iter)
 - rust-lang#90303 (Add regression test for issue 90164)
 - rust-lang#90305 (Add regression test for rust-lang#87258)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in fcc9a9a Oct 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs GATs-triaged Issues using the `generic_associated_types` feature that have been triaged glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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.

9 participants