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: broken mir while building rustc #114375

Closed
matthiaskrgr opened this issue Aug 2, 2023 · 13 comments · Fixed by #115005
Closed

ICE: broken mir while building rustc #114375

matthiaskrgr opened this issue Aug 2, 2023 · 13 comments · Fixed by #115005
Labels
C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-critical Critical priority requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

Code

rustc -Zvalidate-mir file.rs

#![feature(rustc_private)]

extern crate rustc_parse;
extern crate rustc_session;
extern crate rustc_span;

extern crate rustc_driver;

use rustc_session::parse::ParseSess;
use rustc_span::source_map::FilePathMapping;

fn main() {
    rustc_span::create_default_session_globals_then(|| run());
}

fn run() {
    let ps = ParseSess::new(
        vec![rustc_parse::DEFAULT_LOCALE_RESOURCE],
        FilePathMapping::empty(),
    );
}

Meta

rustc --version --verbose:

rustc 1.73.0-nightly (d12c6e947 2023-08-01)
binary: rustc
commit-hash: d12c6e947ceacf3b22c154caf9532b390d8dc88a
commit-date: 2023-08-01
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5

Error output

<output>

Not posting the entire 1.7K lines backtrace 🙃

Backtrace

warning: unused variable: `ps`
  --> treereduce.out:19:9
   |
19 |     let ps = ParseSess::new(
   |         ^^ help: if this is intentional, prefix it with an underscore: `_ps`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: broken MIR in DropGlue(DefId(2:2152 ~ core[9b2a]::ptr::drop_in_place), Some(std::backtrace::Inner)) (before pass AddMovesFor>
                                Field projection `PlaceRef { local: _1, projection: [Deref, Downcast(Some("Captured"), 2)] }.0` specified type `std::sync::L>
   --> /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:497:1
    |
497 | pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: delayed at compiler/rustc_const_eval/src/transform/validate.rs:76:25
         0: <rustc_errors::HandlerInner>::emit_diagnostic
         1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
         2: <rustc_const_eval::transform::validate::CfgChecker>::fail::<alloc::string::String>
         3: <rustc_const_eval::transform::validate::Validator as rustc_middle::mir::MirPass>::run_pass
         4: rustc_mir_transform::pass_manager::validate_body
         5: rustc_mir_transform::pass_manager::run_passes
         6: rustc_mir_transform::shim::make_shim
         7: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_shims::dynamic_query::{closure#2}::{closure#0}, rus>
         8: <rustc_query_impl::query_impl::mir_shims::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_mi>
         9: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_m>
        10: rustc_query_impl::query_impl::mir_shims::get_query_non_incr::__rust_end_short_backtrace
        11: <rustc_middle::ty::context::TyCtxt>::instance_mir
        12: rustc_monomorphize::collector::collect_used_items
        13: rustc_monomorphize::collector::collect_items_rec
        14: rustc_monomorphize::collector::collect_items_rec
        15: rustc_monomorphize::collector::collect_items_rec
        16: rustc_monomorphize::collector::collect_items_rec
        17: rustc_monomorphize::collector::collect_items_rec
        18: rustc_monomorphize::collector::collect_items_rec
        19: rustc_monomorphize::collector::collect_items_rec
        20: rustc_monomorphize::collector::collect_items_rec
        21: rustc_monomorphize::collector::collect_items_rec
        22: rustc_monomorphize::collector::collect_items_rec
        23: rustc_monomorphize::collector::collect_items_rec
        24: rustc_monomorphize::collector::collect_items_rec
        25: rustc_monomorphize::collector::collect_items_rec
        26: rustc_monomorphize::collector::collect_items_rec
        27: rustc_monomorphize::collector::collect_items_rec
        28: rustc_monomorphize::collector::collect_items_rec
        29: rustc_monomorphize::collector::collect_items_rec
        30: rustc_monomorphize::collector::collect_items_rec
        31: rustc_data_structures::sync::par_for_each_in::<alloc::vec::Vec<rustc_middle::mir::mono::MonoItem>, rustc_monomorphize::collector::collect_crate_>
        32: <rustc_session::session::Session>::time::<(), rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}>
        33: rustc_monomorphize::collector::collect_crate_mono_items
        34: rustc_monomorphize::partitioning::collect_and_partition_mono_items
        35: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::collect_and_partition_mono_items::dynamic_query::{closu>
        36: <rustc_query_impl::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::co>
        37: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_mi>
        38: rustc_query_impl::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
        39: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend>
        40: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
        41: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
        42: rustc_interface::passes::start_codegen
        43: <rustc_middle::ty::context::GlobalCtxt>::enter::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}, core::result::Result<alloc::>
        44: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Op>
        45: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::ru>
        46: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::>
        47: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/d12c6e947ceacf3b22c154caf9532b390d8dc88a/library/alloc/src/boxed.rs:2007:9
        48: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/d12c6e947ceacf3b22c154caf9532b390d8dc88a/library/alloc/src/boxed.rs:2007:9
        49: std::sys::unix::thread::Thread::new::thread_start
                   at /rustc/d12c6e947ceacf3b22c154caf9532b390d8dc88a/library/std/src/sys/unix/thread.rs:108:17
        50: <unknown>
        51: <unknown>
   --> /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:497:1
    |
497 | pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: broken MIR in DropGlue(DefId(2:2152 ~ core[9b2a]::ptr::drop_in_place), Some(std::backtrace::Inner)) (before pass AddMovesFor>
                                Field projection `PlaceRef { local: _1, projection: [Deref, Downcast(Some("Captured"), 2)] }.0` specified type `std::sync::L>
lines 42-82
        21: rustc_monomorphize::collector::collect_items_rec
        22: rustc_monomorphize::collector::collect_items_rec
        23: rustc_monomorphize::collector::collect_items_rec
        24: rustc_monomorphize::collector::collect_items_rec
        25: rustc_monomorphize::collector::collect_items_rec
        26: rustc_monomorphize::collector::collect_items_rec
        27: rustc_monomorphize::collector::collect_items_rec
        28: rustc_monomorphize::collector::collect_items_rec
        29: rustc_monomorphize::collector::collect_items_rec
        30: rustc_monomorphize::collector::collect_items_rec
        31: rustc_data_structures::sync::par_for_each_in::<alloc::vec::Vec<rustc_middle::mir::mono::MonoItem>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure#0}>
        32: <rustc_session::session::Session>::time::<(), rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}>
        33: rustc_monomorphize::collector::collect_crate_mono_items
        34: rustc_monomorphize::partitioning::collect_and_partition_mono_items
        35: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 24]>>
        36: <rustc_query_impl::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, ())>>::call_once
        37: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 24]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        38: rustc_query_impl::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
        39: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend>
        40: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
        41: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
        42: rustc_interface::passes::start_codegen
        43: <rustc_middle::ty::context::GlobalCtxt>::enter::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}, core::result::Result<alloc::boxed::Box<dyn core::any::Any>, rustc_span::ErrorGuaranteed>>
        44: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
        45: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span:>
        46: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        47: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/d12c6e947ceacf3b22c154caf9532b390d8dc88a/library/alloc/src/boxed.rs:2007:9
        48: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/d12c6e947ceacf3b22c154caf9532b390d8dc88a/library/alloc/src/boxed.rs:2007:9
        49: std::sys::unix::thread::Thread::new::thread_start
                   at /rustc/d12c6e947ceacf3b22c154caf9532b390d8dc88a/library/std/src/sys/unix/thread.rs:108:17
        50: <unknown>
        51: <unknown>
   --> /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:497:1
    |
