Rollup merge of #109716 - scottmcm:field-to-fieldidx, r=oli-obk
Move `mir::Field` → `abi::FieldIdx` The first PR for https://github.com/rust-lang/compiler-team/issues/606 This is just the move-and-rename, because it's plenty big already. Future PRs will start using `FieldIdx` more broadly, and concomitantly removing `FieldIdx::new`s.
This commit is contained in:
commit
85c38454c0
46 changed files with 192 additions and 157 deletions
|
@ -13,8 +13,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
|
|||
use rustc_mir_dataflow::value_analysis::{Map, State, TrackElem, ValueAnalysis, ValueOrPlace};
|
||||
use rustc_mir_dataflow::{lattice::FlatSet, Analysis, ResultsVisitor, SwitchIntEdgeEffects};
|
||||
use rustc_span::DUMMY_SP;
|
||||
use rustc_target::abi::Align;
|
||||
use rustc_target::abi::VariantIdx;
|
||||
use rustc_target::abi::{Align, FieldIdx, VariantIdx};
|
||||
|
||||
use crate::MirPass;
|
||||
|
||||
|
@ -148,7 +147,7 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
|
|||
for (field_index, operand) in operands.iter().enumerate() {
|
||||
if let Some(field) = self.map().apply(
|
||||
variant_target_idx,
|
||||
TrackElem::Field(Field::from_usize(field_index)),
|
||||
TrackElem::Field(FieldIdx::from_usize(field_index)),
|
||||
) {
|
||||
let result = self.handle_operand(operand, state);
|
||||
state.insert_idx(field, result, self.map());
|
||||
|
|
|
@ -9,6 +9,7 @@ use rustc_middle::mir::patch::MirPatch;
|
|||
use rustc_middle::mir::visit::MutVisitor;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::{Ty, TyCtxt};
|
||||
use rustc_target::abi::FieldIdx;
|
||||
|
||||
/// Constructs the types used when accessing a Box's pointer
|
||||
pub fn build_ptr_tys<'tcx>(
|
||||
|
@ -32,9 +33,9 @@ pub fn build_projection<'tcx>(
|
|||
ptr_ty: Ty<'tcx>,
|
||||
) -> [PlaceElem<'tcx>; 3] {
|
||||
[
|
||||
PlaceElem::Field(Field::new(0), unique_ty),
|
||||
PlaceElem::Field(Field::new(0), nonnull_ty),
|
||||
PlaceElem::Field(Field::new(0), ptr_ty),
|
||||
PlaceElem::Field(FieldIdx::new(0), unique_ty),
|
||||
PlaceElem::Field(FieldIdx::new(0), nonnull_ty),
|
||||
PlaceElem::Field(FieldIdx::new(0), ptr_ty),
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ use rustc_mir_dataflow::MoveDataParamEnv;
|
|||
use rustc_mir_dataflow::{on_all_children_bits, on_all_drop_children_bits};
|
||||
use rustc_mir_dataflow::{Analysis, ResultsCursor};
|
||||
use rustc_span::{DesugaringKind, Span};
|
||||
use rustc_target::abi::VariantIdx;
|
||||
use rustc_target::abi::{FieldIdx, VariantIdx};
|
||||
use std::fmt;
|
||||
|
||||
/// During MIR building, Drop terminators are inserted in every place where a drop may occur.
|
||||
|
@ -252,7 +252,7 @@ impl<'a, 'tcx> DropElaborator<'a, 'tcx> for Elaborator<'a, '_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn field_subpath(&self, path: Self::Path, field: Field) -> Option<Self::Path> {
|
||||
fn field_subpath(&self, path: Self::Path, field: FieldIdx) -> Option<Self::Path> {
|
||||
rustc_mir_dataflow::move_path_children_matching(self.ctxt.move_data(), path, |e| match e {
|
||||
ProjectionElem::Field(idx, _) => idx == field,
|
||||
_ => false,
|
||||
|
|
|
@ -73,7 +73,7 @@ use rustc_mir_dataflow::{self, Analysis};
|
|||
use rustc_span::def_id::{DefId, LocalDefId};
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::Span;
|
||||
use rustc_target::abi::VariantIdx;
|
||||
use rustc_target::abi::{FieldIdx, VariantIdx};
|
||||
use rustc_target::spec::PanicStrategy;
|
||||
use std::{iter, ops};
|
||||
|
||||
|
@ -162,9 +162,10 @@ impl<'tcx> MutVisitor<'tcx> for PinArgVisitor<'tcx> {
|
|||
place,
|
||||
Place {
|
||||
local: SELF_ARG,
|
||||
projection: self
|
||||
.tcx()
|
||||
.mk_place_elems(&[ProjectionElem::Field(Field::new(0), self.ref_gen_ty)]),
|
||||
projection: self.tcx().mk_place_elems(&[ProjectionElem::Field(
|
||||
FieldIdx::new(0),
|
||||
self.ref_gen_ty,
|
||||
)]),
|
||||
},
|
||||
self.tcx,
|
||||
);
|
||||
|
@ -297,7 +298,7 @@ impl<'tcx> TransformVisitor<'tcx> {
|
|||
let self_place = Place::from(SELF_ARG);
|
||||
let base = self.tcx.mk_place_downcast_unnamed(self_place, variant_index);
|
||||
let mut projection = base.projection.to_vec();
|
||||
projection.push(ProjectionElem::Field(Field::new(idx), ty));
|
||||
projection.push(ProjectionElem::Field(FieldIdx::new(idx), ty));
|
||||
|
||||
Place { local: base.local, projection: self.tcx.mk_place_elems(&projection) }
|
||||
}
|
||||
|
@ -967,7 +968,7 @@ fn compute_layout<'tcx>(
|
|||
|
||||
// Build the generator variant field list.
|
||||
// Create a map from local indices to generator struct indices.
|
||||
let mut variant_fields: IndexVec<VariantIdx, IndexVec<Field, GeneratorSavedLocal>> =
|
||||
let mut variant_fields: IndexVec<VariantIdx, IndexVec<FieldIdx, GeneratorSavedLocal>> =
|
||||
iter::repeat(IndexVec::new()).take(RESERVED_VARIANTS).collect();
|
||||
let mut remap = FxHashMap::default();
|
||||
for (suspension_point_idx, live_locals) in live_locals_at_suspension_points.iter().enumerate() {
|
||||
|
|
|
@ -10,7 +10,7 @@ use rustc_middle::mir::*;
|
|||
use rustc_middle::ty::{self, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
|
||||
use rustc_session::config::OptLevel;
|
||||
use rustc_span::{hygiene::ExpnKind, ExpnData, LocalExpnId, Span};
|
||||
use rustc_target::abi::FIRST_VARIANT;
|
||||
use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
||||
use crate::simplify::{remove_dead_blocks, CfgSimplifier};
|
||||
|
@ -701,7 +701,7 @@ impl<'tcx> Inliner<'tcx> {
|
|||
// The `tmp0`, `tmp1`, and `tmp2` in our example above.
|
||||
let tuple_tmp_args = tuple_tys.iter().enumerate().map(|(i, ty)| {
|
||||
// This is e.g., `tuple_tmp.0` in our example above.
|
||||
let tuple_field = Operand::Move(tcx.mk_place_field(tuple, Field::new(i), ty));
|
||||
let tuple_field = Operand::Move(tcx.mk_place_field(tuple, FieldIdx::new(i), ty));
|
||||
|
||||
// Spill to a local to make e.g., `tmp0`.
|
||||
self.create_temp_if_necessary(tuple_field, callsite, caller_body)
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
use crate::MirPass;
|
||||
use rustc_hir::Mutability;
|
||||
use rustc_middle::mir::{
|
||||
BinOp, Body, CastKind, Constant, ConstantKind, Field, LocalDecls, Operand, Place,
|
||||
ProjectionElem, Rvalue, SourceInfo, Statement, StatementKind, SwitchTargets, Terminator,
|
||||
TerminatorKind, UnOp,
|
||||
BinOp, Body, CastKind, Constant, ConstantKind, LocalDecls, Operand, Place, ProjectionElem,
|
||||
Rvalue, SourceInfo, Statement, StatementKind, SwitchTargets, Terminator, TerminatorKind, UnOp,
|
||||
};
|
||||
use rustc_middle::ty::layout::ValidityRequirement;
|
||||
use rustc_middle::ty::util::IntTypeExt;
|
||||
use rustc_middle::ty::{self, ParamEnv, SubstsRef, Ty, TyCtxt};
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_target::abi::FieldIdx;
|
||||
|
||||
pub struct InstCombine;
|
||||
|
||||
|
@ -187,7 +187,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
|
|||
for (i, field) in variant.fields.iter().enumerate() {
|
||||
let field_ty = field.ty(self.tcx, substs);
|
||||
if field_ty == *cast_ty {
|
||||
let place = place.project_deeper(&[ProjectionElem::Field(Field::from_usize(i), *cast_ty)], self.tcx);
|
||||
let place = place.project_deeper(&[ProjectionElem::Field(FieldIdx::from_usize(i), *cast_ty)], self.tcx);
|
||||
let operand = if operand.is_move() { Operand::Move(place) } else { Operand::Copy(place) };
|
||||
*rvalue = Rvalue::Use(operand);
|
||||
return;
|
||||
|
|
|
@ -6,7 +6,7 @@ use rustc_middle::ty::subst::SubstsRef;
|
|||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
use rustc_span::Span;
|
||||
use rustc_target::abi::VariantIdx;
|
||||
use rustc_target::abi::{FieldIdx, VariantIdx};
|
||||
|
||||
pub struct LowerIntrinsics;
|
||||
|
||||
|
@ -211,7 +211,7 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
|
|||
Some(sym::Some),
|
||||
VariantIdx::from_u32(1),
|
||||
),
|
||||
PlaceElem::Field(Field::from_u32(0), *dest_ty),
|
||||
PlaceElem::Field(FieldIdx::from_u32(0), *dest_ty),
|
||||
],
|
||||
tcx,
|
||||
),
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use rustc_index::bit_set::ChunkedBitSet;
|
||||
use rustc_middle::mir::{Body, Field, TerminatorKind};
|
||||
use rustc_middle::mir::{Body, TerminatorKind};
|
||||
use rustc_middle::ty::subst::SubstsRef;
|
||||
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt, VariantDef};
|
||||
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
|
||||
use rustc_mir_dataflow::move_paths::{LookupResult, MoveData, MovePathIndex};
|
||||
use rustc_mir_dataflow::{self, move_path_children_matching, Analysis, MoveDataParamEnv};
|
||||
use rustc_target::abi::FieldIdx;
|
||||
|
||||
use crate::MirPass;
|
||||
|
||||
|
@ -130,7 +131,7 @@ fn is_needs_drop_and_init<'tcx>(
|
|||
.fields
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(f, field)| (Field::from_usize(f), field.ty(tcx, substs), mpi))
|
||||
.map(|(f, field)| (FieldIdx::from_usize(f), field.ty(tcx, substs), mpi))
|
||||
.any(field_needs_drop_and_init)
|
||||
})
|
||||
}
|
||||
|
@ -138,7 +139,7 @@ fn is_needs_drop_and_init<'tcx>(
|
|||
ty::Tuple(fields) => fields
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(f, f_ty)| (Field::from_usize(f), f_ty, mpi))
|
||||
.map(|(f, f_ty)| (FieldIdx::from_usize(f), f_ty, mpi))
|
||||
.any(field_needs_drop_and_init),
|
||||
|
||||
_ => true,
|
||||
|
|
|
@ -5,7 +5,7 @@ use rustc_middle::mir::*;
|
|||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::InternalSubsts;
|
||||
use rustc_middle::ty::{self, EarlyBinder, GeneratorSubsts, Ty, TyCtxt};
|
||||
use rustc_target::abi::{VariantIdx, FIRST_VARIANT};
|
||||
use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
|
||||
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
|
||||
|
@ -309,7 +309,7 @@ impl<'a, 'tcx> DropElaborator<'a, 'tcx> for DropShimElaborator<'a, 'tcx> {
|
|||
|
||||
fn clear_drop_flag(&mut self, _location: Location, _path: Self::Path, _mode: DropFlagMode) {}
|
||||
|
||||
fn field_subpath(&self, _path: Self::Path, _field: Field) -> Option<Self::Path> {
|
||||
fn field_subpath(&self, _path: Self::Path, _field: FieldIdx) -> Option<Self::Path> {
|
||||
None
|
||||
}
|
||||
fn deref_subpath(&self, _path: Self::Path) -> Option<Self::Path> {
|
||||
|
@ -530,7 +530,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
|
|||
// created by block 2*i. We store this block in `unwind` so that the next clone block
|
||||
// will unwind to it if cloning fails.
|
||||
|
||||
let field = Field::new(i);
|
||||
let field = FieldIdx::new(i);
|
||||
let src_field = self.tcx.mk_place_field(src, field, ity);
|
||||
|
||||
let dest_field = self.tcx.mk_place_field(dest, field, ity);
|
||||
|
@ -753,7 +753,7 @@ fn build_call_shim<'tcx>(
|
|||
if let Some(untuple_args) = untuple_args {
|
||||
let tuple_arg = Local::new(1 + (sig.inputs().len() - 1));
|
||||
args.extend(untuple_args.iter().enumerate().map(|(i, ity)| {
|
||||
Operand::Move(tcx.mk_place_field(Place::from(tuple_arg), Field::new(i), *ity))
|
||||
Operand::Move(tcx.mk_place_field(Place::from(tuple_arg), FieldIdx::new(i), *ity))
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ use rustc_middle::mir::visit::*;
|
|||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_mir_dataflow::value_analysis::{excluded_locals, iter_fields};
|
||||
use rustc_target::abi::FieldIdx;
|
||||
|
||||
pub struct ScalarReplacementOfAggregates;
|
||||
|
||||
|
@ -115,7 +116,7 @@ fn escaping_locals(excluded: &BitSet<Local>, body: &Body<'_>) -> BitSet<Local> {
|
|||
struct ReplacementMap<'tcx> {
|
||||
/// Pre-computed list of all "new" locals for each "old" local. This is used to expand storage
|
||||
/// and deinit statement and debuginfo.
|
||||
fragments: IndexVec<Local, Option<IndexVec<Field, Option<(Ty<'tcx>, Local)>>>>,
|
||||
fragments: IndexVec<Local, Option<IndexVec<FieldIdx, Option<(Ty<'tcx>, Local)>>>>,
|
||||
}
|
||||
|
||||
impl<'tcx> ReplacementMap<'tcx> {
|
||||
|
@ -129,7 +130,7 @@ impl<'tcx> ReplacementMap<'tcx> {
|
|||
fn place_fragments(
|
||||
&self,
|
||||
place: Place<'tcx>,
|
||||
) -> Option<impl Iterator<Item = (Field, Ty<'tcx>, Local)> + '_> {
|
||||
) -> Option<impl Iterator<Item = (FieldIdx, Ty<'tcx>, Local)> + '_> {
|
||||
let local = place.as_local()?;
|
||||
let fields = self.fragments[local].as_ref()?;
|
||||
Some(fields.iter_enumerated().filter_map(|(field, &opt_ty_local)| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue