Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d1ff5aa

Browse files
authoredJun 29, 2024
Unrolled build for rust-lang#127068
Rollup merge of rust-lang#127068 - compiler-errors:stall-drop, r=BoxyUwU Stall computing instance for drop shim until it has no unsubstituted const params Do not inline the drop shim for types that still have unsubstituted const params. ## Why? rust-lang#127030 ICEs because it tries to inline the drop shim for a type with an unsubstituted const param. In order to generate this shim, this requires calling the drop shim builder, which invokes the trait solver to compute whether constituent types need drop (since we compute if a type is copy to disqualify any `Drop` behavior): https://github.com/rust-lang/rust/blob/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/compiler/rustc_mir_dataflow/src/elaborate_drops.rs#L378 However, since we don't keep the param-env of the instance we resolved the item for, we use the wrong param-env: https://github.com/rust-lang/rust/blob/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/compiler/rustc_mir_transform/src/shim.rs#L278 (which is the param-env of `std::ptr::drop_in_place`) This param-env is notably missing `ConstParamHasTy` predicates, and since we removed the type from consts in rust-lang#125958, we literally cannot prove these predicates in this (relatively) empty param-env. This currently happens in places like the MIR inliner, but may happen elsewhere such as in lints that resolve terminators. ## What? We force the inliner to not consider calls for `drop_in_place` for types that have unsubstituted const params. ## So what? This may negatively affect MIR inlining, but I doubt this matters in practice, and fixes a beta regression, so let's fix it. I will look into approaches for fixing this in a more maintainable way, perhaps delaying the creation of drop shim bodies until codegen (like how intrinsics work).
2 parents 9ed2ab3 + f17b27b commit d1ff5aa

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed
 

‎compiler/rustc_mir_transform/src/inline.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}
1111
use rustc_middle::mir::visit::*;
1212
use rustc_middle::mir::*;
1313
use rustc_middle::ty::TypeVisitableExt;
14-
use rustc_middle::ty::{self, Instance, InstanceKind, ParamEnv, Ty, TyCtxt};
14+
use rustc_middle::ty::{self, Instance, InstanceKind, ParamEnv, Ty, TyCtxt, TypeFlags};
1515
use rustc_session::config::{DebugInfo, OptLevel};
1616
use rustc_span::source_map::Spanned;
1717
use rustc_span::sym;
@@ -306,6 +306,16 @@ impl<'tcx> Inliner<'tcx> {
306306
InstanceKind::Intrinsic(_) | InstanceKind::Virtual(..) => {
307307
return Err("instance without MIR (intrinsic / virtual)");
308308
}
309+
310+
// FIXME(#127030): `ConstParamHasTy` has bad interactions with
311+
// the drop shim builder, which does not evaluate predicates in
312+
// the correct param-env for types being dropped. Stall resolving
313+
// the MIR for this instance until all of its const params are
314+
// substituted.
315+
InstanceKind::DropGlue(_, Some(ty)) if ty.has_type_flags(TypeFlags::HAS_CT_PARAM) => {
316+
return Err("still needs substitution");
317+
}
318+
309319
// This cannot result in an immediate cycle since the callee MIR is a shim, which does
310320
// not get any optimizations run on it. Any subsequent inlining may cause cycles, but we
311321
// do not need to catch this here, we can wait until the inliner decides to continue
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ compile-flags: -Zinline-mir=yes --crate-type=lib
2+
//@ build-pass
3+
4+
use std::mem::ManuallyDrop;
5+
6+
pub struct Foo<T, const N: usize>([T; N]);
7+
8+
pub struct Dorp {}
9+
10+
impl Drop for Dorp {
11+
fn drop(&mut self) {}
12+
}
13+
14+
#[inline]
15+
// SAFETY: call this with a valid allocation idk
16+
pub unsafe fn drop<const M: usize>(x: *mut Foo<Dorp, M>) {
17+
std::ptr::drop_in_place(x);
18+
}

0 commit comments

Comments
 (0)
Failed to load comments.