497 | pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: broken MIR in DropGlue(DefId(2:2152 ~ core[9b2a]::ptr::drop_in_place), Some(std::backtrace::Inner)) (before pass AddMovesForPackedDrops) at bb5[0]:
                                Field projection `PlaceRef { local: _1, projection: [Deref, Downcast(Some("Captured"), 2)] }.0` specified type `std::sync::LazyLock<std::backtrace::Capture, [closure@std::backtrace::lazy_resolve::{closure#0}]>`, but actual type is `std::sync::LazyLock<std::backtrace::Capture, std::back>
   --> /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:497:1
    |
497 | pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: delayed at compiler/rustc_const_eval/src/transform/validate.rs:76:25
         0: <rustc_errors::HandlerInner>::emit_diagnostic
         1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
         2: <rustc_const_eval::transform::validate::CfgChecker>::fail::<alloc::string::String>
         3: <rustc_const_eval::transform::validate::Validator as rustc_middle::mir::MirPass>::run_pass
         4: rustc_mir_transform::pass_manager::validate_body
         5: rustc_mir_transform::pass_manager::run_passes
         6: rustc_mir_transform::shim::make_shim
         7: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_shims::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
         8: <rustc_query_impl::query_impl::mir_shims::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_middle::ty::instance::InstanceDef)>>::call_once
         9: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::instance::InstanceDef, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        10: rustc_query_impl::query_impl::mir_shims::get_query_non_incr::__rust_end_short_backtrace
        11: <rustc_middle::ty::context::TyCtxt>::instance_mir
        12: rustc_monomorphize::collector::collect_used_items
        13: rustc_monomorphize::collector::collect_items_rec
        14: rustc_monomorphize::collector::collect_items_rec
        15: rustc_monomorphize::collector::collect_items_rec
        16: rustc_monomorphize::collector::collect_items_rec
        17: rustc_monomorphize::collector::collect_items_rec
        18: rustc_monomorphize::collector::collect_items_rec
        19: rustc_monomorphize::collector::collect_items_rec
        20: rustc_monomorphize::collector::collect_items_rec
        21: rustc_monomorphize::collector::collect_items_rec
        22: rustc_monomorphize::collector::collect_items_rec
        23: rustc_monomorphize::collector::collect_items_rec
        24: rustc_monomorphize::collector::collect_items_rec
        25: rustc_monomorphize::collector::collect_items_rec
        26: rustc_monomorphize::collector::collect_items_rec
        27: rustc_monomorphize::collector::collect_items_rec
        28: rustc_monomorphize::collector::collect_items_rec
        29: rustc_monomorphize::collector::collect_items_rec
        30: rustc_monomorphize::collector::collect_items_rec
        31: rustc_data_structures::sync::par_for_each_in::<alloc::vec::Vec<rustc_middle::mir::mono::MonoItem>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure#0}>
        32: <rustc_session::session::Session>::time::<(), rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}>
        33: rustc_monomorphize::collector::collect_crate_mono_items
        34: rustc_monomorphize::partitioning::collect_and_partition_mono_items
        35: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 24]>>
        36: <rustc_query_impl::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, ())>>::call_once
        37: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 24]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        38: rustc_query_impl::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
        39: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend>
        40: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
        41: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
        42: rustc_interface::passes::start_codegen
        43: <rustc_middle::ty::context::GlobalCtxt>::enter::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}, core::result::Result<alloc::boxed::Box<dyn core::any::Any>, rustc_span::ErrorGuaranteed>>
        44: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
        45: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span:>
        46: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        47: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/d12c6e947ceacf3b22c154caf9532b390d8dc88a/library/alloc/src/boxed.rs:2007:9
        48: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/d12c6e947ceacf3b22c154caf9532b390d8dc88a/library/alloc/src/boxed.rs:2007:9
        49: std::sys::unix::thread::Thread::new::thread_start
                   at /rustc/d12c6e947ceacf3b22c154caf9532b390d8dc88a/library/std/src/sys/unix/thread.rs:108:17
        50: <unknown>
        51: <unknown>
   --> /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:497:1
    |
497 | pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@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. labels Aug 2, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 2, 2023
@matthiaskrgr
Copy link
Member Author

You can also reproduce this in the rustc repo itself where

Building compiler artifacts (stage0 -> stage1, x86_64-unknown-linux-gnu)
   Compiling rustc_errors v0.0.0 (/home/matthias/vcs/github/rust/compiler/rustc_errors)
    Building [==============>          ] 206/322: rustc_errors

will encounter the error with
RUSTFLAGS="-Zverify-llvm-ir=true -Zvalidate-mir" RUSTC_BOOTSTRAP=1 ./x.py build

@lukas-code
Copy link
Contributor

lukas-code commented Aug 2, 2023

Reduced:

// crate foo

#![feature(type_alias_impl_trait)]

type Tait = impl Sized;
fn _constrain() -> Tait {}

struct WrapperWithDrop<T>(T);
impl<T> Drop for WrapperWithDrop<T> {
    fn drop(&mut self) {}
}

pub struct Foo(WrapperWithDrop<Tait>);
// crate bar

pub fn drop_foo(_: foo::Foo) {}
cargo rustc -p bar -- -Z validate-mir

@rustbot label F-type_alias_impl_trait

@rustbot rustbot added the F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` label Aug 2, 2023
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 3, 2023
@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Aug 5, 2023

