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

Nightly ICE: 'no errors encountered even though delay_span_bug issued' and 'unresolved inference variable in outlives: ?8t' #114783

Closed
burtonageo opened this issue Aug 13, 2023 · 1 comment · Fixed by #114787
Assignees
Labels
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.

Comments

@burtonageo
Copy link
Contributor

burtonageo commented Aug 13, 2023

Code

use smallvec::{SmallVec};
use std::marker::PhantomData;

struct Element {}

trait AsBufferView {
    type Device: Device;
    type View;
    fn as_raw_buffer(&self) -> &<Self::Device as Device>::Buffer;
    fn as_buffer_view(&self) -> &Self::View;
}

trait InputLayoutArray {
    const LAYOUTS: &'static [&'static [Element]];
}

impl<V: InputLayout> InputLayoutArray for V {
    const LAYOUTS: &'static [&'static [Element]] = &[<V as InputLayout>::LAYOUT];
}

trait InputLayout {
    const LAYOUT: &'static [Element];
}

macro_rules! impl_input_layout_array {
    () => {};
    (($vtx_id:ident $(,)?)) => {};
    (($vtx_id:ident, $($rest:ident),+ $(,)?)) => {
        impl_input_layout_array! { ($($rest),+ ) }
        impl<$vtx_id, $($rest),+> InputLayoutArray for ($vtx_id, $($rest),+)
        where
            $vtx_id: InputLayout,
            $($rest: InputLayout),+
        {
            const LAYOUTS: &'static [&'static [Element]] = &[];
        }
    };
}

impl_input_layout_array! { (V16, V15, V14, V13, V12, V11, V10, V9, V8, V7, V6, V5, V4, V3, V2, V1, V0,) }

impl<V: InputLayout> InputLayout for (V,) {
    const LAYOUT: &'static [Element] = <V as InputLayout>::LAYOUT;
}

trait Device {
    type Buffer;
}

trait VertexBufferInputs {
    type VertexInput: InputLayoutArray;
    type Device: Device;
    fn buffers(&self) -> SmallVec<[&<Self::Device as Device>::Buffer; MAX_VERTEX_BUFFERS]>;
}

const MAX_VERTEX_BUFFERS: usize = 8;

struct VertexBufferView<V, Device> {
    _boo: PhantomData<(V, Device)>,
}

macro_rules! impl_vertex_buffer_inputs {
    (($vtx_id:ident : $vbuf_id:ident $(,)?)) => {
        impl<D: Device, $vtx_id, $vbuf_id> VertexBufferInputs for (&'_ $vbuf_id,)
        where
            $vtx_id: InputLayout,
            $vbuf_id: AsBufferView<Device = D, View = VertexBufferView<$vtx_id, D>>,
        {
            type VertexInput = ($vtx_id,);
            type Device = D;

            fn buffers(&self) -> SmallVec<[&<Self::Device as Device>::Buffer; MAX_VERTEX_BUFFERS]> {
                loop {}
            }
        }
    };
    (($vtx_id:ident : $vbuf_id:ident , $($vtx_id_rest:ident : $vbuf_id_rest:ident ),+ $(,)?)) => {
        impl_vertex_buffer_inputs!{ ( $( $vtx_id_rest : $vbuf_id_rest ),+ ) }

        impl<D, $vtx_id, $($vtx_id_rest),+, $vbuf_id, $($vbuf_id_rest),+,> VertexBufferInputs for (
            &'_ $vbuf_id, $( &'_ $vbuf_id_rest ),+ ,
        )
        where
            D: Device,
            $vtx_id: InputLayout,
            $( $vtx_id_rest: InputLayout ),+ ,
            $vbuf_id: AsBufferView<Device = D, View = VertexBufferView<$vtx_id, D>>,
            $( $vbuf_id_rest: AsBufferView<Device = D, View = VertexBufferView<$vtx_id_rest, D>> ),+
        {
            type VertexInput = ($vtx_id, $($vtx_id_rest),+ ,);
            type Device = D;

            fn buffers(&self) -> SmallVec<[&<Self::Device as Device>::Buffer; MAX_VERTEX_BUFFERS]> {
                loop {}
            }
        }
    };
}

impl_vertex_buffer_inputs! {
    (V7: VBuf7, V6: VBuf6, V5: VBuf5, V4: VBuf4, V3: VBuf3, V2: VBuf2, V1: VBuf1, V0: VBuf0,)
}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=45cbad8e49524de87a2501a6c9704eee

Meta

This code compiles on the stable and beta channels, but crashes with an ICE on the nightly channel.

rustc --version --verbose:

Build using the Nightly version: 1.73.0-nightly
(2023-08-12 28eb857b9504bd05bbed)

Error output

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: unresolved inference variable in outlives: ?8t
   --> src/lib.rs:72:13
    |
