rust-lang/rust

ice: `slices are not scalars`

Closed this issue · 5 comments

File: ./tests/ui/consts/issue-67696-const-prop-ice.rs

mvce:

trait A {
    fn foo(&self) -> Self
    where
        Self: Copy;
}

impl A for [fn(&())] {
    fn foo(&self) -> Self
    where
        Self: Copy,
    {
        *(&[] as &[_])
    }
}

fn main() {}

original:

// check-pass
// compile-flags: --emit=mir,link
// Checks that we don't ICE due to attempting to run const prop
// on a function with unsatisifable 'where' clauses

#![allow(unused)]

trait A {
    fn foo(&self) -> Self where Self: Copy;
}

impl A for [fn(&())] {
    fn foo(&self) -> Self where Self: Copy { *(&[] as &[_]) }
}

impl A for i32 {
    fn foo(&self) -> Self { 3 }
}

fn main() {}

Version information

rustc 1.75.0-nightly (d087c6fae 2023-10-07)
binary: rustc
commit-hash: d087c6fae215484bf47ba6dda1bc836ef4c07ac5
commit-date: 2023-10-07
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.2

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zmir-opt-level=3 --emit=mir

Program output:

thread 'rustc' panicked at compiler/rustc_mir_dataflow/src/value_analysis.rs:764:13:
slices are not scalars
stack backtrace:
   0:     0x7f9c3916387c - std::backtrace_rs::backtrace::libunwind::trace::hd4d4575a9c4ec1e8
                               at /rustc/d087c6fae215484bf47ba6dda1bc836ef4c07ac5/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f9c3916387c - std::backtrace_rs::backtrace::trace_unsynchronized::he6b5af4ffaf9b932
                               at /rustc/d087c6fae215484bf47ba6dda1bc836ef4c07ac5/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f9c3916387c - std::sys_common::backtrace::_print_fmt::h74d6f05f1b0c9626
                               at /rustc/d087c6fae215484bf47ba6dda1bc836ef4c07ac5/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f9c3916387c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5dd5d2aee3b5a38b
                               at /rustc/d087c6fae215484bf47ba6dda1bc836ef4c07ac5/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f9c391ca230 - core::fmt::rt::Argument::fmt::h2cdb73e4398806a6
                               at /rustc/d087c6fae215484bf47ba6dda1bc836ef4c07ac5/library/core/src/fmt/rt.rs:142:9
   5:     0x7f9c391ca230 - core::fmt::write::hfc88193b85ec3528
                               at /rustc/d087c6fae215484bf47ba6dda1bc836ef4c07ac5/library/core/src/fmt/mod.rs:1117:17
   6:     0x7f9c391567ff - std::io::Write::write_fmt::h053bf97a565d0650
                               at /rustc/d087c6fae215484bf47ba6dda1bc836ef4c07ac5/library/std/src/io/mod.rs:1763:15
   7:     0x7f9c39163664 - std::sys_common::backtrace::_print::h1ab2d700a675ac78
                               at /rustc/d087c6fae215484bf47ba6dda1bc836ef4c07ac5/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f9c39163664 - std::sys_common::backtrace::print::h9848cb2b046020fb
                               at /rustc/d087c6fae215484bf47ba6dda1bc836ef4c07ac5/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f9c39166477 - std::panicking::default_hook::{{closure}}::h309ff2f7aa5d4b4d
  10:     0x7f9c391661ba - std::panicking::default_hook::h1aee2c51f9426647
                               at /rustc/d087c6fae215484bf47ba6dda1bc836ef4c07ac5/library/std/src/panicking.rs:292:9
  11:     0x7f9c3bcf60b5 - std[2e97ee137061c0cc]::panicking::update_hook::<alloc[faab63393fa1d28c]::boxed::Box<rustc_driver_impl[ad7f1c0d954a7cf6]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f9c39166c18 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::he83415a3f50efcac
                               at /rustc/d087c6fae215484bf47ba6dda1bc836ef4c07ac5/library/alloc/src/boxed.rs:2021:9
  13:     0x7f9c39166c18 - std::panicking::rust_panic_with_hook::hf453d0ca3899627d
                               at /rustc/d087c6fae215484bf47ba6dda1bc836ef4c07ac5/library/std/src/panicking.rs:735:13
  14:     0x7f9c39166926 - std::panicking::begin_panic_handler::{{closure}}::h352379a27974c256
                               at /rustc/d087c6fae215484bf47ba6dda1bc836ef4c07ac5/library/std/src/panicking.rs:601:13
  15:     0x7f9c39163d96 - std::sys_common::backtrace::__rust_end_short_backtrace::h45dfdbca8969a626
                               at /rustc/d087c6fae215484bf47ba6dda1bc836ef4c07ac5/library/std/src/sys_common/backtrace.rs:170:18
  16:     0x7f9c391666a2 - rust_begin_unwind
                               at /rustc/d087c6fae215484bf47ba6dda1bc836ef4c07ac5/library/std/src/panicking.rs:597:5
  17:     0x7f9c391c6855 - core::panicking::panic_fmt::hd278514c79271747
                               at /rustc/d087c6fae215484bf47ba6dda1bc836ef4c07ac5/library/core/src/panicking.rs:72:14
  18:     0x7f9c3c212827 - <rustc_mir_dataflow[5234a11407ebe53f]::value_analysis::Map>::register_children
  19:     0x7f9c3c21192c - <rustc_mir_dataflow[5234a11407ebe53f]::value_analysis::Map>::new
  20:     0x7f9c3c2f80e5 - <rustc_mir_transform[d2eb6bf8c1dee0a0]::dataflow_const_prop::DataflowConstProp as rustc_middle[d05621295337e53f]::mir::MirPass>::run_pass
  21:     0x7f9c3aae3d3f - rustc_mir_transform[d2eb6bf8c1dee0a0]::pass_manager::run_passes_inner
  22:     0x7f9c3b341a60 - rustc_mir_transform[d2eb6bf8c1dee0a0]::optimized_mir
  23:     0x7f9c3a01c6dd - rustc_query_impl[6134f71abe3206fe]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6134f71abe3206fe]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d05621295337e53f]::query::erase::Erased<[u8; 8usize]>>
  24:     0x7f9c3a3777e1 - rustc_query_system[75efbc7eccd6fddf]::query::plumbing::try_execute_query::<rustc_query_impl[6134f71abe3206fe]::DynamicConfig<rustc_query_system[75efbc7eccd6fddf]::query::caches::DefaultCache<rustc_span[107d2069be8bccdd]::def_id::DefId, rustc_middle[d05621295337e53f]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[6134f71abe3206fe]::plumbing::QueryCtxt, false>
  25:     0x7f9c3b7b6062 - rustc_query_impl[6134f71abe3206fe]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  26:     0x7f9c3a29dd20 - <rustc_middle[d05621295337e53f]::ty::context::TyCtxt>::instance_mir
  27:     0x7f9c3c0dea4e - rustc_middle[d05621295337e53f]::mir::pretty::write_mir_pretty
  28:     0x7f9c3c2c56d3 - rustc_mir_transform[d2eb6bf8c1dee0a0]::dump_mir::emit_mir
  29:     0x7f9c3b4e390c - rustc_interface[265f3f69f2f90fb]::passes::start_codegen
  30:     0x7f9c3b4e2e06 - <rustc_interface[265f3f69f2f90fb]::queries::Queries>::ongoing_codegen
  31:     0x7f9c3b4d1a22 - std[2e97ee137061c0cc]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[265f3f69f2f90fb]::util::run_in_thread_with_globals<rustc_interface[265f3f69f2f90fb]::interface::run_compiler<core[ffd389c32db9b005]::result::Result<(), rustc_span[107d2069be8bccdd]::ErrorGuaranteed>, rustc_driver_impl[ad7f1c0d954a7cf6]::run_compiler::{closure#1}>::{closure#0}, core[ffd389c32db9b005]::result::Result<(), rustc_span[107d2069be8bccdd]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ffd389c32db9b005]::result::Result<(), rustc_span[107d2069be8bccdd]::ErrorGuaranteed>>
  32:     0x7f9c3b4d0c83 - <<std[2e97ee137061c0cc]::thread::Builder>::spawn_unchecked_<rustc_interface[265f3f69f2f90fb]::util::run_in_thread_with_globals<rustc_interface[265f3f69f2f90fb]::interface::run_compiler<core[ffd389c32db9b005]::result::Result<(), rustc_span[107d2069be8bccdd]::ErrorGuaranteed>, rustc_driver_impl[ad7f1c0d954a7cf6]::run_compiler::{closure#1}>::{closure#0}, core[ffd389c32db9b005]::result::Result<(), rustc_span[107d2069be8bccdd]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ffd389c32db9b005]::result::Result<(), rustc_span[107d2069be8bccdd]::ErrorGuaranteed>>::{closure#1} as core[ffd389c32db9b005]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:     0x7f9c39171b95 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h0dbd15d9959aaf81
                               at /rustc/d087c6fae215484bf47ba6dda1bc836ef4c07ac5/library/alloc/src/boxed.rs:2007:9
  34:     0x7f9c39171b95 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h41ce4f853e302519
                               at /rustc/d087c6fae215484bf47ba6dda1bc836ef4c07ac5/library/alloc/src/boxed.rs:2007:9
  35:     0x7f9c39171b95 - std::sys::unix::thread::Thread::new::thread_start::h1208042ab64f5aa2
                               at /rustc/d087c6fae215484bf47ba6dda1bc836ef4c07ac5/library/std/src/sys/unix/thread.rs:108:17
  36:     0x7f9c38f149eb - <unknown>
  37:     0x7f9c38f987cc - <unknown>
  38:                0x0 - <unknown>

error: 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.75.0-nightly (d087c6fae 2023-10-07) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=3 -Z dump-mir-dir=dir

query stack during panic:
#0 [optimized_mir] optimizing MIR for `<impl at /tmp/F/issue-67696-const-prop-ice.rs:12:1: 12:21>::foo`
end of query stack

ouz-a commented

I spent some time digging this, but I have no clue how is this happening yet.

Uh... isn't this regression from one of the dataflow const prop PRs? I don't think the is_global change caused

ouz-a commented

When I reverted changes to and problem disappeared.
Edit: My hunch is this problem existed before but somehow is_global covered it.