Skip to content

Commit

Permalink
Don't inline drop shims with unsubstituted generic consts in MIR inliner
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jun 28, 2024
1 parent 90c2b23 commit f17b27b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 262 deletions.
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
5 changes: 1 addition & 4 deletions tests/ui/const-generics/polymorphic-drop-shim.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//@ compile-flags: -Zinline-mir=yes --crate-type=lib

//@ known-bug: unknown
//@ build-fail
//@ failure-status: 101
//@ build-pass

use std::mem::ManuallyDrop;

Expand Down
Loading

0 comments on commit f17b27b

Please sign in to comment.