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: broken MIR: NoSolution on HRTB over GAT in trait object #130524

Open
arvidfm opened this issue Sep 18, 2024 · 3 comments
Open

ICE: broken MIR: NoSolution on HRTB over GAT in trait object #130524

arvidfm opened this issue Sep 18, 2024 · 3 comments
Labels
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) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@arvidfm
Copy link

arvidfm commented Sep 18, 2024

Code

MWE below, also tested on nightly (via the playground). Interestingly the error goes away if I manually inline the Node::new calls. Minimised from a filter graph that uses trait objects for type erasure.

pub trait Transform {
    type Output<'a>;
}

pub trait Propagate<Input> {}

type Child<T> = Box<dyn for<'a> Propagate<<T as Transform>::Output<'a>>>;

pub struct Node<T>
where
    T: Transform,
{
    transform: T,
    children: Vec<Child<T>>,
}

impl<T> Node<T>
where
    T: Transform,
{
    pub fn new(transform: T, children: Vec<Child<T>>) -> Self {
        Node {
            transform,
            children,
        }
    }
}

impl<Input, T> Propagate<Input> for Node<T> where T: Transform {}

pub fn main() {
    struct Noop;

    impl Transform for Noop {
        type Output<'a> = ();
    }

    let node = Box::new(Node::new(Noop, vec![Box::new(Node::new(Noop, vec![]))]));
}

Meta

rustc --version --verbose:

rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7

Error output

error: internal compiler error: broken MIR in DefId(0:31 ~ playground[6f8d]::test::run#1) ([move _11]): std::boxed::Box<dyn [Binder { value: Trait(Propagate<()>), bound_vars: [Region(BrNamed(DefId(0:10 ~ playground[6f8d]::Child::'a), 'a))] }] + '?14, std::alloc::Global> is not a subtype of std::boxed::Box<dyn [Binder { value: Trait(Propagate<<test::Noop as Transform>::Output<'a>>), bound_vars: [Region(BrNamed(DefId(0:10 ~ playground[6f8d]::Child::'a), 'a))] }] + '?7, std::alloc::Global>: NoSolution
  --> src/lib.rs:43:45
   |
43 |         let node = Box::new(Node::new(Noop, vec![Box::new(Node::new(Noop, vec![]))]));
   |                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:2570:17 - disabled backtrace
  --> src/lib.rs:43:45
   |
43 |         let node = Box::new(Node::new(Noop, vec![Box::new(Node::new(Noop, vec![]))]));
   |                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error: internal compiler error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)

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.81.0 (eeb90cda1 2024-09-04) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
end of query stack
Backtrace

   Compiling my_test v0.1.0 (/tmp/my_test)
warning: unused variable: `node`
  --> src/main.rs:38:9
   |
38 |     let node = Box::new(Node::new(Noop, vec![Box::new(Node::new(Noop, vec![]))]));
   |         ^^^^ help: if this is intentional, prefix it with an underscore: `_node`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: fields `transform` and `children` are never read
  --> src/main.rs:13:5
   |
9  | pub struct Node<T>
   |            ---- fields in this struct
...
13 |     transform: T,
   |     ^^^^^^^^^
14 |     children: Vec<Child<T>>,
   |     ^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: broken MIR in DefId(0:21 ~ my_test[db07]::main) ([move _11]): std::boxed::Box<dyn [Binder { value: Trait(Propagate<()>), bound_vars: [Region(BrNamed(DefId(0:10 ~ my_test[db07]::Child::'a), 'a))] }] + '?14, std::alloc::Global> is not a subtype of std::boxed::Box<dyn [Binder { value: Trait(Propagate<<main::Noop as Transform>::Output<'a>>), bound_vars: [Region(BrNamed(DefId(0:10 ~ my_test[db07]::Child::'a), 'a))] }] + '?7, std::alloc::Global>: NoSolution
  --> src/main.rs:38:41
   |
38 |     let node = Box::new(Node::new(Noop, vec![Box::new(Node::new(Noop, vec![]))]));
   |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:2570:17
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         3: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, alloc::string::String>
         4: <rustc_borrowck::type_check::TypeChecker>::typeck_mir
         5: rustc_borrowck::type_check::type_check
         6: rustc_borrowck::nll::compute_regions
         7: rustc_borrowck::do_mir_borrowck
         8: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
         9: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
        10: rustc_query_impl::query_impl::mir_borrowck::get_query_incr::__rust_end_short_backtrace
        11: rustc_interface::passes::analysis
        12: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        13: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
        14: rustc_query_impl::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
        15: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        16: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        17: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        18: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2070:9
        19: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2070:9
        20: std::sys::pal::unix::thread::Thread::new::thread_start
                   at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/pal/unix/thread.rs:108:17
        21: <unknown>
        22: <unknown>
  --> src/main.rs:38:41
   |
38 |     let node = Box::new(Node::new(Noop, vec![Box::new(Node::new(Noop, vec![]))]));
   |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error: internal compiler error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)

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.81.0 (eeb90cda1 2024-09-04) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:
end of query stack
warning: `my_test` (bin "my_test") generated 2 warnings
error: could not compile `my_test` (bin "my_test"); 2 warnings emitted

@arvidfm arvidfm 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 Sep 18, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 18, 2024
@cyrgani
Copy link
Contributor

cyrgani commented Sep 18, 2024

More reduction:

trait Transform {
    type Output<'a>;
}

trait Propagate<Input> {}

fn new_node<T: Transform>(_c: Vec<Box<dyn for<'a> Propagate<<T as Transform>::Output<'a>>>>) -> T {
    todo!()
}

impl<Input, T> Propagate<Input> for T {}
struct Noop;

impl Transform for Noop {
    type Output<'a> = ();
}

fn main() {
    let _node: Noop = new_node(vec![Box::new(Noop)]);
}

@matthiaskrgr
Copy link
Member

Regression in nightly-2021-07-17
commit[0] 2021-07-15: Auto merge of #83319 - tmiasko:packed-aligned, r=jackh726
commit[1] 2021-07-16: Auto merge of #86993 - jackh726:project-gat-binders, r=nikomatsakis
commit[2] 2021-07-16: Auto merge of #87177 - ehuss:update-cargo, r=ehuss
commit[3] 2021-07-16: Auto merge of #86662 - mockersf:fix-86620-link-unknown-location, r=jyn514
commit[4] 2021-07-16: Auto merge of #87182 - GuillaumeGomez:rollup-whwohua, r=GuillaumeGomez
commit[5] 2021-07-16: Auto merge of #87140 - camsteffen:pat-slice-refs, r=oli-obk
commit[6] 2021-07-16: Auto merge of #84623 - jackh726:gats-incomplete, r=nikomatsakis
commit[7] 2021-07-16: Auto merge of #87201 - GuillaumeGomez:rollup-4loi2q9, r=GuillaumeGomez
ERROR: no CI builds available between b1f8e27 and 74ef0c3 within last 167 days

I would guess either #86993 or #84623 ?

@matthiaskrgr matthiaskrgr added the F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs label Sep 20, 2024
@arvidfm
Copy link
Author

arvidfm commented Sep 20, 2024

I did come across #120811 and #110534 which may or may not be related? They both involve HRTBs, though no trait objects, and the regression date mentioned for the former one is later than when this regressed

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. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. 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

4 participants