72  |               fn buffers(&self) -> SmallVec<[&<Self::Device as Device>::Buffer; MAX_VERTEX_BUFFERS]> {
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
100 | / impl_vertex_buffer_inputs! {
101 | |     (V7: VBuf7, V6: VBuf6, V5: VBuf5, V4: VBuf4, V3: VBuf3, V2: VBuf2, V1: VBuf1, V0: VBuf0,)
102 | | }
    | |_- in this macro invocation
    |

(Backtrace omitted)

   --> src/lib.rs:72:13
    |
72  |               fn buffers(&self) -> SmallVec<[&<Self::Device as Device>::Buffer; MAX_VERTEX_BUFFERS]> {
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
100 | / impl_vertex_buffer_inputs! {
101 | |     (V7: VBuf7, V6: VBuf6, V5: VBuf5, V4: VBuf4, V3: VBuf3, V2: VBuf2, V1: VBuf1, V0: VBuf0,)
102 | | }
    | |_- in this macro invocation
    = note: this error: internal compiler error originates in the macro `impl_vertex_buffer_inputs` (in Nightly builds, run with -Z macro-backtrace for more info)

.. And so on for ?10t, ?11t, etc.

Backtrace

note: delayed at compiler/rustc_infer/src/infer/outlives/obligations.rs:254:35
         0: <rustc_errors::HandlerInner>::emit_diagnostic
         1: <rustc_session::session::Session>::delay_span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
         2: <rustc_infer::infer::outlives::obligations::TypeOutlives<&rustc_infer::infer::InferCtxt>>::components_must_outlive
         3: <rustc_infer::infer::InferCtxt>::resolve_regions
         4: rustc_hir_analysis::check::compare_impl_item::compare_method_predicate_entailment
         5: rustc_hir_analysis::check::check::check_mod_item_types
         6: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_mod_item_types::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 0]>>
         7: <rustc_query_impl::query_impl::check_mod_item_types::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
         8: 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; 0]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
         9: rustc_query_impl::query_impl::check_mod_item_types::get_query_non_incr::__rust_end_short_backtrace
        10: <rustc_middle::hir::map::Map>::for_each_module::<rustc_hir_analysis::check_crate::{closure#6}::{closure#0}>
        11: rustc_hir_analysis::check_crate
        12: rustc_interface::passes::analysis
        13: 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]>>
        14: <rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, ())>>::call_once
        15: 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, false>
        16: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        17: <rustc_middle::ty::context::GlobalCtxt>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#6}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        18: rustc_span::set_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
        19: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        20: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, 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}
        21: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/28eb857b9504bd05bbed0cf8af8e825fbdbb1fa1/library/alloc/src/boxed.rs:2007:9
        22: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/28eb857b9504bd05bbed0cf8af8e825fbdbb1fa1/library/alloc/src/boxed.rs:2007:9
        23: std::sys::unix::thread::Thread::new::thread_start
                   at /rustc/28eb857b9504bd05bbed0cf8af8e825fbdbb1fa1/library/std/src/sys/unix/thread.rs:108:17
        24: start_thread
        25: clone

@burtonageo burtonageo 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 Aug 13, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 13, 2023
@burtonageo burtonageo changed the title Nightly ICE: no errors encountered even though delay_span_bug issued and unresolved inference variable in outlives: ?8t Nightly ICE: no errors encountered even though \delay_span_bug\ issued and unresolved inference variable in outlives: ?8t Aug 13, 2023
@burtonageo burtonageo changed the title Nightly ICE: no errors encountered even though \delay_span_bug\ issued and unresolved inference variable in outlives: ?8t Nightly ICE: 'no errors encountered even though delay_span_bug issued' and 'unresolved inference variable in outlives: ?8t' Aug 13, 2023
@compiler-errors compiler-errors added the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Aug 13, 2023
@Skepfyr
Copy link
Contributor

Skepfyr commented Aug 13, 2023

Minimized (from the chumsky crate) to:

pub trait Foo {
    type Error: Error;
    fn foo(&self, stream: &<Self::Error as Error>::Span);
}

pub struct Wrapper<Inner>(Inner);

impl<E: Error, Inner> Foo for Wrapper<Inner>
where
    Inner: Foo<Error = E>,
{
    type Error = E;

    fn foo(&self, stream: &<Self::Error as Error>::Span) {
        todo!()
    }
}

pub trait Error {
    type Span;
}

or (from the above) to:

trait AsBufferView {
    type Device;
}

trait Error {
    type Span;
}

trait Foo {
    type Error: Error;
    fn foo(&self) -> &<Self::Error as Error>::Span;
}

impl<D: Error, VBuf0> Foo for VBuf0
where
    VBuf0: AsBufferView<Device = D>,
{
    type Error = D;
    fn foo(&self) -> &<Self::Error as Error>::Span {
        todo!()
    }
}

Bisected with cargo-bisect-rustc v0.6.6 to f1b8548, which is #109356 and that PR does look like it's in the right area to have caused this.

@compiler-errors compiler-errors removed the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Aug 13, 2023
@compiler-errors compiler-errors self-assigned this Aug 13, 2023
@compiler-errors compiler-errors added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ and removed 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. labels Aug 13, 2023
@bors bors closed this as completed in 3071e0a Aug 14, 2023
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. 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
4 participants