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

Stall computing instance for drop shim until it has no unsubstituted const params #127068

Merged
merged 2 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}
use rustc_middle::mir::visit::*;
use rustc_middle::mir::*;
use rustc_middle::ty::TypeVisitableExt;
use rustc_middle::ty::{self, Instance, InstanceKind, ParamEnv, Ty, TyCtxt};
use rustc_middle::ty::{self, Instance, InstanceKind, ParamEnv, Ty, TyCtxt, TypeFlags};
use rustc_session::config::{DebugInfo, OptLevel};
use rustc_span::source_map::Spanned;
use rustc_span::sym;
Expand Down Expand Up @@ -306,6 +306,16 @@ impl<'tcx> Inliner<'tcx> {
InstanceKind::Intrinsic(_) | InstanceKind::Virtual(..) => {
return Err("instance without MIR (intrinsic / virtual)");
}

// FIXME(#127030): `ConstParamHasTy` has bad interactions with
// the drop shim builder, which does not evaluate predicates in
// the correct param-env for types being dropped. Stall resolving
// the MIR for this instance until all of its const params are
// substituted.
InstanceKind::DropGlue(_, Some(ty)) if ty.has_type_flags(TypeFlags::HAS_CT_PARAM) => {
return Err("still needs substitution");
}

// This cannot result in an immediate cycle since the callee MIR is a shim, which does
// not get any optimizations run on it. Any subsequent inlining may cause cycles, but we
// do not need to catch this here, we can wait until the inliner decides to continue
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/const-generics/polymorphic-drop-shim.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//@ compile-flags: -Zinline-mir=yes --crate-type=lib
//@ build-pass

use std::mem::ManuallyDrop;

pub struct Foo<T, const N: usize>([T; N]);

pub struct Dorp {}

impl Drop for Dorp {
fn drop(&mut self) {}
}

#[inline]
// SAFETY: call this with a valid allocation idk
pub unsafe fn drop<const M: usize>(x: *mut Foo<Dorp, M>) {
std::ptr::drop_in_place(x);
}
Loading