Found another repro I think:

use std::backtrace::Backtrace;

const _: fn() = || {
    let backtrace: Backtrace = Backtrace::capture();
};

this one bisects to #109075

@matthiaskrgr
Copy link
Member Author

pub fn foo() {
    std::backtrace::Backtrace::force_capture();
}

@matthiaskrgr
Copy link
Member Author

@rustbot prioritize

@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Aug 18, 2023
@apiraino
Copy link
Contributor

going to also link #107440 and #107228 as other reports of the same issue

@apiraino
Copy link
Contributor

apiraino commented Aug 18, 2023

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Aug 18, 2023
@apiraino
Copy link
Contributor

apiraino commented Aug 18, 2023

Ok, after a bit more back ond forth on Zulip, I'm tentatively bumping this issue to P-critical and raise these questions (echoing the comments from the discussion):

Next week Rust 1.72 will be released, artifacts are going to be build real soon, I think.

Thanks for additional comments to help improve my understanding of the context here.

@rustbot label -P-medium +P-critical

@rustbot rustbot added P-critical Critical priority and removed P-medium Medium priority labels Aug 18, 2023
@joboet
Copy link
Contributor

joboet commented Aug 18, 2023

The underlying issue here is an issue with TAIT. #109075 was an implementation-only change simplifying some backtrace code in std that was made under the assumption that TAIT was reliable enough to be used inside std. As it is not user-facing it should be easily revertible. So the question here is whether it is safer to get TAIT working (potentially by reverting #112777?) so it can be used internally or to just hold off on using it until the issue has been resolved, reapplying #109075 once that happens.

