Closed matthiaskrgr closed 3 months ago
cc @cjgillot
I cannot reproduce the original anymore, but #121357 does reproduce. The body is impossible because of the where clauses, so no MIR opts should ever run on it... I'll take a look.
I can still reproduce this with the original mvce when I use the flags that I listed.
bisected #121357 with -Zmir-opt-level=4
searched nightlies: from nightly-2023-09-01 to nightly-2023-10-01 regressed nightly: nightly-2023-09-09 searched commit range: https://github.com/rust-lang/rust/compare/1e746d7741d44551e9378daf13b8797322aa0b74...62ebe3a2b177d50ec664798d731b8a8d1a9120d1 regressed commit: https://github.com/rust-lang/rust/commit/3cd97ed3c3efe11bf6b63d23dce2515238b78a57
bisected with cargo-bisect-rustc v0.6.8
cc #115612 oli was right: https://github.com/rust-lang/rust/issues/116513#issuecomment-1752003649
The bisection here isn't useful sadly, but thank you anyways.
I took a look and yeah, the issue is what I suspected. impossible_predicates
(https://github.com/rust-lang/rust/blob/bb594538fc6e84213a6b8d5e165442570aa48923/compiler/rustc_mir_transform/src/lib.rs#L451) checks whether there are any impossible predicates (like Self: Sized
here). It sadly has to filter out "non-global" predicates, which Self: Sized
belongs to. It has to do this because of overflows as mentioned above.
@compiler-errors told me that the new trait solvers non-fatal handling of overflow will allow this to be fixed. But until then, there's nothing we can do.
As for getting the code working, the solution here so to avoid these impossible bounds wherever possible. In the example here, that's easy to do, just delete it. In #121357 that's a bit more annoying, I don't really see a solution.
We could try playing whack-a-mole by trying to make the MIR opts sorta-handle these cases that slip through, but I don't think that's very sustainable. Might work at least for the trivial cases like #121357 though, but I don't open PRs for that.
another one
fn cast_same_meta<T: ?Sized, U: ?Sized>(ptr: *const T) -> *const U {}
fn sized_slice<T>(ptr: *const [T]) -> *const str
where
[T]: Sized,
{
cast_same_meta(ptr)
}
I'm afraid that this has reached stable with 1.78. I couldn't reproduce it with the minimal example in the previous comment, but a crate of mine now fails on stable, but compiled fine on 1.77.2:
/tmp/ ➜ cargo new ice
Creating binary (application) `ice` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
/tmp/ ➜ cd ice
/tmp/ice/ (master ✔) ➜ cargo add lina
Updating crates.io index
Adding lina v0.2.1 to dependencies
Updating crates.io index
/tmp/ice/ (master ✔) ➜ cargo +1.77.2 build -r
Compiling autocfg v1.3.0
Compiling bytemuck v1.15.0
Compiling num-traits v0.2.19
Compiling lina v0.2.1
Compiling ice v0.1.0 (/tmp/ice)
Finished release [optimized] target(s) in 0.69s
/tmp/ice/ (master ✔) ➜ cargo +1.78.0 build -r
Compiling autocfg v1.3.0
Compiling bytemuck v1.15.0
Compiling num-traits v0.2.19
Compiling lina v0.2.1
thread 'rustc' panicked at compiler/rustc_mir_dataflow/src/value_analysis.rs:849:13:
slices are not scalars
The code responsible for this is fairly simple:
https://github.com/LukasKalbertodt/lina/blob/ce5fb13cd6fec882a1fdd4ec85ae8dadcad037f6/src/mat/hc.rs
Removing that impl makes the crate compile again.
Will we still just wait for the new solver, now that it's a stable-stable regression?
I managed to minimize the example from lina
:
use bytemuck::Pod; // 1.15.0
struct NPlusOneArray<T, const N: usize>([T; N], T);
impl<T: Pod, const N: usize> AsRef<[T]> for NPlusOneArray<T, N>
where
[T]: Pod,
{
fn as_ref(&self) -> &[T] {
todo!()
}
}
(On Playground, ICE in release mode)
File: /tmp/icemaker/033b7887410cef9d40e915f3b66f44d747d3e0d2.rs
https://github.com/rust-lang/rust/issues/116513 season two
auto-reduced (treereduce-rust):
original:
Version information
Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zmir-opt-level=3 --emit=mir
Program output
``` warning: unused variable: `it` --> /tmp/icemaker/033b7887410cef9d40e915f3b66f44d747d3e0d2.rs:3:12 | 3 | fn hey (it: &[T])
| ^^ help: if this is intentional, prefix it with an underscore: `_it`
|
= note: `#[warn(unused_variables)]` on by default
warning: function `hey` is never used
--> /tmp/icemaker/033b7887410cef9d40e915f3b66f44d747d3e0d2.rs:3:4
|
3 | fn hey (it: &[T])
| ^^^
|
= note: `#[warn(dead_code)]` on by default
warning: function `bar` is never used
--> /tmp/icemaker/033b7887410cef9d40e915f3b66f44d747d3e0d2.rs:11:4
|
11 | fn bar (it: Box<[T]>)
| ^^^
warning: function `fun` is never used
--> /tmp/icemaker/033b7887410cef9d40e915f3b66f44d747d3e0d2.rs:19:4
|
19 | fn fun (it: &[T]) -> &T
| ^^^
warning: function `foo` is never used
--> /tmp/icemaker/033b7887410cef9d40e915f3b66f44d747d3e0d2.rs:26:4
|
26 | fn foo (it: Box<[T]>) -> T
| ^^^
thread 'rustc' panicked at compiler/rustc_mir_dataflow/src/value_analysis.rs:764:13:
slices are not scalars
stack backtrace:
0: 0x7f2ba6b628fc - std::backtrace_rs::backtrace::libunwind::trace::h03c0bf785ff8ac95
at /rustc/57ef8898520f7ff2c60341636bb86d94cb550e79/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
1: 0x7f2ba6b628fc - std::backtrace_rs::backtrace::trace_unsynchronized::heb554a194a8b8d76
at /rustc/57ef8898520f7ff2c60341636bb86d94cb550e79/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2: 0x7f2ba6b628fc - std::sys_common::backtrace::_print_fmt::h5104548cf2f1d04d
at /rustc/57ef8898520f7ff2c60341636bb86d94cb550e79/library/std/src/sys_common/backtrace.rs:67:5
3: 0x7f2ba6b628fc - ::fmt::h60a89bd281db8532
at /rustc/57ef8898520f7ff2c60341636bb86d94cb550e79/library/std/src/sys_common/backtrace.rs:44:22
4: 0x7f2ba6bca350 - core::fmt::rt::Argument::fmt::h3f967ff7ed1eb864
at /rustc/57ef8898520f7ff2c60341636bb86d94cb550e79/library/core/src/fmt/rt.rs:142:9
5: 0x7f2ba6bca350 - core::fmt::write::h6c7eacf90d438ccc
at /rustc/57ef8898520f7ff2c60341636bb86d94cb550e79/library/core/src/fmt/mod.rs:1117:17
6: 0x7f2ba6b55c4f - std::io::Write::write_fmt::heed557ad0e7e227d
at /rustc/57ef8898520f7ff2c60341636bb86d94cb550e79/library/std/src/io/mod.rs:1762:15
7: 0x7f2ba6b626e4 - std::sys_common::backtrace::_print::hc14194a28bba6478
at /rustc/57ef8898520f7ff2c60341636bb86d94cb550e79/library/std/src/sys_common/backtrace.rs:47:5
8: 0x7f2ba6b626e4 - std::sys_common::backtrace::print::h49644fe6309a893a
at /rustc/57ef8898520f7ff2c60341636bb86d94cb550e79/library/std/src/sys_common/backtrace.rs:34:9
9: 0x7f2ba6b654f7 - std::panicking::default_hook::{{closure}}::h2aa5ccff7297f9c8
10: 0x7f2ba6b6523a - std::panicking::default_hook::h9e4bff1aa2bdf161
at /rustc/57ef8898520f7ff2c60341636bb86d94cb550e79/library/std/src/panicking.rs:292:9
11: 0x7f2ba9718daa - std[5f80c380de201c9c]::panicking::update_hook::>::{closure#0}
12: 0x7f2ba6b65c98 - as core::ops::function::Fn>::call::h372bad5385f8c0c5
at /rustc/57ef8898520f7ff2c60341636bb86d94cb550e79/library/alloc/src/boxed.rs:2021:9
13: 0x7f2ba6b65c98 - std::panicking::rust_panic_with_hook::h6c6741452089fc1b
at /rustc/57ef8898520f7ff2c60341636bb86d94cb550e79/library/std/src/panicking.rs:735:13
14: 0x7f2ba6b659a6 - std::panicking::begin_panic_handler::{{closure}}::h281b553b64b3c920
at /rustc/57ef8898520f7ff2c60341636bb86d94cb550e79/library/std/src/panicking.rs:601:13
15: 0x7f2ba6b62e16 - std::sys_common::backtrace::__rust_end_short_backtrace::h3fa2532f3895ceba
at /rustc/57ef8898520f7ff2c60341636bb86d94cb550e79/library/std/src/sys_common/backtrace.rs:170:18
16: 0x7f2ba6b65722 - rust_begin_unwind
at /rustc/57ef8898520f7ff2c60341636bb86d94cb550e79/library/std/src/panicking.rs:597:5
17: 0x7f2ba6bc6975 - core::panicking::panic_fmt::h7601551d8f1de7d6
at /rustc/57ef8898520f7ff2c60341636bb86d94cb550e79/library/core/src/panicking.rs:72:14
18: 0x7f2ba9c2a8b7 - ::register_children
19: 0x7f2ba9c299b8 - ::new
20: 0x7f2ba9d0fd45 - ::run_pass
21: 0x7f2ba8560a5f - rustc_mir_transform[892ade550f628091]::pass_manager::run_passes_inner
22: 0x7f2ba8d69a6c - rustc_mir_transform[892ade550f628091]::optimized_mir
23: 0x7f2ba7a196dd - rustc_query_impl[d93ff4b57be0a3f9]::plumbing::__rust_begin_short_backtrace::>
24: 0x7f2ba7dcf2d1 - rustc_query_system[bf593801cb8c9f4a]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[d93ff4b57be0a3f9]::plumbing::QueryCtxt, false>
25: 0x7f2ba91d8a22 - rustc_query_impl[d93ff4b57be0a3f9]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
26: 0x7f2ba7c8bba0 - ::instance_mir
27: 0x7f2ba9af9e5e - rustc_middle[48fc6e82f368dfd0]::mir::pretty::write_mir_pretty
28: 0x7f2ba9cde8e3 - rustc_mir_transform[892ade550f628091]::dump_mir::emit_mir
29: 0x7f2ba8ef940f - rustc_interface[d1c057f52199548c]::passes::start_codegen
30: 0x7f2ba8ef8916 - ::ongoing_codegen
31: 0x7f2ba8ee7552 - std[5f80c380de201c9c]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[3ff10296a9c85239]::run_compiler::{closure#1}>::{closure#0}, core[5ecddd5f6ab0df47]::result::Result<(), rustc_span[3385b0a88a85fcb6]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5ecddd5f6ab0df47]::result::Result<(), rustc_span[3385b0a88a85fcb6]::ErrorGuaranteed>>
32: 0x7f2ba8ee67d3 - <::spawn_unchecked_, rustc_driver_impl[3ff10296a9c85239]::run_compiler::{closure#1}>::{closure#0}, core[5ecddd5f6ab0df47]::result::Result<(), rustc_span[3385b0a88a85fcb6]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5ecddd5f6ab0df47]::result::Result<(), rustc_span[3385b0a88a85fcb6]::ErrorGuaranteed>>::{closure#1} as core[5ecddd5f6ab0df47]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
33: 0x7f2ba6b70c05 - as core::ops::function::FnOnce>::call_once::h0018b354bb46a254
at /rustc/57ef8898520f7ff2c60341636bb86d94cb550e79/library/alloc/src/boxed.rs:2007:9
34: 0x7f2ba6b70c05 - as core::ops::function::FnOnce>::call_once::hb166705f6d4a8b53
at /rustc/57ef8898520f7ff2c60341636bb86d94cb550e79/library/alloc/src/boxed.rs:2007:9
35: 0x7f2ba6b70c05 - std::sys::unix::thread::Thread::new::thread_start::hdac26740529f6e03
at /rustc/57ef8898520f7ff2c60341636bb86d94cb550e79/library/std/src/sys/unix/thread.rs:108:17
36: 0x7f2ba69139eb -
37: 0x7f2ba69977cc -
38: 0x0 -
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 (57ef88985 2023-10-13) 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 `hey`
end of query stack
warning: 5 warnings emitted
```