From a2ee7592d6b7c0daa62b7870ade85e0cc0acca05 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Fri, 31 Mar 2023 00:32:44 -0700 Subject: [PATCH] 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*. --- compiler/rustc_abi/src/layout.rs | 4 +- compiler/rustc_abi/src/lib.rs | 2 +- compiler/rustc_ast_lowering/src/item.rs | 4 +- compiler/rustc_ast_lowering/src/lib.rs | 4 +- .../rustc_borrowck/src/constraints/mod.rs | 6 ++- compiler/rustc_borrowck/src/consumers.rs | 4 +- .../src/diagnostics/explain_borrow.rs | 4 +- .../src/diagnostics/var_name.rs | 6 +-- compiler/rustc_borrowck/src/lib.rs | 8 ++-- .../rustc_borrowck/src/member_constraints.rs | 4 +- compiler/rustc_borrowck/src/nll.rs | 6 +-- .../rustc_borrowck/src/region_infer/mod.rs | 6 +-- compiler/rustc_borrowck/src/renumber.rs | 4 +- compiler/rustc_borrowck/src/type_check/mod.rs | 6 +-- .../src/debuginfo/metadata/enums/mod.rs | 4 +- .../rustc_codegen_ssa/src/coverageinfo/map.rs | 4 +- compiler/rustc_codegen_ssa/src/mir/analyze.rs | 9 ++-- .../src/transform/promote_consts.rs | 6 +-- .../src/graph/dominators/mod.rs | 14 +++---- .../src/graph/iterate/mod.rs | 4 +- .../src/graph/scc/mod.rs | 6 +-- compiler/rustc_index/src/vec.rs | 42 ++++++++++++++++++- .../src/infer/lexical_region_resolve/mod.rs | 6 +-- compiler/rustc_middle/src/mir/basic_blocks.rs | 6 +-- compiler/rustc_middle/src/mir/mod.rs | 19 ++++++--- compiler/rustc_middle/src/mir/tcx.rs | 10 ++--- compiler/rustc_middle/src/mir/traversal.rs | 4 +- compiler/rustc_middle/src/ty/adt.rs | 4 +- .../rustc_mir_build/src/build/custom/mod.rs | 6 +-- .../rustc_mir_build/src/build/custom/parse.rs | 4 +- compiler/rustc_mir_build/src/build/mod.rs | 4 +- compiler/rustc_mir_build/src/build/scope.rs | 4 +- .../rustc_mir_dataflow/src/move_paths/mod.rs | 8 ++-- .../rustc_mir_dataflow/src/value_analysis.rs | 10 ++--- .../src/check_alignment.rs | 2 +- .../rustc_mir_transform/src/const_prop.rs | 6 +-- .../src/const_prop_lint.rs | 8 ++-- compiler/rustc_mir_transform/src/copy_prop.rs | 4 +- .../rustc_mir_transform/src/coverage/graph.rs | 6 +-- .../src/lower_slice_len.rs | 4 +- compiler/rustc_mir_transform/src/simplify.rs | 10 ++--- compiler/rustc_mir_transform/src/ssa.rs | 4 +- 42 files changed, 168 insertions(+), 118 deletions(-) diff --git a/compiler/rustc_abi/src/layout.rs b/compiler/rustc_abi/src/layout.rs index 343f27326ad60..aea59ee6aea3e 100644 --- a/compiler/rustc_abi/src/layout.rs +++ b/compiler/rustc_abi/src/layout.rs @@ -289,7 +289,7 @@ pub trait LayoutCalculator { fn layout_of_struct_or_enum( &self, repr: &ReprOptions, - variants: &IndexVec>>, + variants: &IndexSlice>>, is_enum: bool, is_unsafe_cell: bool, scalar_valid_range: (Bound, Bound), @@ -883,7 +883,7 @@ pub trait LayoutCalculator { fn layout_of_union( &self, repr: &ReprOptions, - variants: &IndexVec>>, + variants: &IndexSlice>>, ) -> Option { let dl = self.current_data_layout(); let dl = dl.borrow(); diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index 428191bc8b934..7b5732b488b41 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -11,7 +11,7 @@ use bitflags::bitflags; use rustc_data_structures::intern::Interned; #[cfg(feature = "nightly")] use rustc_data_structures::stable_hasher::StableOrd; -use rustc_index::vec::{Idx, IndexVec}; +use rustc_index::vec::{Idx, IndexSlice, IndexVec}; #[cfg(feature = "nightly")] use rustc_macros::HashStable_Generic; #[cfg(feature = "nightly")] diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index cc879982abce8..2efffbb6dc5e3 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -12,7 +12,7 @@ use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID}; use rustc_hir::PredicateOrigin; -use rustc_index::vec::{Idx, IndexVec}; +use rustc_index::vec::{Idx, IndexSlice, IndexVec}; use rustc_middle::ty::{ResolverAstLowering, TyCtxt}; use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::source_map::DesugaringKind; @@ -25,7 +25,7 @@ use thin_vec::ThinVec; pub(super) struct ItemLowerer<'a, 'hir> { pub(super) tcx: TyCtxt<'hir>, pub(super) resolver: &'a mut ResolverAstLowering, - pub(super) ast_index: &'a IndexVec>, + pub(super) ast_index: &'a IndexSlice>, pub(super) owners: &'a mut IndexVec>>, } diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index c5d39634c44b7..ca659db4dbea2 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -60,7 +60,7 @@ use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res}; use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID}; use rustc_hir::definitions::DefPathData; use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate}; -use rustc_index::vec::{Idx, IndexVec}; +use rustc_index::vec::{Idx, IndexSlice, IndexVec}; use rustc_macros::fluent_messages; use rustc_middle::{ span_bug, @@ -414,7 +414,7 @@ fn index_crate<'a>( /// This hash will then be part of the crate_hash which is stored in the metadata. fn compute_hir_hash( tcx: TyCtxt<'_>, - owners: &IndexVec>>, + owners: &IndexSlice>>, ) -> Fingerprint { let mut hir_body_nodes: Vec<_> = owners .iter_enumerated() diff --git a/compiler/rustc_borrowck/src/constraints/mod.rs b/compiler/rustc_borrowck/src/constraints/mod.rs index f370c02161b11..d2d9779dbea47 100644 --- a/compiler/rustc_borrowck/src/constraints/mod.rs +++ b/compiler/rustc_borrowck/src/constraints/mod.rs @@ -2,7 +2,7 @@ #![deny(rustc::diagnostic_outside_of_impl)] use rustc_data_structures::graph::scc::Sccs; -use rustc_index::vec::IndexVec; +use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_middle::mir::ConstraintCategory; use rustc_middle::ty::{RegionVid, VarianceDiagInfo}; use rustc_span::Span; @@ -60,7 +60,9 @@ impl<'tcx> OutlivesConstraintSet<'tcx> { Sccs::new(region_graph) } - pub(crate) fn outlives(&self) -> &IndexVec> { + pub(crate) fn outlives( + &self, + ) -> &IndexSlice> { &self.outlives } } diff --git a/compiler/rustc_borrowck/src/consumers.rs b/compiler/rustc_borrowck/src/consumers.rs index 055b281bc2e70..cb1a652222370 100644 --- a/compiler/rustc_borrowck/src/consumers.rs +++ b/compiler/rustc_borrowck/src/consumers.rs @@ -3,7 +3,7 @@ //! This file provides API for compiler consumers. use rustc_hir::def_id::LocalDefId; -use rustc_index::vec::IndexVec; +use rustc_index::vec::IndexSlice; use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt}; use rustc_middle::mir::Body; use rustc_middle::ty::{self, TyCtxt}; @@ -35,6 +35,6 @@ pub fn get_body_with_borrowck_facts( let (input_body, promoted) = tcx.mir_promoted(def); let infcx = tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(def.did)).build(); let input_body: &Body<'_> = &input_body.borrow(); - let promoted: &IndexVec<_, _> = &promoted.borrow(); + let promoted: &IndexSlice<_, _> = &promoted.borrow(); *super::do_mir_borrowck(&infcx, input_body, promoted, true).1.unwrap() } diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index 62b3f3ecfc32f..8860395e71c80 100644 --- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -3,7 +3,7 @@ use rustc_errors::{Applicability, Diagnostic}; use rustc_hir as hir; use rustc_hir::intravisit::Visitor; -use rustc_index::vec::IndexVec; +use rustc_index::vec::IndexSlice; use rustc_infer::infer::NllRegionVariableOrigin; use rustc_middle::mir::{ Body, CastKind, ConstraintCategory, FakeReadCause, Local, LocalInfo, Location, Operand, Place, @@ -60,7 +60,7 @@ impl<'tcx> BorrowExplanation<'tcx> { &self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>, - local_names: &IndexVec>, + local_names: &IndexSlice>, err: &mut Diagnostic, borrow_desc: &str, borrow_span: Option, diff --git a/compiler/rustc_borrowck/src/diagnostics/var_name.rs b/compiler/rustc_borrowck/src/diagnostics/var_name.rs index ada3310d8071b..80b2787ce0c42 100644 --- a/compiler/rustc_borrowck/src/diagnostics/var_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/var_name.rs @@ -3,7 +3,7 @@ use crate::Upvar; use crate::{nll::ToRegionVid, region_infer::RegionInferenceContext}; -use rustc_index::vec::{Idx, IndexVec}; +use rustc_index::vec::{Idx, IndexSlice}; use rustc_middle::mir::{Body, Local}; use rustc_middle::ty::{RegionVid, TyCtxt}; use rustc_span::source_map::Span; @@ -14,7 +14,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { &self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>, - local_names: &IndexVec>, + local_names: &IndexSlice>, upvars: &[Upvar<'tcx>], fr: RegionVid, ) -> Option<(Option, Span)> { @@ -113,7 +113,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { pub(crate) fn get_argument_name_and_span_for_region( &self, body: &Body<'tcx>, - local_names: &IndexVec>, + local_names: &IndexSlice>, argument_index: usize, ) -> (Option, Span) { let implicit_inputs = self.universal_regions().defining_ty.implicit_inputs(); diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index ba322425089a3..1d4d1406239d9 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -23,7 +23,7 @@ use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticMessage, Subdiagnost use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; use rustc_index::bit_set::ChunkedBitSet; -use rustc_index::vec::IndexVec; +use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_infer::infer::{ DefiningAnchor, InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin, TyCtxtInferExt, }; @@ -154,7 +154,7 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: ty::WithOptConstParam) -> &Bor let infcx = tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(hir_owner.def_id)).build(); let input_body: &Body<'_> = &input_body.borrow(); - let promoted: &IndexVec<_, _> = &promoted.borrow(); + let promoted: &IndexSlice<_, _> = &promoted.borrow(); let opt_closure_req = do_mir_borrowck(&infcx, input_body, promoted, false).0; debug!("mir_borrowck done"); @@ -170,7 +170,7 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: ty::WithOptConstParam) -> &Bor fn do_mir_borrowck<'tcx>( infcx: &InferCtxt<'tcx>, input_body: &Body<'tcx>, - input_promoted: &IndexVec>, + input_promoted: &IndexSlice>, return_body_with_facts: bool, ) -> (BorrowCheckResult<'tcx>, Option>>) { let def = input_body.source.with_opt_param().as_local().unwrap(); @@ -223,7 +223,7 @@ fn do_mir_borrowck<'tcx>( // be modified (in place) to contain non-lexical lifetimes. It // will have a lifetime tied to the inference context. let mut body_owned = input_body.clone(); - let mut promoted = input_promoted.clone(); + let mut promoted = input_promoted.to_owned(); let free_regions = nll::replace_regions_in_mir(&infcx, param_env, &mut body_owned, &mut promoted); let body = &body_owned; // no further changes diff --git a/compiler/rustc_borrowck/src/member_constraints.rs b/compiler/rustc_borrowck/src/member_constraints.rs index b6c5d4245d7b4..f637e6a95ac68 100644 --- a/compiler/rustc_borrowck/src/member_constraints.rs +++ b/compiler/rustc_borrowck/src/member_constraints.rs @@ -2,7 +2,7 @@ #![deny(rustc::diagnostic_outside_of_impl)] use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::FxIndexMap; -use rustc_index::vec::IndexVec; +use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_middle::infer::MemberConstraint; use rustc_middle::ty::{self, Ty}; use rustc_span::Span; @@ -215,7 +215,7 @@ where /// target_list: A -> B -> C -> D -> E -> F -> (None) /// ``` fn append_list( - constraints: &mut IndexVec>, + constraints: &mut IndexSlice>, target_list: NllMemberConstraintIndex, source_list: NllMemberConstraintIndex, ) { diff --git a/compiler/rustc_borrowck/src/nll.rs b/compiler/rustc_borrowck/src/nll.rs index f0068fc9226be..06ecbdb1707c5 100644 --- a/compiler/rustc_borrowck/src/nll.rs +++ b/compiler/rustc_borrowck/src/nll.rs @@ -4,7 +4,7 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_hir::def_id::LocalDefId; -use rustc_index::vec::IndexVec; +use rustc_index::vec::IndexSlice; use rustc_middle::mir::{create_dump_file, dump_enabled, dump_mir, PassWhere}; use rustc_middle::mir::{ BasicBlock, Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location, @@ -59,7 +59,7 @@ pub(crate) fn replace_regions_in_mir<'tcx>( infcx: &BorrowckInferCtxt<'_, 'tcx>, param_env: ty::ParamEnv<'tcx>, body: &mut Body<'tcx>, - promoted: &mut IndexVec>, + promoted: &mut IndexSlice>, ) -> UniversalRegions<'tcx> { let def = body.source.with_opt_param().as_local().unwrap(); @@ -158,7 +158,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>( infcx: &BorrowckInferCtxt<'_, 'tcx>, universal_regions: UniversalRegions<'tcx>, body: &Body<'tcx>, - promoted: &IndexVec>, + promoted: &IndexSlice>, location_table: &LocationTable, param_env: ty::ParamEnv<'tcx>, flow_inits: &mut ResultsCursor<'cx, 'tcx, MaybeInitializedPlaces<'cx, 'tcx>>, diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index 03f175daca9e8..f67af4584a4a5 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -7,7 +7,7 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::graph::scc::Sccs; use rustc_errors::Diagnostic; use rustc_hir::def_id::CRATE_DEF_ID; -use rustc_index::vec::IndexVec; +use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_infer::infer::outlives::test_type_match; use rustc_infer::infer::region_constraints::{GenericKind, VarInfos, VerifyBound, VerifyIfEq}; use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin}; @@ -399,7 +399,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// the minimum, or narrowest, universe. fn compute_scc_universes( constraint_sccs: &Sccs, - definitions: &IndexVec>, + definitions: &IndexSlice>, ) -> IndexVec { let num_sccs = constraint_sccs.num_sccs(); let mut scc_universes = IndexVec::from_elem_n(ty::UniverseIndex::MAX, num_sccs); @@ -486,7 +486,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// more details. fn compute_scc_representatives( constraints_scc: &Sccs, - definitions: &IndexVec>, + definitions: &IndexSlice>, ) -> IndexVec { let num_sccs = constraints_scc.num_sccs(); let next_region_vid = definitions.next_index(); diff --git a/compiler/rustc_borrowck/src/renumber.rs b/compiler/rustc_borrowck/src/renumber.rs index 016f6f78dfa1d..0fbf01dbe4455 100644 --- a/compiler/rustc_borrowck/src/renumber.rs +++ b/compiler/rustc_borrowck/src/renumber.rs @@ -1,7 +1,7 @@ #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] use crate::BorrowckInferCtxt; -use rustc_index::vec::IndexVec; +use rustc_index::vec::IndexSlice; use rustc_infer::infer::NllRegionVariableOrigin; use rustc_middle::mir::visit::{MutVisitor, TyContext}; use rustc_middle::mir::Constant; @@ -16,7 +16,7 @@ use rustc_span::{Span, Symbol}; pub fn renumber_mir<'tcx>( infcx: &BorrowckInferCtxt<'_, 'tcx>, body: &mut Body<'tcx>, - promoted: &mut IndexVec>, + promoted: &mut IndexSlice>, ) { debug!(?body.arg_count); diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index f3fe5a6cada16..2fc4e32ecb24e 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -125,7 +125,7 @@ pub(crate) fn type_check<'mir, 'tcx>( infcx: &BorrowckInferCtxt<'_, 'tcx>, param_env: ty::ParamEnv<'tcx>, body: &Body<'tcx>, - promoted: &IndexVec>, + promoted: &IndexSlice>, universal_regions: &Rc>, location_table: &LocationTable, borrow_set: &BorrowSet<'tcx>, @@ -292,7 +292,7 @@ enum FieldAccessError { /// is a problem. struct TypeVerifier<'a, 'b, 'tcx> { cx: &'a mut TypeChecker<'b, 'tcx>, - promoted: &'b IndexVec>, + promoted: &'b IndexSlice>, last_span: Span, errors_reported: bool, } @@ -493,7 +493,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { fn new( cx: &'a mut TypeChecker<'b, 'tcx>, - promoted: &'b IndexVec>, + promoted: &'b IndexSlice>, ) -> Self { TypeVerifier { promoted, last_span: cx.body.span, cx, errors_reported: false } } diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs index c3439591b920a..55a217f59f91e 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs @@ -3,7 +3,7 @@ use rustc_codegen_ssa::debuginfo::{ wants_c_like_enum_debuginfo, }; use rustc_hir::def::CtorKind; -use rustc_index::vec::IndexVec; +use rustc_index::vec::IndexSlice; use rustc_middle::{ bug, mir::{GeneratorLayout, GeneratorSavedLocal}, @@ -323,7 +323,7 @@ pub fn build_generator_variant_struct_type_di_node<'ll, 'tcx>( generator_type_and_layout: TyAndLayout<'tcx>, generator_type_di_node: &'ll DIType, generator_layout: &GeneratorLayout<'tcx>, - state_specific_upvar_names: &IndexVec>, + state_specific_upvar_names: &IndexSlice>, common_upvar_names: &[String], ) -> &'ll DIType { let variant_name = GeneratorSubsts::variant_name(variant_index); diff --git a/compiler/rustc_codegen_ssa/src/coverageinfo/map.rs b/compiler/rustc_codegen_ssa/src/coverageinfo/map.rs index 1a6495cb15cf2..1ea13040072e7 100644 --- a/compiler/rustc_codegen_ssa/src/coverageinfo/map.rs +++ b/compiler/rustc_codegen_ssa/src/coverageinfo/map.rs @@ -1,6 +1,6 @@ pub use super::ffi::*; -use rustc_index::vec::IndexVec; +use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_middle::mir::coverage::{ CodeRegion, CounterValueReference, ExpressionOperandId, InjectedExpressionId, InjectedExpressionIndex, MappedExpressionIndex, Op, @@ -205,7 +205,7 @@ impl<'tcx> FunctionCoverage<'tcx> { // `expression_index`s lower than the referencing `Expression`. Therefore, it is // reasonable to look up the new index of an expression operand while the `new_indexes` // vector is only complete up to the current `ExpressionIndex`. - let id_to_counter = |new_indexes: &IndexVec< + let id_to_counter = |new_indexes: &IndexSlice< InjectedExpressionIndex, Option, >, diff --git a/compiler/rustc_codegen_ssa/src/mir/analyze.rs b/compiler/rustc_codegen_ssa/src/mir/analyze.rs index 0ce395e912db3..dcf533dc39c3b 100644 --- a/compiler/rustc_codegen_ssa/src/mir/analyze.rs +++ b/compiler/rustc_codegen_ssa/src/mir/analyze.rs @@ -5,7 +5,7 @@ use super::FunctionCx; use crate::traits::*; 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::mir::traversal; use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::{self, Location, TerminatorKind}; @@ -277,7 +277,7 @@ impl CleanupKind { /// Recover that structure in an analyze pass. pub fn cleanup_kinds(mir: &mir::Body<'_>) -> IndexVec { fn discover_masters<'tcx>( - result: &mut IndexVec, + result: &mut IndexSlice, mir: &mir::Body<'tcx>, ) { for (bb, data) in mir.basic_blocks.iter_enumerated() { @@ -308,7 +308,10 @@ pub fn cleanup_kinds(mir: &mir::Body<'_>) -> IndexVec(result: &mut IndexVec, mir: &mir::Body<'tcx>) { + fn propagate<'tcx>( + result: &mut IndexSlice, + mir: &mir::Body<'tcx>, + ) { let mut funclet_succs = IndexVec::from_elem(None, &mir.basic_blocks); let mut set_successor = |funclet: mir::BasicBlock, succ| match funclet_succs[funclet] { diff --git a/compiler/rustc_const_eval/src/transform/promote_consts.rs b/compiler/rustc_const_eval/src/transform/promote_consts.rs index 40c848de2beed..6774e5a583764 100644 --- a/compiler/rustc_const_eval/src/transform/promote_consts.rs +++ b/compiler/rustc_const_eval/src/transform/promote_consts.rs @@ -21,7 +21,7 @@ use rustc_middle::ty::subst::InternalSubsts; use rustc_middle::ty::{self, List, TyCtxt, TypeVisitableExt}; use rustc_span::Span; -use rustc_index::vec::{Idx, IndexVec}; +use rustc_index::vec::{Idx, IndexSlice, IndexVec}; use std::cell::Cell; use std::{cmp, iter, mem}; @@ -184,7 +184,7 @@ pub fn collect_temps_and_candidates<'tcx>( /// This wraps an `Item`, and has access to all fields of that `Item` via `Deref` coercion. struct Validator<'a, 'tcx> { ccx: &'a ConstCx<'a, 'tcx>, - temps: &'a mut IndexVec, + temps: &'a mut IndexSlice, } impl<'a, 'tcx> std::ops::Deref for Validator<'a, 'tcx> { @@ -669,7 +669,7 @@ impl<'tcx> Validator<'_, 'tcx> { // FIXME(eddyb) remove the differences for promotability in `static`, `const`, `const fn`. pub fn validate_candidates( ccx: &ConstCx<'_, '_>, - temps: &mut IndexVec, + temps: &mut IndexSlice, candidates: &[Candidate], ) -> Vec { let mut validator = Validator { ccx, temps }; diff --git a/compiler/rustc_data_structures/src/graph/dominators/mod.rs b/compiler/rustc_data_structures/src/graph/dominators/mod.rs index 0a21a4249c829..0df9dc112ee61 100644 --- a/compiler/rustc_data_structures/src/graph/dominators/mod.rs +++ b/compiler/rustc_data_structures/src/graph/dominators/mod.rs @@ -10,7 +10,7 @@ //! use super::ControlFlowGraph; -use rustc_index::vec::{Idx, IndexVec}; +use rustc_index::vec::{Idx, IndexSlice, IndexVec}; use std::cmp::Ordering; #[cfg(test)] @@ -256,10 +256,10 @@ pub fn dominators(graph: G) -> Dominators { /// where `+>` is a proper ancestor and `*>` is just an ancestor. #[inline] fn eval( - ancestor: &mut IndexVec, + ancestor: &mut IndexSlice, lastlinked: Option, - semi: &IndexVec, - label: &mut IndexVec, + semi: &IndexSlice, + label: &mut IndexSlice, node: PreorderIndex, ) -> PreorderIndex { if is_processed(node, lastlinked) { @@ -277,10 +277,10 @@ fn is_processed(v: PreorderIndex, lastlinked: Option) -> bool { #[inline] fn compress( - ancestor: &mut IndexVec, + ancestor: &mut IndexSlice, lastlinked: Option, - semi: &IndexVec, - label: &mut IndexVec, + semi: &IndexSlice, + label: &mut IndexSlice, v: PreorderIndex, ) { assert!(is_processed(v, lastlinked)); diff --git a/compiler/rustc_data_structures/src/graph/iterate/mod.rs b/compiler/rustc_data_structures/src/graph/iterate/mod.rs index 8a9af300c066e..01a83b40a75a5 100644 --- a/compiler/rustc_data_structures/src/graph/iterate/mod.rs +++ b/compiler/rustc_data_structures/src/graph/iterate/mod.rs @@ -1,6 +1,6 @@ use super::{DirectedGraph, WithNumNodes, WithStartNode, WithSuccessors}; use rustc_index::bit_set::BitSet; -use rustc_index::vec::IndexVec; +use rustc_index::vec::{IndexSlice, IndexVec}; use std::ops::ControlFlow; #[cfg(test)] @@ -31,7 +31,7 @@ fn post_order_walk( graph: &G, node: G::Node, result: &mut Vec, - visited: &mut IndexVec, + visited: &mut IndexSlice, ) { struct PostOrderFrame { node: Node, diff --git a/compiler/rustc_data_structures/src/graph/scc/mod.rs b/compiler/rustc_data_structures/src/graph/scc/mod.rs index c4b11951ab7a0..28c357e54dd61 100644 --- a/compiler/rustc_data_structures/src/graph/scc/mod.rs +++ b/compiler/rustc_data_structures/src/graph/scc/mod.rs @@ -8,7 +8,7 @@ use crate::fx::FxHashSet; use crate::graph::vec_graph::VecGraph; use crate::graph::{DirectedGraph, GraphSuccessors, WithNumEdges, WithNumNodes, WithSuccessors}; -use rustc_index::vec::{Idx, IndexVec}; +use rustc_index::vec::{Idx, IndexSlice, IndexVec}; use std::ops::Range; #[cfg(test)] @@ -43,7 +43,7 @@ impl Sccs { SccsConstruction::construct(graph) } - pub fn scc_indices(&self) -> &IndexVec { + pub fn scc_indices(&self) -> &IndexSlice { &self.scc_indices } @@ -123,7 +123,7 @@ impl SccData { self.ranges.len() } - pub fn ranges(&self) -> &IndexVec> { + pub fn ranges(&self) -> &IndexSlice> { &self.ranges } diff --git a/compiler/rustc_index/src/vec.rs b/compiler/rustc_index/src/vec.rs index 6caae059f4ad6..5945de2302a56 100644 --- a/compiler/rustc_index/src/vec.rs +++ b/compiler/rustc_index/src/vec.rs @@ -1,6 +1,7 @@ #[cfg(feature = "rustc_serialize")] use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; +use std::borrow::{Borrow, BorrowMut}; use std::fmt; use std::fmt::Debug; use std::hash::Hash; @@ -51,6 +52,12 @@ impl Idx for u32 { } } +/// An owned contiguous collection of `T`s, indexed by `I` rather than by `usize`. +/// +/// While it's possible to use `u32` or `usize` directly for `I`, +/// you almost certainly want to use a [`newtype_index!`]-generated type instead. +/// +/// [`newtype_index!`]: ../macro.newtype_index.html #[derive(Clone, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct IndexVec { @@ -58,6 +65,13 @@ pub struct IndexVec { _marker: PhantomData, } +/// A view into contiguous `T`s, indexed by `I` rather than by `usize`. +/// +/// One common pattern you'll see is code that uses [`IndexVec::from_elem`] +/// to create the storage needed for a particular "universe" (aka the set of all +/// the possible keys that need an associated value) then passes that working +/// area as `&mut IndexSlice` to clarify that nothing will be added nor +/// removed during processing (and, as a bonus, to chase fewer pointers). #[derive(PartialEq, Eq, Hash)] #[repr(transparent)] pub struct IndexSlice { @@ -116,7 +130,7 @@ impl IndexVec { } #[inline] - pub fn from_elem(elem: T, universe: &IndexVec) -> Self + pub fn from_elem(elem: T, universe: &IndexSlice) -> Self where T: Clone, { @@ -244,6 +258,30 @@ impl DerefMut for IndexVec { } } +impl Borrow> for IndexVec { + fn borrow(&self) -> &IndexSlice { + self + } +} + +impl BorrowMut> for IndexVec { + fn borrow_mut(&mut self) -> &mut IndexSlice { + self + } +} + +impl ToOwned for IndexSlice { + type Owned = IndexVec; + + fn to_owned(&self) -> IndexVec { + IndexVec::from_raw(self.raw.to_owned()) + } + + fn clone_into(&self, target: &mut IndexVec) { + self.raw.clone_into(&mut target.raw) + } +} + impl IndexSlice { #[inline] pub fn from_raw(raw: &[T]) -> &Self { @@ -388,7 +426,7 @@ impl IndexVec { } } -impl IndexVec { +impl IndexSlice { #[inline] pub fn binary_search(&self, value: &T) -> Result { match self.raw.binary_search(value) { diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs index cf657756ff534..9e2bdb7f510b3 100644 --- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs +++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs @@ -13,7 +13,7 @@ use rustc_data_structures::graph::implementation::{ Direction, Graph, NodeIndex, INCOMING, OUTGOING, }; use rustc_data_structures::intern::Interned; -use rustc_index::vec::IndexVec; +use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::PlaceholderRegion; use rustc_middle::ty::{self, Ty, TyCtxt}; @@ -723,7 +723,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { fn collect_error_for_expanding_node( &self, graph: &RegionGraph<'tcx>, - dup_vec: &mut IndexVec>, + dup_vec: &mut IndexSlice>, node_idx: RegionVid, errors: &mut Vec>, ) { @@ -846,7 +846,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { graph: &RegionGraph<'tcx>, orig_node_idx: RegionVid, dir: Direction, - mut dup_vec: Option<&mut IndexVec>>, + mut dup_vec: Option<&mut IndexSlice>>, ) -> (Vec>, FxHashSet, bool) { struct WalkState<'tcx> { set: FxHashSet, diff --git a/compiler/rustc_middle/src/mir/basic_blocks.rs b/compiler/rustc_middle/src/mir/basic_blocks.rs index b93871769b791..3fb468379358a 100644 --- a/compiler/rustc_middle/src/mir/basic_blocks.rs +++ b/compiler/rustc_middle/src/mir/basic_blocks.rs @@ -6,7 +6,7 @@ use rustc_data_structures::graph; use rustc_data_structures::graph::dominators::{dominators, Dominators}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::OnceCell; -use rustc_index::vec::IndexVec; +use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use smallvec::SmallVec; @@ -124,10 +124,10 @@ impl<'tcx> BasicBlocks<'tcx> { } impl<'tcx> std::ops::Deref for BasicBlocks<'tcx> { - type Target = IndexVec>; + type Target = IndexSlice>; #[inline] - fn deref(&self) -> &IndexVec> { + fn deref(&self) -> &IndexSlice> { &self.basic_blocks } } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index de7e8bc861d2c..44fd8478be9b5 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -27,7 +27,7 @@ use polonius_engine::Atom; pub use rustc_ast::Mutability; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::graph::dominators::Dominators; -use rustc_index::vec::{Idx, IndexVec}; +use rustc_index::vec::{Idx, IndexSlice, IndexVec}; use rustc_serialize::{Decodable, Encodable}; use rustc_span::symbol::Symbol; use rustc_span::{Span, DUMMY_SP}; @@ -70,12 +70,19 @@ pub use self::pretty::{ }; /// Types for locals -pub type LocalDecls<'tcx> = IndexVec>; +pub type LocalDecls<'tcx> = IndexSlice>; pub trait HasLocalDecls<'tcx> { fn local_decls(&self) -> &LocalDecls<'tcx>; } +impl<'tcx> HasLocalDecls<'tcx> for IndexVec> { + #[inline] + fn local_decls(&self) -> &LocalDecls<'tcx> { + self + } +} + impl<'tcx> HasLocalDecls<'tcx> for LocalDecls<'tcx> { #[inline] fn local_decls(&self) -> &LocalDecls<'tcx> { @@ -250,7 +257,7 @@ pub struct Body<'tcx> { /// The first local is the return value pointer, followed by `arg_count` /// locals for the function arguments, followed by any user-declared /// variables and temporaries. - pub local_decls: LocalDecls<'tcx>, + pub local_decls: IndexVec>, /// User type annotations. pub user_type_annotations: ty::CanonicalUserTypeAnnotations<'tcx>, @@ -311,7 +318,7 @@ impl<'tcx> Body<'tcx> { source: MirSource<'tcx>, basic_blocks: IndexVec>, source_scopes: IndexVec>, - local_decls: LocalDecls<'tcx>, + local_decls: IndexVec>, user_type_annotations: ty::CanonicalUserTypeAnnotations<'tcx>, arg_count: usize, var_debug_info: Vec>, @@ -1779,7 +1786,7 @@ impl SourceScope { /// from the function that was inlined instead of the function call site. pub fn lint_root( self, - source_scopes: &IndexVec>, + source_scopes: &IndexSlice>, ) -> Option { let mut data = &source_scopes[self]; // FIXME(oli-obk): we should be able to just walk the `inlined_parent_scope`, but it @@ -1799,7 +1806,7 @@ impl SourceScope { #[inline] pub fn inlined_instance<'tcx>( self, - source_scopes: &IndexVec>, + source_scopes: &IndexSlice>, ) -> Option> { let scope_data = &source_scopes[self]; if let Some((inlined_instance, _)) = scope_data.inlined { diff --git a/compiler/rustc_middle/src/mir/tcx.rs b/compiler/rustc_middle/src/mir/tcx.rs index ac28ef5276cf8..0092401470f56 100644 --- a/compiler/rustc_middle/src/mir/tcx.rs +++ b/compiler/rustc_middle/src/mir/tcx.rs @@ -116,7 +116,7 @@ impl<'tcx> PlaceTy<'tcx> { } impl<'tcx> Place<'tcx> { - pub fn ty_from( + pub fn ty_from( local: Local, projection: &[PlaceElem<'tcx>], local_decls: &D, @@ -132,7 +132,7 @@ impl<'tcx> Place<'tcx> { }) } - pub fn ty(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx> + pub fn ty(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx> where D: HasLocalDecls<'tcx>, { @@ -141,7 +141,7 @@ impl<'tcx> Place<'tcx> { } impl<'tcx> PlaceRef<'tcx> { - pub fn ty(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx> + pub fn ty(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx> where D: HasLocalDecls<'tcx>, { @@ -155,7 +155,7 @@ pub enum RvalueInitializationState { } impl<'tcx> Rvalue<'tcx> { - pub fn ty(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> Ty<'tcx> + pub fn ty(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> Ty<'tcx> where D: HasLocalDecls<'tcx>, { @@ -217,7 +217,7 @@ impl<'tcx> Rvalue<'tcx> { } impl<'tcx> Operand<'tcx> { - pub fn ty(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> Ty<'tcx> + pub fn ty(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> Ty<'tcx> where D: HasLocalDecls<'tcx>, { diff --git a/compiler/rustc_middle/src/mir/traversal.rs b/compiler/rustc_middle/src/mir/traversal.rs index f37222cb29758..62cdf794b1e91 100644 --- a/compiler/rustc_middle/src/mir/traversal.rs +++ b/compiler/rustc_middle/src/mir/traversal.rs @@ -101,7 +101,7 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> { /// /// A Postorder traversal of this graph is `D B C A` or `D C B A` pub struct Postorder<'a, 'tcx> { - basic_blocks: &'a IndexVec>, + basic_blocks: &'a IndexSlice>, visited: BitSet, visit_stack: Vec<(BasicBlock, Successors<'a>)>, root_is_start_block: bool, @@ -109,7 +109,7 @@ pub struct Postorder<'a, 'tcx> { impl<'a, 'tcx> Postorder<'a, 'tcx> { pub fn new( - basic_blocks: &'a IndexVec>, + basic_blocks: &'a IndexSlice>, root: BasicBlock, ) -> Postorder<'a, 'tcx> { let mut po = Postorder { diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs index 50d7fb1813a57..3a03c0901d798 100644 --- a/compiler/rustc_middle/src/ty/adt.rs +++ b/compiler/rustc_middle/src/ty/adt.rs @@ -10,7 +10,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::DefId; -use rustc_index::vec::IndexVec; +use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_query_system::ich::StableHashingContext; use rustc_session::DataTypeKind; use rustc_span::symbol::sym; @@ -168,7 +168,7 @@ impl<'tcx> AdtDef<'tcx> { } #[inline] - pub fn variants(self) -> &'tcx IndexVec { + pub fn variants(self) -> &'tcx IndexSlice { &self.0.0.variants } diff --git a/compiler/rustc_mir_build/src/build/custom/mod.rs b/compiler/rustc_mir_build/src/build/custom/mod.rs index 33fdc1901cd78..d385153ba94c5 100644 --- a/compiler/rustc_mir_build/src/build/custom/mod.rs +++ b/compiler/rustc_mir_build/src/build/custom/mod.rs @@ -21,7 +21,7 @@ use rustc_ast::Attribute; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::DefId; use rustc_hir::HirId; -use rustc_index::vec::IndexVec; +use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_middle::{ mir::*, thir::*, @@ -37,7 +37,7 @@ pub(super) fn build_custom_mir<'tcx>( hir_id: HirId, thir: &Thir<'tcx>, expr: ExprId, - params: &IndexVec>, + params: &IndexSlice>, return_ty: Ty<'tcx>, return_ty_span: Span, span: Span, @@ -49,7 +49,7 @@ pub(super) fn build_custom_mir<'tcx>( phase: MirPhase::Built, source_scopes: IndexVec::new(), generator: None, - local_decls: LocalDecls::new(), + local_decls: IndexVec::new(), user_type_annotations: IndexVec::new(), arg_count: params.len(), spread_arg: None, diff --git a/compiler/rustc_mir_build/src/build/custom/parse.rs b/compiler/rustc_mir_build/src/build/custom/parse.rs index d72770e70c7ec..12b2f5d807774 100644 --- a/compiler/rustc_mir_build/src/build/custom/parse.rs +++ b/compiler/rustc_mir_build/src/build/custom/parse.rs @@ -1,4 +1,4 @@ -use rustc_index::vec::IndexVec; +use rustc_index::vec::IndexSlice; use rustc_middle::{mir::*, thir::*, ty::Ty}; use rustc_span::Span; @@ -81,7 +81,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> { } } - pub fn parse_args(&mut self, params: &IndexVec>) -> PResult<()> { + pub fn parse_args(&mut self, params: &IndexSlice>) -> PResult<()> { for param in params.iter() { let (var, span) = { let pat = param.pat.as_ref().unwrap(); diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs index e87e38fd04caf..ac645cce5c6aa 100644 --- a/compiler/rustc_mir_build/src/build/mod.rs +++ b/compiler/rustc_mir_build/src/build/mod.rs @@ -11,7 +11,7 @@ use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{GeneratorKind, Node}; -use rustc_index::vec::{Idx, IndexVec}; +use rustc_index::vec::{Idx, IndexSlice, IndexVec}; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_middle::hir::place::PlaceBase as HirPlaceBase; use rustc_middle::middle::region; @@ -821,7 +821,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { fn args_and_body( &mut self, mut block: BasicBlock, - arguments: &IndexVec>, + arguments: &IndexSlice>, argument_scope: region::Scope, expr: &Expr<'tcx>, ) -> BlockAnd<()> { diff --git a/compiler/rustc_mir_build/src/build/scope.rs b/compiler/rustc_mir_build/src/build/scope.rs index 4bc2c0ca791e6..25af221bf369b 100644 --- a/compiler/rustc_mir_build/src/build/scope.rs +++ b/compiler/rustc_mir_build/src/build/scope.rs @@ -86,7 +86,7 @@ use std::mem; use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder, CFG}; use rustc_data_structures::fx::FxHashMap; use rustc_hir::HirId; -use rustc_index::vec::IndexVec; +use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_middle::middle::region; use rustc_middle::mir::*; use rustc_middle::thir::{Expr, LintLevel}; @@ -360,7 +360,7 @@ impl DropTree { fn link_blocks<'tcx>( &self, cfg: &mut CFG<'tcx>, - blocks: &IndexVec>, + blocks: &IndexSlice>, ) { for (drop_idx, drop_data) in self.drops.iter_enumerated().rev() { let Some(block) = blocks[drop_idx] else { continue }; diff --git a/compiler/rustc_mir_dataflow/src/move_paths/mod.rs b/compiler/rustc_mir_dataflow/src/move_paths/mod.rs index 5f22a418de863..257a42cddc8d2 100644 --- a/compiler/rustc_mir_dataflow/src/move_paths/mod.rs +++ b/compiler/rustc_mir_dataflow/src/move_paths/mod.rs @@ -1,6 +1,6 @@ use crate::move_paths::builder::MoveDat; use rustc_data_structures::fx::FxHashMap; -use rustc_index::vec::IndexVec; +use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_middle::mir::*; use rustc_middle::ty::{ParamEnv, Ty, TyCtxt}; use rustc_span::Span; @@ -64,7 +64,7 @@ impl<'tcx> MovePath<'tcx> { /// Returns an iterator over the parents of `self`. pub fn parents<'a>( &self, - move_paths: &'a IndexVec>, + move_paths: &'a IndexSlice>, ) -> impl 'a + Iterator)> { let first = self.parent.map(|mpi| (mpi, &move_paths[mpi])); MovePathLinearIter { @@ -78,7 +78,7 @@ impl<'tcx> MovePath<'tcx> { /// Returns an iterator over the immediate children of `self`. pub fn children<'a>( &self, - move_paths: &'a IndexVec>, + move_paths: &'a IndexSlice>, ) -> impl 'a + Iterator)> { let first = self.first_child.map(|mpi| (mpi, &move_paths[mpi])); MovePathLinearIter { @@ -95,7 +95,7 @@ impl<'tcx> MovePath<'tcx> { /// `f` will **not** be called on `self`. pub fn find_descendant( &self, - move_paths: &IndexVec>, + move_paths: &IndexSlice>, f: impl Fn(MovePathIndex) -> bool, ) -> Option { let mut todo = if let Some(child) = self.first_child { diff --git a/compiler/rustc_mir_dataflow/src/value_analysis.rs b/compiler/rustc_mir_dataflow/src/value_analysis.rs index 63e553bec5329..33a15a8d224f8 100644 --- a/compiler/rustc_mir_dataflow/src/value_analysis.rs +++ b/compiler/rustc_mir_dataflow/src/value_analysis.rs @@ -36,7 +36,7 @@ use std::fmt::{Debug, Formatter}; use rustc_data_structures::fx::FxHashMap; use rustc_index::bit_set::BitSet; -use rustc_index::vec::IndexVec; +use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_middle::mir::visit::{MutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; use rustc_middle::ty::{self, Ty, TyCtxt}; @@ -1028,8 +1028,8 @@ where fn debug_with_context_rec( place: PlaceIndex, place_str: &str, - new: &IndexVec, - old: Option<&IndexVec>, + new: &IndexSlice, + old: Option<&IndexSlice>, map: &Map, f: &mut Formatter<'_>, ) -> std::fmt::Result { @@ -1069,8 +1069,8 @@ fn debug_with_context_rec( } fn debug_with_context( - new: &IndexVec, - old: Option<&IndexVec>, + new: &IndexSlice, + old: Option<&IndexSlice>, map: &Map, f: &mut Formatter<'_>, ) -> std::fmt::Result { diff --git a/compiler/rustc_mir_transform/src/check_alignment.rs b/compiler/rustc_mir_transform/src/check_alignment.rs index 996416ef22ef0..5815887e5bbb6 100644 --- a/compiler/rustc_mir_transform/src/check_alignment.rs +++ b/compiler/rustc_mir_transform/src/check_alignment.rs @@ -128,7 +128,7 @@ fn split_block( fn insert_alignment_check<'tcx>( tcx: TyCtxt<'tcx>, - local_decls: &mut LocalDecls<'tcx>, + local_decls: &mut IndexVec>, block_data: &mut BasicBlockData<'tcx>, pointer: Place<'tcx>, pointee_ty: Ty<'tcx>, diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index e7075d5e79120..ac55948e61b57 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -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_decls: &'mir IndexSlice>, } impl<'tcx> LayoutOfHelpers<'tcx> for ConstPropagator<'_, 'tcx> { diff --git a/compiler/rustc_mir_transform/src/const_prop_lint.rs b/compiler/rustc_mir_transform/src/const_prop_lint.rs index 60401b054922a..d7696a5700061 100644 --- a/compiler/rustc_mir_transform/src/const_prop_lint.rs +++ b/compiler/rustc_mir_transform/src/const_prop_lint.rs @@ -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>, - local_decls: &'mir IndexVec>, + source_scopes: &'mir IndexSlice>, + local_decls: &'mir IndexSlice>, // 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, diff --git a/compiler/rustc_mir_transform/src/copy_prop.rs b/compiler/rustc_mir_transform/src/copy_prop.rs index f27beb64a14d9..c155048c98b46 100644 --- a/compiler/rustc_mir_transform/src/copy_prop.rs +++ b/compiler/rustc_mir_transform/src/copy_prop.rs @@ -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, storage_to_remove: BitSet, borrowed_locals: BitSet, - copy_classes: &'a IndexVec, + copy_classes: &'a IndexSlice, } impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> { diff --git a/compiler/rustc_mir_transform/src/coverage/graph.rs b/compiler/rustc_mir_transform/src/coverage/graph.rs index 49028ca4e5ec8..689d6c71361dd 100644 --- a/compiler/rustc_mir_transform/src/coverage/graph.rs +++ b/compiler/rustc_mir_transform/src/coverage/graph.rs @@ -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, - bb_to_bcb: &mut IndexVec>, + bb_to_bcb: &mut IndexSlice>, basic_blocks: Vec, ) { - let bcb = BasicCoverageBlock::from_usize(bcbs.len()); + let bcb = bcbs.next_index(); for &bb in basic_blocks.iter() { bb_to_bcb[bb] = Some(bcb); } diff --git a/compiler/rustc_mir_transform/src/lower_slice_len.rs b/compiler/rustc_mir_transform/src/lower_slice_len.rs index c6e7468aab429..101fae2f08c5c 100644 --- a/compiler/rustc_mir_transform/src/lower_slice_len.rs +++ b/compiler/rustc_mir_transform/src/lower_slice_len.rs @@ -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_decls: &IndexSlice>, slice_len_fn_item_def_id: DefId, ) { let mut patch_found: Option> = None; diff --git a/compiler/rustc_mir_transform/src/simplify.rs b/compiler/rustc_mir_transform/src/simplify.rs index 5bdb8ab6bfc1d..c79e1cf080509 100644 --- a/compiler/rustc_mir_transform/src/simplify.rs +++ b/compiler/rustc_mir_transform/src/simplify.rs @@ -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>, + basic_blocks: &'a mut IndexSlice>, pred_count: IndexVec, } @@ -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>, - source_scopes: &IndexVec>, + basic_blocks: &mut IndexSlice>, + source_scopes: &IndexSlice>, first_dead_block: usize, ) { // Identify instances that still have some live coverage counters left. @@ -489,7 +489,7 @@ fn make_local_map( local_decls: &mut IndexVec, used_locals: &UsedLocals, ) -> IndexVec> { - let mut map: IndexVec> = IndexVec::from_elem(None, &*local_decls); + let mut map: IndexVec> = IndexVec::from_elem(None, local_decls); let mut used = Local::new(0); for alive_index in local_decls.indices() { diff --git a/compiler/rustc_mir_transform/src/ssa.rs b/compiler/rustc_mir_transform/src/ssa.rs index 73168652f8fa2..be026402dd578 100644 --- a/compiler/rustc_mir_transform/src/ssa.rs +++ b/compiler/rustc_mir_transform/src/ssa.rs @@ -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 { + pub fn copy_classes(&self) -> &IndexSlice { &self.copy_classes }