Skip to content

Commit ac4379f

Browse files
committed
Auto merge of #108787 - cjgillot:sroa-lifetime, r=compiler-errors
Erase regions even when failing to normalize type in MIR opts The first commit just moves the tests around. Fixes #108720 cc `@saethlin`
2 parents 8c0f83d + 708536b commit ac4379f

23 files changed

+730
-476
lines changed

Diff for: compiler/rustc_mir_dataflow/src/value_analysis.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ impl Map {
690690
}
691691

692692
// Recurse with all fields of this place.
693-
iter_fields(ty, tcx, |variant, field, ty| {
693+
iter_fields(ty, tcx, ty::ParamEnv::reveal_all(), |variant, field, ty| {
694694
if let Some(variant) = variant {
695695
projection.push(PlaceElem::Downcast(None, variant));
696696
let _ = self.make_place(local, projection);
@@ -939,6 +939,7 @@ impl<V, T> TryFrom<ProjectionElem<V, T>> for TrackElem {
939939
pub fn iter_fields<'tcx>(
940940
ty: Ty<'tcx>,
941941
tcx: TyCtxt<'tcx>,
942+
param_env: ty::ParamEnv<'tcx>,
942943
mut f: impl FnMut(Option<VariantIdx>, Field, Ty<'tcx>),
943944
) {
944945
match ty.kind() {
@@ -956,14 +957,14 @@ pub fn iter_fields<'tcx>(
956957
for (f_index, f_def) in v_def.fields.iter().enumerate() {
957958
let field_ty = f_def.ty(tcx, substs);
958959
let field_ty = tcx
959-
.try_normalize_erasing_regions(ty::ParamEnv::reveal_all(), field_ty)
960-
.unwrap_or(field_ty);
960+
.try_normalize_erasing_regions(param_env, field_ty)
961+
.unwrap_or_else(|_| tcx.erase_regions(field_ty));
961962
f(variant, f_index.into(), field_ty);
962963
}
963964
}
964965
}
965966
ty::Closure(_, substs) => {
966-
iter_fields(substs.as_closure().tupled_upvars_ty(), tcx, f);
967+
iter_fields(substs.as_closure().tupled_upvars_ty(), tcx, param_env, f);
967968
}
968969
_ => (),
969970
}

Diff for: compiler/rustc_mir_transform/src/sroa.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_index::vec::IndexVec;
44
use rustc_middle::mir::patch::MirPatch;
55
use rustc_middle::mir::visit::*;
66
use rustc_middle::mir::*;
7-
use rustc_middle::ty::{Ty, TyCtxt};
7+
use rustc_middle::ty::{self, Ty, TyCtxt};
88
use rustc_mir_dataflow::value_analysis::{excluded_locals, iter_fields};
99

1010
pub struct ScalarReplacementOfAggregates;
@@ -18,11 +18,12 @@ impl<'tcx> MirPass<'tcx> for ScalarReplacementOfAggregates {
1818
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
1919
debug!(def_id = ?body.source.def_id());
2020
let mut excluded = excluded_locals(body);
21+
let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id());
2122
loop {
2223
debug!(?excluded);
2324
let escaping = escaping_locals(&excluded, body);
2425
debug!(?escaping);
25-
let replacements = compute_flattening(tcx, body, escaping);
26+
let replacements = compute_flattening(tcx, param_env, body, escaping);
2627
debug!(?replacements);
2728
let all_dead_locals = replace_flattened_locals(tcx, body, replacements);
2829
if !all_dead_locals.is_empty() {
@@ -144,6 +145,7 @@ impl<'tcx> ReplacementMap<'tcx> {
144145
/// The replacement will be done later in `ReplacementVisitor`.
145146
fn compute_flattening<'tcx>(
146147
tcx: TyCtxt<'tcx>,
148+
param_env: ty::ParamEnv<'tcx>,
147149
body: &mut Body<'tcx>,
148150
escaping: BitSet<Local>,
149151
) -> ReplacementMap<'tcx> {
@@ -155,7 +157,7 @@ fn compute_flattening<'tcx>(
155157
}
156158
let decl = body.local_decls[local].clone();
157159
let ty = decl.ty;
158-
iter_fields(ty, tcx, |variant, field, field_ty| {
160+
iter_fields(ty, tcx, param_env, |variant, field, field_ty| {
159161
if variant.is_some() {
160162
// Downcasts are currently not supported.
161163
return;

Diff for: tests/mir-opt/sroa.constant.ScalarReplacementOfAggregates.diff

-46
This file was deleted.

Diff for: tests/mir-opt/sroa.copies.ScalarReplacementOfAggregates.diff

-91
This file was deleted.

Diff for: tests/mir-opt/sroa.dropping.ScalarReplacementOfAggregates.diff

-44
This file was deleted.

Diff for: tests/mir-opt/sroa.enums.ScalarReplacementOfAggregates.diff

-43
This file was deleted.

Diff for: tests/mir-opt/sroa.escaping.ScalarReplacementOfAggregates.diff

-44
This file was deleted.

0 commit comments

Comments
 (0)