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

ReferencePropagation MIR opt prevents partial initialisation in MIR #111426

Closed
cbeuw opened this issue May 10, 2023 · 1 comment · Fixed by #111432
Closed

ReferencePropagation MIR opt prevents partial initialisation in MIR #111426

cbeuw opened this issue May 10, 2023 · 1 comment · Fixed by #111432
Labels
C-bug Category: This is a bug.

Comments

@cbeuw
Copy link
Contributor

cbeuw commented May 10, 2023

ReferencePropagation panics when a local of a composite type is initialised field-by-field (when the first assignment to this local is through a projection)

#![feature(custom_mir, core_intrinsics)]
extern crate core;
use core::intrinsics::mir::*;

#[custom_mir(dialect = "runtime", phase = "initial")]
pub fn fn0() {
    mir! (
        let x: (isize, );
        {
        x.0 = 1;
        Return()
        }
    )
}
pub fn main() {
    fn0();
}
% rustc +master -Zmir-opt-level=0 -Zmir-enable-passes=+ReferencePropagation repro.rs
thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `None`,
 right: `Some(_2)`', compiler/rustc_mir_transform/src/ssa.rs:276:9
stack backtrace:
   0:        0x104ad5abc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h55f7d97045313ad5
   1:        0x104b25570 - core::fmt::write::h106bf26cb364358d
   2:        0x104acbcc8 - std::io::Write::write_fmt::hde7b4c7920e77eda
   3:        0x104ad5910 - std::sys_common::backtrace::print::h95b67084a837f60c
   4:        0x104ad8314 - std::panicking::default_hook::{{closure}}::hf4eb388f1c340bec
   5:        0x104ad811c - std::panicking::default_hook::h3e20c7e694225675
   6:        0x10cf358e4 - rustc_driver_impl[57ad0c21a6a9d990]::install_ice_hook::{closure#0}
   7:        0x104ad8928 - std::panicking::rust_panic_with_hook::h4a5e4d9762ea7797
   8:        0x104ad8724 - std::panicking::begin_panic_handler::{{closure}}::h1b5a6942462f6646
   9:        0x104ad5eb4 - std::sys_common::backtrace::__rust_end_short_backtrace::h0bb3d97a073dbb67
  10:        0x104ad84b0 - _rust_begin_unwind
  11:        0x104b502fc - core::panicking::panic_fmt::h1b9b804fde1edf71
  12:        0x104b50660 - core::panicking::assert_failed_inner::hf8ed417130b26580
  13:        0x1111d9084 - core[fa76fbc839568f1d]::panicking::assert_failed::<core[fa76fbc839568f1d]::option::Option<rustc_middle[28ddddcee064ee09]::mir::Local>, core[fa76fbc839568f1d]::option::Option<rustc_middle[28ddddcee064ee09]::mir::Local>>
  14:        0x10f6760b4 - <rustc_mir_transform[94137a30ce227c72]::ssa::SsaLocals>::new
  15:        0x10f7943c0 - <rustc_mir_transform[94137a30ce227c72]::ref_prop::ReferencePropagation as rustc_middle[28ddddcee064ee09]::mir::MirPass>::run_pass
  16:        0x10f731854 - rustc_mir_transform[94137a30ce227c72]::pass_manager::run_passes_inner
  17:        0x10f664490 - rustc_mir_transform[94137a30ce227c72]::optimized_mir
  18:        0x11007cca0 - rustc_query_system[c91188e96fcab682]::query::plumbing::try_execute_query::<rustc_query_impl[b54e71c67810b295]::queries::optimized_mir, rustc_query_impl[b54e71c67810b295]::plumbing::QueryCtxt>
  19:        0x1101e57d8 - rustc_query_impl[b54e71c67810b295]::get_query::optimized_mir
  20:        0x110cc34a8 - rustc_middle[28ddddcee064ee09]::ty::query::query_get_at::<rustc_query_system[c91188e96fcab682]::query::caches::DefaultCache<rustc_span[c6e86278ee0bafba]::def_id::DefId, rustc_middle[28ddddcee064ee09]::query::erase::Erased<[u8; 8usize]>>>
  21:        0x110cd6964 - <rustc_middle[28ddddcee064ee09]::ty::context::TyCtxt>::instance_mir
  22:        0x10f601db8 - rustc_monomorphize[2a7d102951d99f0f]::collector::collect_neighbours
  23:        0x10f600d70 - rustc_monomorphize[2a7d102951d99f0f]::collector::collect_items_rec
  24:        0x10f601074 - rustc_monomorphize[2a7d102951d99f0f]::collector::collect_items_rec
  25:        0x10f6217b8 - <core[fa76fbc839568f1d]::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures[11d1296fd85ed732]::sync::par_for_each_in<alloc[699e0727aa91b95d]::vec::Vec<rustc_middle[28ddddcee064ee09]::mir::mono::MonoItem>, rustc_monomorphize[2a7d102951d99f0f]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>::{closure#0}::{closure#0}> as core[fa76fbc839568f1d]::ops::function::FnOnce<()>>::call_once
  26:        0x10f613ec4 - rustc_data_structures[11d1296fd85ed732]::sync::par_for_each_in::<alloc[699e0727aa91b95d]::vec::Vec<rustc_middle[28ddddcee064ee09]::mir::mono::MonoItem>, rustc_monomorphize[2a7d102951d99f0f]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>
  27:        0x10f61c9c8 - <rustc_session[5a840e94703f904]::session::Session>::time::<(), rustc_monomorphize[2a7d102951d99f0f]::collector::collect_crate_mono_items::{closure#1}>
  28:        0x10f5ff484 - rustc_monomorphize[2a7d102951d99f0f]::collector::collect_crate_mono_items
  29:        0x10f6116ac - rustc_monomorphize[2a7d102951d99f0f]::partitioning::collect_and_partition_mono_items
  30:        0x1101480d4 - rustc_query_system[c91188e96fcab682]::query::plumbing::try_execute_query::<rustc_query_impl[b54e71c67810b295]::queries::collect_and_partition_mono_items, rustc_query_impl[b54e71c67810b295]::plumbing::QueryCtxt>
  31:        0x1101f99c0 - rustc_query_impl[b54e71c67810b295]::get_query::collect_and_partition_mono_items
  32:        0x10cff2428 - rustc_codegen_ssa[f92b5776b52308c8]::base::codegen_crate::<rustc_codegen_llvm[13255e5f9e066824]::LlvmCodegenBackend>
  33:        0x10d044814 - <rustc_codegen_llvm[13255e5f9e066824]::LlvmCodegenBackend as rustc_codegen_ssa[f92b5776b52308c8]::traits::backend::CodegenBackend>::codegen_crate
  34:        0x10cfe5554 - rustc_interface[a675cf37ce06623c]::passes::start_codegen
  35:        0x10cf5dcd8 - <rustc_middle[28ddddcee064ee09]::ty::context::GlobalCtxt>::enter::<<rustc_interface[a675cf37ce06623c]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[fa76fbc839568f1d]::result::Result<alloc[699e0727aa91b95d]::boxed::Box<dyn core[fa76fbc839568f1d]::any::Any>, rustc_span[c6e86278ee0bafba]::ErrorGuaranteed>>
  36:        0x10cfe8b90 - <rustc_interface[a675cf37ce06623c]::queries::Queries>::ongoing_codegen
  37:        0x10cf11a2c - <rustc_interface[a675cf37ce06623c]::interface::Compiler>::enter::<rustc_driver_impl[57ad0c21a6a9d990]::run_compiler::{closure#1}::{closure#2}, core[fa76fbc839568f1d]::result::Result<core[fa76fbc839568f1d]::option::Option<rustc_interface[a675cf37ce06623c]::queries::Linker>, rustc_span[c6e86278ee0bafba]::ErrorGuaranteed>>
  38:        0x10ced9dac - std[8c9422f4eb635902]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[a675cf37ce06623c]::util::run_in_thread_pool_with_globals<rustc_interface[a675cf37ce06623c]::interface::run_compiler<core[fa76fbc839568f1d]::result::Result<(), rustc_span[c6e86278ee0bafba]::ErrorGuaranteed>, rustc_driver_impl[57ad0c21a6a9d990]::run_compiler::{closure#1}>::{closure#0}, core[fa76fbc839568f1d]::result::Result<(), rustc_span[c6e86278ee0bafba]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[fa76fbc839568f1d]::result::Result<(), rustc_span[c6e86278ee0bafba]::ErrorGuaranteed>>
  39:        0x10cedbbe4 - <<std[8c9422f4eb635902]::thread::Builder>::spawn_unchecked_<rustc_interface[a675cf37ce06623c]::util::run_in_thread_pool_with_globals<rustc_interface[a675cf37ce06623c]::interface::run_compiler<core[fa76fbc839568f1d]::result::Result<(), rustc_span[c6e86278ee0bafba]::ErrorGuaranteed>, rustc_driver_impl[57ad0c21a6a9d990]::run_compiler::{closure#1}>::{closure#0}, core[fa76fbc839568f1d]::result::Result<(), rustc_span[c6e86278ee0bafba]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[fa76fbc839568f1d]::result::Result<(), rustc_span[c6e86278ee0bafba]::ErrorGuaranteed>>::{closure#1} as core[fa76fbc839568f1d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  40:        0x104ae1290 - std::sys::unix::thread::Thread::new::thread_start::he87bdd6811d19cfc
  41:        0x1a89f7fa8 - __pthread_joiner_wake

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.71.0-nightly (25444e5a2 2023-05-10) running on aarch64-apple-darwin

note: compiler flags: -Z mir-opt-level=0 -Z mir-enable-passes=+ReferencePropagation

query stack during panic:
#0 [optimized_mir] optimizing MIR for `fn0`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack

This can only reproduced with Custom MIR as I do not find any way to make MIR building emit partial initialisations. Nonetheless I don't think it should break in this case.

cc @cjgillot

@cbeuw cbeuw added the C-bug Category: This is a bug. label May 10, 2023
@saethlin
Copy link
Member

FYI I think that this pattern is what we used to emit before #107267

@bors bors closed this as completed in 968911d May 11, 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants