Skip to content

Commit 4a76541

Browse files
authored
Rollup merge of #91577 - ecstatic-morse:mir-pass-manager-cleanup, r=oli-obk
Address some FIXMEs left over from #91475 This shouldn't change behavior, only clarify what we're currently doing. I filed #91576 to see if the treatment of generator drop shims is intentional. cc #91475
2 parents 87f2c51 + f04b8f2 commit 4a76541

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
480480
// FIXME(#70073): This pass is responsible for both optimization as well as some lints.
481481
&const_prop::ConstProp,
482482
//
483-
// FIXME: The old pass manager ran this only at mir-opt-level >= 1, but
484-
// const-prop runs unconditionally. Should this run unconditionally as well?
483+
// Const-prop runs unconditionally, but doesn't mutate the MIR at mir-opt-level=0.
485484
&o1(simplify_branches::SimplifyConstCondition::new("after-const-prop")),
486485
&early_otherwise_branch::EarlyOtherwiseBranch,
487486
&simplify_comparison_integral::SimplifyComparisonIntegral,

compiler/rustc_mir_transform/src/shim.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,19 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
6464

6565
build_call_shim(tcx, instance, Some(Adjustment::RefMut), CallKind::Direct(call_mut))
6666
}
67-
ty::InstanceDef::DropGlue(def_id, ty) => build_drop_shim(tcx, def_id, ty),
67+
68+
ty::InstanceDef::DropGlue(def_id, ty) => {
69+
// FIXME(#91576): Drop shims for generators aren't subject to the MIR passes at the end
70+
// of this function. Is this intentional?
71+
if let Some(ty::Generator(gen_def_id, substs, _)) = ty.map(ty::TyS::kind) {
72+
let body = tcx.optimized_mir(*gen_def_id).generator_drop().unwrap();
73+
let body = body.clone().subst(tcx, substs);
74+
debug!("make_shim({:?}) = {:?}", instance, body);
75+
return body;
76+
}
77+
78+
build_drop_shim(tcx, def_id, ty)
79+
}
6880
ty::InstanceDef::CloneShim(def_id, ty) => build_clone_shim(tcx, def_id, ty),
6981
ty::InstanceDef::Virtual(..) => {
7082
bug!("InstanceDef::Virtual ({:?}) is for direct calls only", instance)
@@ -75,14 +87,6 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
7587
};
7688
debug!("make_shim({:?}) = untransformed {:?}", instance, result);
7789

78-
// In some of the above cases, we seem to be invoking the passes for non-shim MIR bodies.
79-
// If that happens, there's no need to run them again.
80-
//
81-
// FIXME: Is this intentional?
82-
if result.phase >= MirPhase::Const {
83-
return result;
84-
}
85-
8690
pm::run_passes(
8791
tcx,
8892
&mut result,
@@ -140,11 +144,7 @@ fn local_decls_for_sig<'tcx>(
140144
fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>) -> Body<'tcx> {
141145
debug!("build_drop_shim(def_id={:?}, ty={:?})", def_id, ty);
142146

143-
// Check if this is a generator, if so, return the drop glue for it
144-
if let Some(&ty::Generator(gen_def_id, substs, _)) = ty.map(|ty| ty.kind()) {
145-
let body = tcx.optimized_mir(gen_def_id).generator_drop().unwrap();
146-
return body.clone().subst(tcx, substs);
147-
}
147+
assert!(!matches!(ty, Some(ty) if ty.is_generator()));
148148

149149
let substs = if let Some(ty) = ty {
150150
tcx.intern_substs(&[ty.into()])

0 commit comments

Comments
 (0)