Skip to content
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
9 changes: 5 additions & 4 deletions compiler/rustc_mir_dataflow/src/value_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ impl Map {
}

// Recurse with all fields of this place.
iter_fields(ty, tcx, |variant, field, ty| {
iter_fields(ty, tcx, ty::ParamEnv::reveal_all(), |variant, field, ty| {
if let Some(variant) = variant {
projection.push(PlaceElem::Downcast(None, variant));
let _ = self.make_place(local, projection);
Expand Down Expand Up @@ -939,6 +939,7 @@ impl<V, T> TryFrom<ProjectionElem<V, T>> for TrackElem {
pub fn iter_fields<'tcx>(
ty: Ty<'tcx>,
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
mut f: impl FnMut(Option<VariantIdx>, Field, Ty<'tcx>),
) {
match ty.kind() {
Expand All @@ -956,14 +957,14 @@ pub fn iter_fields<'tcx>(
for (f_index, f_def) in v_def.fields.iter().enumerate() {
let field_ty = f_def.ty(tcx, substs);
let field_ty = tcx
.try_normalize_erasing_regions(ty::ParamEnv::reveal_all(), field_ty)
.unwrap_or(field_ty);
.try_normalize_erasing_regions(param_env, field_ty)
.unwrap_or_else(|_| tcx.erase_regions(field_ty));
f(variant, f_index.into(), field_ty);
}
}
}
ty::Closure(_, substs) => {
iter_fields(substs.as_closure().tupled_upvars_ty(), tcx, f);
iter_fields(substs.as_closure().tupled_upvars_ty(), tcx, param_env, f);
}
_ => (),
}
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_mir_transform/src/sroa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_index::vec::IndexVec;
use rustc_middle::mir::patch::MirPatch;
use rustc_middle::mir::visit::*;
use rustc_middle::mir::*;
use rustc_middle::ty::{Ty, TyCtxt};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_mir_dataflow::value_analysis::{excluded_locals, iter_fields};

pub struct ScalarReplacementOfAggregates;
Expand All @@ -18,11 +18,12 @@ impl<'tcx> MirPass<'tcx> for ScalarReplacementOfAggregates {
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
debug!(def_id = ?body.source.def_id());
let mut excluded = excluded_locals(body);
let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id());
loop {
debug!(?excluded);
let escaping = escaping_locals(&excluded, body);
debug!(?escaping);
let replacements = compute_flattening(tcx, body, escaping);
let replacements = compute_flattening(tcx, param_env, body, escaping);
debug!(?replacements);
let all_dead_locals = replace_flattened_locals(tcx, body, replacements);
if !all_dead_locals.is_empty() {
Expand Down Expand Up @@ -144,6 +145,7 @@ impl<'tcx> ReplacementMap<'tcx> {
/// The replacement will be done later in `ReplacementVisitor`.
fn compute_flattening<'tcx>(
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
body: &mut Body<'tcx>,
escaping: BitSet<Local>,
) -> ReplacementMap<'tcx> {
Expand All @@ -155,7 +157,7 @@ fn compute_flattening<'tcx>(
}
let decl = body.local_decls[local].clone();
let ty = decl.ty;
iter_fields(ty, tcx, |variant, field, field_ty| {
iter_fields(ty, tcx, param_env, |variant, field, field_ty| {
if variant.is_some() {
// Downcasts are currently not supported.
return;
Expand Down
46 changes: 0 additions & 46 deletions tests/mir-opt/sroa.constant.ScalarReplacementOfAggregates.diff

This file was deleted.

91 changes: 0 additions & 91 deletions tests/mir-opt/sroa.copies.ScalarReplacementOfAggregates.diff

This file was deleted.

44 changes: 0 additions & 44 deletions tests/mir-opt/sroa.dropping.ScalarReplacementOfAggregates.diff

This file was deleted.

43 changes: 0 additions & 43 deletions tests/mir-opt/sroa.enums.ScalarReplacementOfAggregates.diff

This file was deleted.

44 changes: 0 additions & 44 deletions tests/mir-opt/sroa.escaping.ScalarReplacementOfAggregates.diff

This file was deleted.

Loading