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'd during const eval of generic with DST #80742

Closed
mental32 opened this issue Jan 6, 2021 · 0 comments · Fixed by #81185
Closed

ICE'd during const eval of generic with DST #80742

mental32 opened this issue Jan 6, 2021 · 0 comments · Fixed by #81185
Labels
C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` F-generic_const_exprs `#![feature(generic_const_exprs)]` 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

@mental32
Copy link
Contributor

mental32 commented Jan 6, 2021

Reproducible in the playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=a7e62bb084b21bc2081c79e320c740a0

Code

#![feature(const_evaluatable_checked)]
#![feature(const_generics)]

use core::fmt::Debug;
use core::marker::PhantomData;

struct Inline<T>
where [u8; ::core::mem::size_of::<T>() + 1]: 
{
    _phantom: PhantomData<T>,
    buf: [u8; ::core::mem::size_of::<T>() + 1]
}

impl<T> Inline<T>  where [u8; ::core::mem::size_of::<T>() + 1]: {
    pub fn new(val: T) -> Inline<T> {
        todo!()
    }
}

fn main() {
    // let dst = Inline::<usize>::new(0); OK
    let dst = Inline::<dyn Debug>::new(0);  // BANG!
}

Meta

rustc --version --verbose:

rustc 1.51.0-nightly (61f5a0092 2021-01-04)
binary: rustc
commit-hash: 61f5a0092364061ec5649ca98d5e3e9b927880fe
commit-date: 2021-01-04
host: x86_64-unknown-linux-gnu
release: 1.51.0-nightly

Error output

   Compiling icey v0.1.0 (/tmp/icey)
warning: the feature `const_evaluatable_checked` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/main.rs:1:12
  |
1 | #![feature(const_evaluatable_checked)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information

warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/main.rs:2:12
  |
2 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information

thread 'rustc' panicked at 'SizeOf nullary MIR operator called for unsized type', compiler/rustc_mir/src/interpret/step.rs:267:17
note: run with `RUST_BACKTRACE=1` environment variable to display a 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.51.0-nightly (61f5a0092 2021-01-04) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `Inline::<T>::{constant#0}`
#1 [eval_to_const_value_raw] simplifying constant for the type system `Inline::<T>::{constant#0}`
end of query stack
warning: 2 warnings emitted

error: could not compile `icey`

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

   Compiling icey v0.1.0 (/tmp/icey)
warning: the feature `const_evaluatable_checked` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/main.rs:1:12
  |
1 | #![feature(const_evaluatable_checked)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information

warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/main.rs:2:12
  |
2 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information

