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
(cherry picked from commit f17b27b)
  • Loading branch information
compiler-errors authored and cuviper committed Jul 5, 2024
1 parent e1f26a6 commit bb45867
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 @@ -10,7 +10,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, InstanceDef, ParamEnv, Ty, TyCtxt};
use rustc_middle::ty::{self, Instance, InstanceDef, ParamEnv, Ty, TyCtxt, TypeFlags};
use rustc_session::config::{DebugInfo, OptLevel};
use rustc_span::source_map::Spanned;
use rustc_span::sym;
Expand Down Expand Up @@ -320,6 +320,16 @@ impl<'tcx> Inliner<'tcx> {
InstanceDef::Intrinsic(_) | InstanceDef::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.
InstanceDef::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 bb45867

Please sign in to comment.