I have no compiler experience, but my initial hunch would be that the library change is preferable for now. I'll get a PR ready until tomorrow, unless someone beats me to it.

@wesleywiser wesleywiser added requires-nightly This issue requires a nightly compiler in some way. I-compiler-nominated The issue / PR has been nominated for discussion during a compiler team meeting. labels Aug 18, 2023
@compiler-errors compiler-errors added requires-nightly This issue requires a nightly compiler in some way. and removed requires-nightly This issue requires a nightly compiler in some way. labels Aug 18, 2023
@compiler-errors
Copy link
Member

#112777 should not be reverted. All it does is cause us to now eagerly reveal opaques that were being skipped over during normalization, which means that we're just not hitting this code anymore:

if (src, dest).has_opaque_types() {
return true;
}

It does not introduce a bug, it just reveals one that already existed.


I'm gonna use the minimized example (#114375 (comment)) here. What's happening here is that we're generating a drop shim for foo::Foo that looks like:

fn std::ptr::drop_in_place(_1: *mut Foo) -> () {
    let mut _0: ();

    bb0: {
        goto -> bb5;
    }

    bb1: {
        return;
    }

    bb2 (cleanup): {
        resume;
    }

    bb3: {
        goto -> bb1;
    }

    bb4 (cleanup): {
        drop(((*_1).0: foo::WrapperWithDrop<()>)) -> [return: bb2, unwind terminate];
    }

    bb5: {
        drop(((*_1).0: foo::WrapperWithDrop<()>)) -> [return: bb3, unwind: bb2];
    }
}

which then tries to validate that (*_1).0: foo::WrapperWithDrop<()>. However, it has type foo::WrapperWithDrop<Tait>, where Tait is a ty::Weak, which does not hit the has_opaque_types code I linked above.

Before #112777, we'd emit something that looks like:

fn std::ptr::drop_in_place(_1: *mut Foo) -> () {
    let mut _0: ();

    bb0: {
        goto -> bb5;
    }

    bb1: {
        return;
    }

    bb2 (cleanup): {
        resume;
    }

    bb3: {
        goto -> bb1;
    }

    bb4 (cleanup): {
        drop(((*_1).0: foo::WrapperWithDrop<Tait::{opaque#0}>)) -> [return: bb2, unwind terminate];
    }

    bb5: {
        drop(((*_1).0: foo::WrapperWithDrop<Tait::{opaque#0}>)) -> [return: bb3, unwind: bb2];
    }
}

which is a field that is incompletely normalized, but does hit the has_opaque_types code above.

@joboet
Copy link
Contributor

joboet commented Aug 19, 2023

Submitted the PR reverting #109075: #114988.

@compiler-errors
Copy link
Member

#115005 fixes this issue by not considering mir validity on shims until they have been optimized, which uses the reveal-all param-env for that shim.

This ICE shouldn't be possible to trigger without -Zvalidate-mir, since it has to do with one of the intra-pass mir validations that are only done when that flag is active:

if validate {
validate_body(tcx, body, format!("before pass {name}"));
}

I don't personally think that #114988 needs to be reverted, either.

@compiler-errors
Copy link
Member

This was also possible to trigger even before #112777 using an associated type. The test in #115005 exercises this too.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 22, 2023
Don't do intra-pass validation on MIR shims

Fixes rust-lang#114375

In the test that was committed, we end up generating the drop shim for `struct Foo` that looks like:

```
fn std::ptr::drop_in_place(_1: *mut Foo) -> () {
    let mut _0: ();

    bb0: {
        goto -> bb5;
    }

    bb1: {
        return;
    }

    bb2 (cleanup): {
        resume;
    }

    bb3: {
        goto -> bb1;
    }

    bb4 (cleanup): {
        drop(((*_1).0: foo::WrapperWithDrop<()>)) -> [return: bb2, unwind terminate];
    }

    bb5: {
        drop(((*_1).0: foo::WrapperWithDrop<()>)) -> [return: bb3, unwind: bb2];
    }
}
```

In `bb4` and `bb5`, we assert that `(*_1).0` has type `WrapperWithDrop<()>`. However, In a user-facing param env, the type is actually `WrapperWithDrop<Tait>`. These types are not equal in a user-facing param-env (and can't be made equal even if we use `DefiningAnchor::Bubble`, since it's a non-local TAIT).
@bors bors closed this as completed in c469197 Aug 22, 2023
@wesleywiser wesleywiser removed the I-compiler-nominated The issue / PR has been nominated for discussion during a compiler team meeting. label Aug 24, 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. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-critical Critical priority requires-nightly This issue requires a nightly compiler in some way. 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.

8 participants