thread 'rustc' panicked at 'SizeOf nullary MIR operator called for unsized type', compiler/rustc_mir/src/interpret/step.rs:267:17
stack backtrace:
   0: std::panicking::begin_panic
   1: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::eval_rvalue_into_place
   2: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::run
   3: rustc_mir::const_eval::eval_queries::eval_to_allocation_raw_provider
   4: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::eval_to_allocation_raw>::compute
   5: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
   6: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
   7: rustc_data_structures::stack::ensure_sufficient_stack
   8: rustc_query_system::query::plumbing::get_query_impl
   9: rustc_mir::const_eval::eval_queries::eval_to_const_value_raw_provider
  10: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::eval_to_const_value_raw>::compute
  11: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  12: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  13: rustc_data_structures::stack::ensure_sufficient_stack
  14: rustc_query_system::query::plumbing::get_query_impl
  15: rustc_middle::mir::interpret::queries::<impl rustc_middle::ty::context::TyCtxt>::const_eval_resolve
  16: rustc_infer::infer::InferCtxt::const_eval_resolve
  17: rustc_trait_selection::traits::const_evaluatable::is_const_evaluatable
  18: rustc_trait_selection::traits::select::SelectionContext::evaluate_predicate_recursively::{{closure}}
  19: rustc_trait_selection::traits::select::SelectionContext::evaluate_predicate_recursively
  20: rustc_infer::infer::InferCtxt::probe
  21: rustc_trait_selection::traits::select::SelectionContext::evaluate_root_obligation
  22: rustc_infer::infer::InferCtxtBuilder::enter_with_canonical
  23: rustc_traits::evaluate_obligation::evaluate_obligation
  24: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::evaluate_obligation>::compute
  25: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  26: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  27: rustc_data_structures::stack::ensure_sufficient_stack
  28: rustc_query_system::query::plumbing::get_query_impl
  29: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation
  30: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation_no_overflow
  31: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::predicate_may_hold
  32: rustc_infer::infer::InferCtxt::probe
  33: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
  34: rustc_typeck::check::method::probe::ProbeContext::pick_method
  35: rustc_typeck::check::method::probe::ProbeContext::pick_core
  36: rustc_typeck::check::method::probe::ProbeContext::pick
  37: rustc_infer::infer::InferCtxt::probe
  38: rustc_typeck::check::method::probe::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::probe_for_name
  39: rustc_typeck::check::method::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::resolve_ufcs
  40: rustc_typeck::check::fn_ctxt::_impl::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::resolve_ty_and_res_ufcs
  41: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  42: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  43: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_call
  44: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  45: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  46: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_decl_initializer
  47: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_decl_local
  48: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_stmt
  49: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  50: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  51: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
  52: rustc_typeck::check::check::check_fn
  53: rustc_infer::infer::InferCtxtBuilder::enter
  54: rustc_typeck::check::typeck
  55: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck>::compute
  56: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  57: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  58: rustc_data_structures::stack::ensure_sufficient_stack
  59: rustc_query_system::query::plumbing::get_query_impl
  60: rustc_query_system::query::plumbing::ensure_query_impl
  61: rustc_typeck::check::typeck_item_bodies
  62: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck_item_bodies>::compute
  63: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  64: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  65: rustc_data_structures::stack::ensure_sufficient_stack
  66: rustc_query_system::query::plumbing::get_query_impl
  67: rustc_typeck::check_crate
  68: rustc_interface::passes::analysis
  69: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  70: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  71: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  72: rustc_data_structures::stack::ensure_sufficient_stack
  73: rustc_query_system::query::plumbing::get_query_impl
  74: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  75: rustc_span::with_source_map
  76: rustc_interface::interface::create_compiler_and_run
  77: rustc_span::with_session_globals
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.51.0-nightly (61f5a0092 2021-01-04) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `Inline::<T>::{constant#0}`
#1 [eval_to_const_value_raw] simplifying constant for the type system `Inline::<T>::{constant#0}`
#2 [evaluate_obligation] evaluating trait selection obligation `the constant `Inline::<dyn std::fmt::Debug>::{constant#0}` can be evaluated`
#3 [typeck] type-checking `main`
#4 [typeck_item_bodies] type-checking all item bodies
#5 [analysis] running analysis passes on this crate
end of query stack
warning: 2 warnings emitted

error: could not compile `icey`

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

@mental32 mental32 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 Jan 6, 2021
@jonas-schievink jonas-schievink added F-generic_const_exprs `#![feature(generic_const_exprs)]` F-const_generics `#![feature(const_generics)]` labels Jan 6, 2021
JohnTitor added a commit to JohnTitor/glacier that referenced this issue Jan 15, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jan 15, 2021
m-ou-se added a commit to m-ou-se/rust that referenced this issue Jan 20, 2021
Fix ICE in mir when evaluating SizeOf on unsized type

Not quite ready yet. This tries to fix rust-lang#80742 as discussed on [Zulip topic][1],
by using `delay_span_bug`.

I don't understand what `delay_span_bug` does. It seems like my error message
is never used. With this patch, in this program:

```rust
#![allow(incomplete_features)]
#![feature(const_evaluatable_checked)]
#![feature(const_generics)]

use std::fmt::Debug;
use std::marker::PhantomData;
use std::mem::size_of;

struct Inline<T>
where
    [u8; size_of::<T>() + 1]: ,
{
    _phantom: PhantomData<T>,
    buf: [u8; size_of::<T>() + 1],
}

impl<T> Inline<T>
where
    [u8; size_of::<T>() + 1]: ,
{
    pub fn new(val: T) -> Inline<T> {
        todo!()
    }
}

fn main() {
    let dst = Inline::<dyn Debug>::new(0); // line 27
}
```

these errors are printed, both for line 27 (annotated line above):

- "no function or associated item named `new` found for struct `Inline<dyn
  Debug>` in the current scope"
- "the size for values of type `dyn Debug` cannot be known at compilation time"

Second error makes sense, but I'm not sure about the first one and why it's
even printed.

Finally, I'm not sure about the span passing in `const_eval`.

[1]: https://rust-lang.zulipchat.com/#narrow/stream/269128-miri/topic/Help.20fixing.20.2380742
m-ou-se added a commit to m-ou-se/rust that referenced this issue Jan 20, 2021
Fix ICE in mir when evaluating SizeOf on unsized type

Not quite ready yet. This tries to fix rust-lang#80742 as discussed on [Zulip topic][1],
by using `delay_span_bug`.

I don't understand what `delay_span_bug` does. It seems like my error message
is never used. With this patch, in this program:

```rust
#![allow(incomplete_features)]
#![feature(const_evaluatable_checked)]
#![feature(const_generics)]

use std::fmt::Debug;
use std::marker::PhantomData;
use std::mem::size_of;

struct Inline<T>
where
    [u8; size_of::<T>() + 1]: ,
{
    _phantom: PhantomData<T>,
    buf: [u8; size_of::<T>() + 1],
}

impl<T> Inline<T>
where
    [u8; size_of::<T>() + 1]: ,
{
    pub fn new(val: T) -> Inline<T> {
        todo!()
    }
}

fn main() {
    let dst = Inline::<dyn Debug>::new(0); // line 27
}
```

these errors are printed, both for line 27 (annotated line above):

- "no function or associated item named `new` found for struct `Inline<dyn
  Debug>` in the current scope"
- "the size for values of type `dyn Debug` cannot be known at compilation time"

Second error makes sense, but I'm not sure about the first one and why it's
even printed.

Finally, I'm not sure about the span passing in `const_eval`.

[1]: https://rust-lang.zulipchat.com/#narrow/stream/269128-miri/topic/Help.20fixing.20.2380742
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jan 21, 2021
Fix ICE in mir when evaluating SizeOf on unsized type

Not quite ready yet. This tries to fix rust-lang#80742 as discussed on [Zulip topic][1],
by using `delay_span_bug`.

I don't understand what `delay_span_bug` does. It seems like my error message
is never used. With this patch, in this program:

```rust
#![allow(incomplete_features)]
#![feature(const_evaluatable_checked)]
#![feature(const_generics)]

use std::fmt::Debug;
use std::marker::PhantomData;
use std::mem::size_of;

struct Inline<T>
where
    [u8; size_of::<T>() + 1]: ,
{
    _phantom: PhantomData<T>,
    buf: [u8; size_of::<T>() + 1],
}

impl<T> Inline<T>
where
    [u8; size_of::<T>() + 1]: ,
{
    pub fn new(val: T) -> Inline<T> {
        todo!()
    }
}

fn main() {
    let dst = Inline::<dyn Debug>::new(0); // line 27
}
```

these errors are printed, both for line 27 (annotated line above):

- "no function or associated item named `new` found for struct `Inline<dyn
  Debug>` in the current scope"
- "the size for values of type `dyn Debug` cannot be known at compilation time"

Second error makes sense, but I'm not sure about the first one and why it's
even printed.

Finally, I'm not sure about the span passing in `const_eval`.

[1]: https://rust-lang.zulipchat.com/#narrow/stream/269128-miri/topic/Help.20fixing.20.2380742
@bors bors closed this as completed in 3fb53c2 Jan 21, 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. F-const_generics `#![feature(const_generics)]` F-generic_const_exprs `#![feature(generic_const_exprs)]` 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.

3 participants