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: Got a scalar pair where a scalar was expected #121363

Open
matthiaskrgr opened this issue Feb 20, 2024 · 13 comments
Open

ICE: Got a scalar pair where a scalar was expected #121363

matthiaskrgr opened this issue Feb 20, 2024 · 13 comments
Labels
A-mir-opt Area: MIR optimizations C-bug Category: This is a bug. F-trivial_bounds `#![feature(trivial_bounds)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

#![feature(trivial_bounds)]

#[derive(Debug)]
struct TwoStrs(str, str)
where
    str: Sized;

original:

#[derive(Debug)]
struct Foo(i32);

#[derive(Debug)]
struct TwoStrs(str, str) where str: Sized;

Version information

rustc 1.78.0-nightly (bb594538f 2024-02-20)
binary: rustc
commit-hash: bb594538fc6e84213a6b8d5e165442570aa48923
commit-date: 2024-02-20
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zmir-opt-level=5 -Zcrate-attr=feature(trivial_bounds) --crate-type=lib

Program output

warning: struct `TwoStrs` is never constructed
 --> /tmp/icemaker_global_tempdir.d7BGTl8YHHxI/rustc_testrunner_tmpdir_reporting.Zw6CwslhbT5j/mvce.rs:2:8
  |
2 | struct TwoStrs(str, str)
  |        ^^^^^^^
  |
  = note: `TwoStrs` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
  = note: `#[warn(dead_code)]` on by default

warning: trait bound str: Sized does not depend on any type or lifetime parameters
 --> /tmp/icemaker_global_tempdir.d7BGTl8YHHxI/rustc_testrunner_tmpdir_reporting.Zw6CwslhbT5j/mvce.rs:4:10
  |
4 |     str: Sized;
  |          ^^^^^
  |
  = note: `#[warn(trivial_bounds)]` on by default

error: internal compiler error: /rustc/bb594538fc6e84213a6b8d5e165442570aa48923/compiler/rustc_const_eval/src/interpret/operand.rs:82:42: Got a scalar pair where a scalar was expected

thread 'rustc' panicked at compiler/rustc_middle/src/util/bug.rs:35:44:
Box<dyn Any>
stack backtrace:
   0:     0x7ff23b050af6 - std::backtrace_rs::backtrace::libunwind::trace::h1eedb42239d9af6b
                               at /rustc/bb594538fc6e84213a6b8d5e165442570aa48923/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7ff23b050af6 - std::backtrace_rs::backtrace::trace_unsynchronized::hf37e37075d32c152
                               at /rustc/bb594538fc6e84213a6b8d5e165442570aa48923/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7ff23b050af6 - std::sys_common::backtrace::_print_fmt::h089ff4e21712e78d
                               at /rustc/bb594538fc6e84213a6b8d5e165442570aa48923/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7ff23b050af6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h249f2f40a85530bd
                               at /rustc/bb594538fc6e84213a6b8d5e165442570aa48923/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7ff23b0a1a7c - core::fmt::rt::Argument::fmt::h0aeed2b676ebf5da
                               at /rustc/bb594538fc6e84213a6b8d5e165442570aa48923/library/core/src/fmt/rt.rs:142:9
   5:     0x7ff23b0a1a7c - core::fmt::write::h25b3f5340152b6c4
                               at /rustc/bb594538fc6e84213a6b8d5e165442570aa48923/library/core/src/fmt/mod.rs:1120:17
   6:     0x7ff23b04542f - std::io::Write::write_fmt::h8746a81e0adfe285
                               at /rustc/bb594538fc6e84213a6b8d5e165442570aa48923/library/std/src/io/mod.rs:1846:15
   7:     0x7ff23b0508a4 - std::sys_common::backtrace::_print::hcf22409f3667d346
                               at /rustc/bb594538fc6e84213a6b8d5e165442570aa48923/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7ff23b0508a4 - std::sys_common::backtrace::print::h7d3fd33863df24d3
                               at /rustc/bb594538fc6e84213a6b8d5e165442570aa48923/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7ff23b0535eb - std::panicking::default_hook::{{closure}}::h69f3f4f5b3bceec1
  10:     0x7ff23b053339 - std::panicking::default_hook::hf73563d650f0e118
                               at /rustc/bb594538fc6e84213a6b8d5e165442570aa48923/library/std/src/panicking.rs:292:9
  11:     0x7ff237e1a63c - std[38a2ac7f7aa65357]::panicking::update_hook::<alloc[250c3b7c6f6c60ed]::boxed::Box<rustc_driver_impl[98bdfcf9c8fb7ba2]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7ff23b053d50 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h0f1d4fd9cb21869d
                               at /rustc/bb594538fc6e84213a6b8d5e165442570aa48923/library/alloc/src/boxed.rs:2030:9
  13:     0x7ff23b053d50 - std::panicking::rust_panic_with_hook::h55549baaf7aa2e9c
                               at /rustc/bb594538fc6e84213a6b8d5e165442570aa48923/library/std/src/panicking.rs:786:13
  14:     0x7ff237e47244 - std[38a2ac7f7aa65357]::panicking::begin_panic::<rustc_errors[31b00c9a61d6a627]::ExplicitBug>::{closure#0}
  15:     0x7ff237e43e96 - std[38a2ac7f7aa65357]::sys_common::backtrace::__rust_end_short_backtrace::<std[38a2ac7f7aa65357]::panicking::begin_panic<rustc_errors[31b00c9a61d6a627]::ExplicitBug>::{closure#0}, !>
  16:     0x7ff237e3f626 - std[38a2ac7f7aa65357]::panicking::begin_panic::<rustc_errors[31b00c9a61d6a627]::ExplicitBug>
  17:     0x7ff237e51ad1 - <rustc_errors[31b00c9a61d6a627]::diagnostic_builder::BugAbort as rustc_errors[31b00c9a61d6a627]::diagnostic_builder::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7ff2382247ec - <rustc_errors[31b00c9a61d6a627]::DiagCtxt>::bug::<alloc[250c3b7c6f6c60ed]::string::String>
  19:     0x7ff2382c76eb - rustc_middle[cfb3c689534e2244]::util::bug::opt_span_bug_fmt::<rustc_span[39701832932d6f53]::span_encoding::Span>::{closure#0}
  20:     0x7ff2382ac41a - rustc_middle[cfb3c689534e2244]::ty::context::tls::with_opt::<rustc_middle[cfb3c689534e2244]::util::bug::opt_span_bug_fmt<rustc_span[39701832932d6f53]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7ff2382ac2b8 - rustc_middle[cfb3c689534e2244]::ty::context::tls::with_context_opt::<rustc_middle[cfb3c689534e2244]::ty::context::tls::with_opt<rustc_middle[cfb3c689534e2244]::util::bug::opt_span_bug_fmt<rustc_span[39701832932d6f53]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7ff236740bc0 - rustc_middle[cfb3c689534e2244]::util::bug::bug_fmt
  23:     0x7ff2395a8f6b - <rustc_mir_transform[3a9949066bb08602]::gvn::VnState>::simplify_operand
  24:     0x7ff2370be253 - <rustc_mir_transform[3a9949066bb08602]::gvn::GVN as rustc_middle[cfb3c689534e2244]::mir::MirPass>::run_pass
  25:     0x7ff239012649 - rustc_mir_transform[3a9949066bb08602]::pass_manager::run_passes_inner
  26:     0x7ff2394a84bf - rustc_mir_transform[3a9949066bb08602]::optimized_mir
  27:     0x7ff239073c75 - rustc_query_impl[72e671e77ccdc0fd]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[72e671e77ccdc0fd]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[cfb3c689534e2244]::query::erase::Erased<[u8; 8usize]>>
  28:     0x7ff239074321 - rustc_query_system[eb6d0acd22a0ff82]::query::plumbing::try_execute_query::<rustc_query_impl[72e671e77ccdc0fd]::DynamicConfig<rustc_query_system[eb6d0acd22a0ff82]::query::caches::DefIdCache<rustc_middle[cfb3c689534e2244]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[72e671e77ccdc0fd]::plumbing::QueryCtxt, false>
  29:     0x7ff239073a9e - rustc_query_impl[72e671e77ccdc0fd]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  30:     0x7ff239453461 - rustc_middle[cfb3c689534e2244]::query::plumbing::query_get_at::<rustc_query_system[eb6d0acd22a0ff82]::query::caches::DefIdCache<rustc_middle[cfb3c689534e2244]::query::erase::Erased<[u8; 8usize]>>>
  31:     0x7ff239f9d7fd - <rustc_metadata[7844668d1f998472]::rmeta::encoder::EncodeContext>::encode_crate_root
  32:     0x7ff239fdf116 - rustc_metadata[7844668d1f998472]::rmeta::encoder::encode_metadata
  33:     0x7ff239fdd2b8 - rustc_metadata[7844668d1f998472]::fs::encode_and_write_metadata
  34:     0x7ff239fdc65d - rustc_interface[d43ea88de449c898]::passes::start_codegen
  35:     0x7ff239fdbed8 - <rustc_interface[d43ea88de449c898]::queries::Queries>::codegen_and_build_linker
  36:     0x7ff239d6482d - rustc_interface[d43ea88de449c898]::interface::run_compiler::<core[9082f35584c4c405]::result::Result<(), rustc_span[39701832932d6f53]::ErrorGuaranteed>, rustc_driver_impl[98bdfcf9c8fb7ba2]::run_compiler::{closure#0}>::{closure#0}
  37:     0x7ff239fc1c05 - std[38a2ac7f7aa65357]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[d43ea88de449c898]::util::run_in_thread_with_globals<rustc_interface[d43ea88de449c898]::util::run_in_thread_pool_with_globals<rustc_interface[d43ea88de449c898]::interface::run_compiler<core[9082f35584c4c405]::result::Result<(), rustc_span[39701832932d6f53]::ErrorGuaranteed>, rustc_driver_impl[98bdfcf9c8fb7ba2]::run_compiler::{closure#0}>::{closure#0}, core[9082f35584c4c405]::result::Result<(), rustc_span[39701832932d6f53]::ErrorGuaranteed>>::{closure#0}, core[9082f35584c4c405]::result::Result<(), rustc_span[39701832932d6f53]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[9082f35584c4c405]::result::Result<(), rustc_span[39701832932d6f53]::ErrorGuaranteed>>
  38:     0x7ff239fc1a32 - <<std[38a2ac7f7aa65357]::thread::Builder>::spawn_unchecked_<rustc_interface[d43ea88de449c898]::util::run_in_thread_with_globals<rustc_interface[d43ea88de449c898]::util::run_in_thread_pool_with_globals<rustc_interface[d43ea88de449c898]::interface::run_compiler<core[9082f35584c4c405]::result::Result<(), rustc_span[39701832932d6f53]::ErrorGuaranteed>, rustc_driver_impl[98bdfcf9c8fb7ba2]::run_compiler::{closure#0}>::{closure#0}, core[9082f35584c4c405]::result::Result<(), rustc_span[39701832932d6f53]::ErrorGuaranteed>>::{closure#0}, core[9082f35584c4c405]::result::Result<(), rustc_span[39701832932d6f53]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[9082f35584c4c405]::result::Result<(), rustc_span[39701832932d6f53]::ErrorGuaranteed>>::{closure#1} as core[9082f35584c4c405]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  39:     0x7ff23b05d725 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h8e2928e2096a726d
                               at /rustc/bb594538fc6e84213a6b8d5e165442570aa48923/library/alloc/src/boxed.rs:2016:9
  40:     0x7ff23b05d725 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h4f25e5317edfd617
                               at /rustc/bb594538fc6e84213a6b8d5e165442570aa48923/library/alloc/src/boxed.rs:2016:9
  41:     0x7ff23b05d725 - std::sys::pal::unix::thread::Thread::new::thread_start::hc7193b55f6b48c9a
                               at /rustc/bb594538fc6e84213a6b8d5e165442570aa48923/library/std/src/sys/pal/unix/thread.rs:108:17
  42:     0x7ff234eaa9eb - <unknown>
  43:     0x7ff234f2e7cc - <unknown>
  44:                0x0 - <unknown>

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.78.0-nightly (bb594538f 2024-02-20) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=5 -Z crate-attr=feature(trivial_bounds) --crate-type lib -Z dump-mir-dir=dir

query stack during panic:
#0 [optimized_mir] optimizing MIR for `<impl at /tmp/icemaker_global_tempdir.d7BGTl8YHHxI/rustc_testrunner_tmpdir_reporting.Zw6CwslhbT5j/mvce.rs:1:10: 1:15>::fmt`
end of query stack
error: aborting due to 1 previous error; 2 warnings emitted


@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. A-mir-opt Area: MIR optimizations F-trivial_bounds `#![feature(trivial_bounds)]` labels Feb 20, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 20, 2024
@matthiaskrgr
Copy link
Member Author

this bisects to #117363 🤔 cc @saethlin

@saethlin
Copy link
Member

Can you try re-bisecting with -Zcross-crate-inline-threshold=0 or -Zinline-mir=no?

@matthiaskrgr
Copy link
Member Author

with -Zmir-opt-level=5 --crate-type=lib -Zinline-mir=no , this bisects to #117727

@saethlin
Copy link
Member

Good, that's what I expected. What does this bisect to?

struct TwoStrs(str, str) where str: Sized;
impl ::core::fmt::Debug for TwoStrs where str: Sized {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_tuple_field2_finish(f, "TwoStrs",
            &self.0, &&self.1)
    }
}

(I just expanded your example and deleted the #[inline])

@matthiaskrgr
Copy link
Member Author

with --edition=2021 -Zmir-opt-level=5 --crate-type=lib also to #117363

@saethlin
Copy link
Member

Whatever minimization you do should always try to turn off as many MIR optimizations as possible. The machine-accessible thing is to lower the mir-opt-level, because we don't have a machine-readable list of what passes are enabled that I'm aware of (perhaps you could extract one from logs, but no thanks).

Bisecting with -Zmir-opt-level=0:

********************************************************************************
Regression in nightly-2022-12-11
********************************************************************************

fetching https://static.rust-lang.org/dist/2022-12-10/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2022-12-10: 40 B / 40 B [=================================================================] 100.00 % 1.11 MB/s converted 2022-12-10 to dfe3fe710181738a2cb3060c23ec5efb3c68ca09
fetching https://static.rust-lang.org/dist/2022-12-11/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2022-12-11: 40 B / 40 B [===============================================================] 100.00 % 697.96 KB/s converted 2022-12-11 to c6fcdb690609769a240fc8ab0de0ce68d5ea7dba
looking for regression commit between 2022-12-10 and 2022-12-11
fetching (via remote github) commits from max(dfe3fe710181738a2cb3060c23ec5efb3c68ca09, 2022-12-08) to c6fcdb690609769a240fc8ab0de0ce68d5ea7dba
ending github query because we found starting sha: dfe3fe710181738a2cb3060c23ec5efb3c68ca09
get_commits_between returning commits, len: 8
  commit[0] 2022-12-09: Auto merge of #105499 - pietroalbini:pa-bump-version, r=pietroalbini
  commit[1] 2022-12-09: Auto merge of #105363 - WaffleLapkin:thin2win_box_next_argument, r=nnethercote
  commit[2] 2022-12-10: Auto merge of #105512 - matthiaskrgr:rollup-i74avrf, r=matthiaskrgr
  commit[3] 2022-12-10: Auto merge of #105357 - oli-obk:feeding, r=cjgillot,petrochenkov
  commit[4] 2022-12-10: Auto merge of #105525 - matthiaskrgr:rollup-ricyw5s, r=matthiaskrgr
  commit[5] 2022-12-10: Auto merge of #105384 - uweigand:s390x-test-codegen, r=Mark-Simulacrum
  commit[6] 2022-12-10: Auto merge of #105531 - matthiaskrgr:rollup-7y7zbgl, r=matthiaskrgr
  commit[7] 2022-12-10: Auto merge of #105416 - nnethercote:more-linting-tweaks, r=cjgillot
ERROR: no CI builds available between dfe3fe710181738a2cb3060c23ec5efb3c68ca09 and c6fcdb690609769a240fc8ab0de0ce68d5ea7dba within last 167 days

@saethlin
Copy link
Member

To be clear, the reason you should try to do this is that the MIR optimization pipeline gets tweaked constantly, so if you just turn on all MIR optimizations possible, the bisection can easily get confused because among other things, the behavior of the inliner can fluctuate from nightly to nightly, even if the MIR optimization code wasn't changed.

Minimizing or eliminating the MIR optimizations involved in the reproducer helps with that effect a lot.

@matthiaskrgr
Copy link
Member Author

I have not been able to crash it with -Zmir-opt-level=0

@saethlin
Copy link
Member

That's odd. I can crash godbolt: https://godbolt.org/z/haMGExKM6

@matthiaskrgr
Copy link
Member Author

ah you made it a pub struct!

@matthiaskrgr
Copy link
Member Author

#![feature(trivial_bounds)]

#[derive(Debug)]
pub struct TwoStrs(str, str)
where
    str: Sized;

with -Zmir-opt-level=0 --crate-type lib:

Regression in nightly-2022-12-11
commit[0] 2022-12-09: Auto merge of #105499 - pietroalbini:pa-bump-version, r=pietroalbini
commit[1] 2022-12-09: Auto merge of #105363 - WaffleLapkin:thin2win_box_next_argument, r=nnethercote
commit[2] 2022-12-10: Auto merge of #105512 - matthiaskrgr:rollup-i74avrf, r=matthiaskrgr
commit[3] 2022-12-10: Auto merge of #105357 - oli-obk:feeding, r=cjgillot,petrochenkov
commit[4] 2022-12-10: Auto merge of #105525 - matthiaskrgr:rollup-ricyw5s, r=matthiaskrgr
commit[5] 2022-12-10: Auto merge of #105384 - uweigand:s390x-test-codegen, r=Mark-Simulacrum
commit[6] 2022-12-10: Auto merge of #105531 - matthiaskrgr:rollup-7y7zbgl, r=matthiaskrgr
commit[7] 2022-12-10: Auto merge of #105416 - nnethercote:more-linting-tweaks, r=cjgillot
ERROR: no CI builds available between dfe3fe7 and c6fcdb6 within last 167 days

@saethlin
Copy link
Member

Ah. I'm in the habit of making things pub if I want to know about their MIR.

@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 29, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 19, 2024
@matthiaskrgr
Copy link
Member Author

reproducible with -Zmir-enable-passes=+GVN --crate-type lib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt Area: MIR optimizations C-bug Category: This is a bug. F-trivial_bounds `#![feature(trivial_bounds)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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