Use &IndexSlice
instead of &IndexVec
where possible
All the same reasons as for `[T]`: more general, less pointer chasing, and `&mut IndexSlice` emphasizes that it doesn't change *length*.
This commit is contained in:
parent
a93bcdc307
commit
a2ee7592d6
42 changed files with 168 additions and 118 deletions
|
@ -128,7 +128,7 @@ fn split_block(
|
|||
|
||||
fn insert_alignment_check<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
local_decls: &mut LocalDecls<'tcx>,
|
||||
local_decls: &mut IndexVec<Local, LocalDecl<'tcx>>,
|
||||
block_data: &mut BasicBlockData<'tcx>,
|
||||
pointer: Place<'tcx>,
|
||||
pointee_ty: Ty<'tcx>,
|
||||
|
|
|
@ -7,7 +7,7 @@ use rustc_const_eval::const_eval::CheckAlignment;
|
|||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::vec::{IndexSlice, IndexVec};
|
||||
use rustc_middle::mir::visit::{
|
||||
MutVisitor, MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor,
|
||||
};
|
||||
|
@ -127,7 +127,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
|
|||
|
||||
let dummy_body = &Body::new(
|
||||
body.source,
|
||||
(*body.basic_blocks).clone(),
|
||||
(*body.basic_blocks).to_owned(),
|
||||
body.source_scopes.clone(),
|
||||
body.local_decls.clone(),
|
||||
Default::default(),
|
||||
|
@ -319,7 +319,7 @@ struct ConstPropagator<'mir, 'tcx> {
|
|||
ecx: InterpCx<'mir, 'tcx, ConstPropMachine<'mir, 'tcx>>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
param_env: ParamEnv<'tcx>,
|
||||
local_decls: &'mir IndexVec<Local, LocalDecl<'tcx>>,
|
||||
local_decls: &'mir IndexSlice<Local, LocalDecl<'tcx>>,
|
||||
}
|
||||
|
||||
impl<'tcx> LayoutOfHelpers<'tcx> for ConstPropagator<'_, 'tcx> {
|
||||
|
|
|
@ -9,7 +9,7 @@ use rustc_const_eval::interpret::{
|
|||
};
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::HirId;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::vec::IndexSlice;
|
||||
use rustc_middle::mir::visit::Visitor;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
|
||||
|
@ -103,7 +103,7 @@ impl<'tcx> MirLint<'tcx> for ConstProp {
|
|||
|
||||
let dummy_body = &Body::new(
|
||||
body.source,
|
||||
(*body.basic_blocks).clone(),
|
||||
(*body.basic_blocks).to_owned(),
|
||||
body.source_scopes.clone(),
|
||||
body.local_decls.clone(),
|
||||
Default::default(),
|
||||
|
@ -130,8 +130,8 @@ struct ConstPropagator<'mir, 'tcx> {
|
|||
ecx: InterpCx<'mir, 'tcx, ConstPropMachine<'mir, 'tcx>>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
param_env: ParamEnv<'tcx>,
|
||||
source_scopes: &'mir IndexVec<SourceScope, SourceScopeData<'tcx>>,
|
||||
local_decls: &'mir IndexVec<Local, LocalDecl<'tcx>>,
|
||||
source_scopes: &'mir IndexSlice<SourceScope, SourceScopeData<'tcx>>,
|
||||
local_decls: &'mir IndexSlice<Local, LocalDecl<'tcx>>,
|
||||
// Because we have `MutVisitor` we can't obtain the `SourceInfo` from a `Location`. So we store
|
||||
// the last known `SourceInfo` here and just keep revisiting it.
|
||||
source_info: Option<SourceInfo>,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::vec::IndexSlice;
|
||||
use rustc_middle::mir::visit::*;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
|
@ -102,7 +102,7 @@ struct Replacer<'a, 'tcx> {
|
|||
fully_moved: BitSet<Local>,
|
||||
storage_to_remove: BitSet<Local>,
|
||||
borrowed_locals: BitSet<Local>,
|
||||
copy_classes: &'a IndexVec<Local, Local>,
|
||||
copy_classes: &'a IndexSlice<Local, Local>,
|
||||
}
|
||||
|
||||
impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
|
||||
|
|
|
@ -5,7 +5,7 @@ use rustc_data_structures::fx::FxHashMap;
|
|||
use rustc_data_structures::graph::dominators::{self, Dominators};
|
||||
use rustc_data_structures::graph::{self, GraphSuccessors, WithNumNodes, WithStartNode};
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::vec::{IndexSlice, IndexVec};
|
||||
use rustc_middle::mir::coverage::*;
|
||||
use rustc_middle::mir::{self, BasicBlock, BasicBlockData, Terminator, TerminatorKind};
|
||||
|
||||
|
@ -176,10 +176,10 @@ impl CoverageGraph {
|
|||
|
||||
fn add_basic_coverage_block(
|
||||
bcbs: &mut IndexVec<BasicCoverageBlock, BasicCoverageBlockData>,
|
||||
bb_to_bcb: &mut IndexVec<BasicBlock, Option<BasicCoverageBlock>>,
|
||||
bb_to_bcb: &mut IndexSlice<BasicBlock, Option<BasicCoverageBlock>>,
|
||||
basic_blocks: Vec<BasicBlock>,
|
||||
) {
|
||||
let bcb = BasicCoverageBlock::from_usize(bcbs.len());
|
||||
let bcb = bcbs.next_index();
|
||||
for &bb in basic_blocks.iter() {
|
||||
bb_to_bcb[bb] = Some(bcb);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
use crate::MirPass;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::vec::IndexSlice;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
|
||||
|
@ -42,7 +42,7 @@ struct SliceLenPatchInformation<'tcx> {
|
|||
fn lower_slice_len_call<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
block: &mut BasicBlockData<'tcx>,
|
||||
local_decls: &IndexVec<Local, LocalDecl<'tcx>>,
|
||||
local_decls: &IndexSlice<Local, LocalDecl<'tcx>>,
|
||||
slice_len_fn_item_def_id: DefId,
|
||||
) {
|
||||
let mut patch_found: Option<SliceLenPatchInformation<'_>> = None;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
use crate::MirPass;
|
||||
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use rustc_index::vec::{Idx, IndexSlice, IndexVec};
|
||||
use rustc_middle::mir::coverage::*;
|
||||
use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor};
|
||||
use rustc_middle::mir::*;
|
||||
|
@ -67,7 +67,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyCfg {
|
|||
}
|
||||
|
||||
pub struct CfgSimplifier<'a, 'tcx> {
|
||||
basic_blocks: &'a mut IndexVec<BasicBlock, BasicBlockData<'tcx>>,
|
||||
basic_blocks: &'a mut IndexSlice<BasicBlock, BasicBlockData<'tcx>>,
|
||||
pred_count: IndexVec<BasicBlock, u32>,
|
||||
}
|
||||
|
||||
|
@ -369,8 +369,8 @@ pub fn remove_dead_blocks<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
|||
/// instances in a single body, so the strategy described above is applied to
|
||||
/// coverage counters from each instance individually.
|
||||
fn save_unreachable_coverage(
|
||||
basic_blocks: &mut IndexVec<BasicBlock, BasicBlockData<'_>>,
|
||||
source_scopes: &IndexVec<SourceScope, SourceScopeData<'_>>,
|
||||
basic_blocks: &mut IndexSlice<BasicBlock, BasicBlockData<'_>>,
|
||||
source_scopes: &IndexSlice<SourceScope, SourceScopeData<'_>>,
|
||||
first_dead_block: usize,
|
||||
) {
|
||||
// Identify instances that still have some live coverage counters left.
|
||||
|
@ -489,7 +489,7 @@ fn make_local_map<V>(
|
|||
local_decls: &mut IndexVec<Local, V>,
|
||||
used_locals: &UsedLocals,
|
||||
) -> IndexVec<Local, Option<Local>> {
|
||||
let mut map: IndexVec<Local, Option<Local>> = IndexVec::from_elem(None, &*local_decls);
|
||||
let mut map: IndexVec<Local, Option<Local>> = IndexVec::from_elem(None, local_decls);
|
||||
let mut used = Local::new(0);
|
||||
|
||||
for alive_index in local_decls.indices() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use either::Either;
|
||||
use rustc_data_structures::graph::dominators::Dominators;
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::vec::{IndexSlice, IndexVec};
|
||||
use rustc_middle::middle::resolve_bound_vars::Set1;
|
||||
use rustc_middle::mir::visit::*;
|
||||
use rustc_middle::mir::*;
|
||||
|
@ -135,7 +135,7 @@ impl SsaLocals {
|
|||
/// _d => _a // transitively through _c
|
||||
///
|
||||
/// Exception: we do not see through the return place, as it cannot be substituted.
|
||||
pub fn copy_classes(&self) -> &IndexVec<Local, Local> {
|
||||
pub fn copy_classes(&self) -> &IndexSlice<Local, Local> {
|
||||
&self.copy_classes
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue