From 756aa1e46c1c562585f8f55cd5dd2e0a3021ab1f Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Tue, 3 Dec 2019 11:51:58 -0500 Subject: [PATCH 1/3] rustc: Apply clearer naming to BodyAndCache, fix Deref impl, remove unneeded Index impl, remove body fn rustc_codegen_ssa: Fix BodyAndCache reborrow to Body and change instances of body() call to derefence rustc_mir: Fix BodyAndCache reborrow to Body and change intances of body() call to derefence --- src/librustc/arena.rs | 8 +-- src/librustc/mir/cache.rs | 54 +++++++++---------- src/librustc/mir/mod.rs | 6 +-- src/librustc/mir/visit.rs | 4 +- src/librustc/query/mod.rs | 18 +++---- src/librustc/ty/context.rs | 12 ++--- src/librustc/ty/mod.rs | 4 +- src/librustc_codegen_ssa/mir/block.rs | 2 +- src/librustc_codegen_ssa/mir/mod.rs | 2 +- src/librustc_metadata/rmeta/decoder.rs | 6 +-- src/librustc_metadata/rmeta/mod.rs | 4 +- src/librustc_mir/borrow_check/borrow_set.rs | 6 +-- .../diagnostics/mutability_errors.rs | 4 +- src/librustc_mir/borrow_check/mod.rs | 12 ++--- .../borrow_check/nll/invalidation.rs | 4 +- src/librustc_mir/borrow_check/nll/mod.rs | 12 ++--- .../borrow_check/nll/region_infer/values.rs | 4 +- src/librustc_mir/borrow_check/nll/renumber.rs | 6 +-- .../nll/type_check/liveness/local_use_map.rs | 4 +- .../nll/type_check/liveness/mod.rs | 4 +- .../nll/type_check/liveness/polonius.rs | 4 +- .../nll/type_check/liveness/trace.rs | 6 +-- .../borrow_check/nll/type_check/mod.rs | 28 +++++----- src/librustc_mir/borrow_check/prefixes.rs | 4 +- src/librustc_mir/build/mod.rs | 4 +- src/librustc_mir/const_eval.rs | 4 +- .../dataflow/impls/storage_liveness.rs | 6 +-- src/librustc_mir/interpret/eval_context.rs | 2 +- src/librustc_mir/shim.rs | 18 +++---- src/librustc_mir/transform/add_call_guards.rs | 4 +- .../transform/add_moves_for_packed_drops.rs | 4 +- src/librustc_mir/transform/add_retag.rs | 2 +- .../transform/check_consts/mod.rs | 4 +- .../transform/check_consts/validation.rs | 6 +-- .../transform/cleanup_post_borrowck.rs | 4 +- src/librustc_mir/transform/const_prop.rs | 12 ++--- src/librustc_mir/transform/copy_prop.rs | 6 +-- src/librustc_mir/transform/deaggregator.rs | 2 +- src/librustc_mir/transform/dump_mir.rs | 4 +- src/librustc_mir/transform/elaborate_drops.rs | 2 +- src/librustc_mir/transform/erase_regions.rs | 2 +- src/librustc_mir/transform/generator.rs | 30 +++++------ src/librustc_mir/transform/inline.rs | 12 ++--- src/librustc_mir/transform/instcombine.rs | 4 +- src/librustc_mir/transform/mod.rs | 18 +++---- src/librustc_mir/transform/no_landing_pads.rs | 4 +- src/librustc_mir/transform/promote_consts.rs | 20 +++---- .../transform/remove_noop_landing_pads.rs | 6 +-- src/librustc_mir/transform/rustc_peek.rs | 4 +- src/librustc_mir/transform/simplify.rs | 10 ++-- .../transform/simplify_branches.rs | 2 +- src/librustc_mir/transform/simplify_try.rs | 4 +- .../transform/uniform_array_move_out.rs | 4 +- .../transform/uninhabited_enum_branching.rs | 4 +- src/librustc_mir/util/collect_writes.rs | 4 +- src/librustc_mir/util/def_use.rs | 8 +-- src/librustc_mir/util/liveness.rs | 2 +- src/librustc_mir/util/patch.rs | 2 +- 58 files changed, 219 insertions(+), 223 deletions(-) diff --git a/src/librustc/arena.rs b/src/librustc/arena.rs index 364a35f1b6faa..eb7a170980154 100644 --- a/src/librustc/arena.rs +++ b/src/librustc/arena.rs @@ -23,17 +23,17 @@ macro_rules! arena_types { [] generics: rustc::ty::Generics, [] trait_def: rustc::ty::TraitDef, [] adt_def: rustc::ty::AdtDef, - [] steal_mir: rustc::ty::steal::Steal>, - [] mir: rustc::mir::BodyCache<$tcx>, + [] steal_mir: rustc::ty::steal::Steal>, + [] mir: rustc::mir::BodyAndCache<$tcx>, [] steal_promoted: rustc::ty::steal::Steal< rustc_index::vec::IndexVec< rustc::mir::Promoted, - rustc::mir::BodyCache<$tcx> + rustc::mir::BodyAndCache<$tcx> > >, [] promoted: rustc_index::vec::IndexVec< rustc::mir::Promoted, - rustc::mir::BodyCache<$tcx> + rustc::mir::BodyAndCache<$tcx> >, [] tables: rustc::ty::TypeckTables<$tcx>, [] const_allocs: rustc::mir::interpret::Allocation, diff --git a/src/librustc/mir/cache.rs b/src/librustc/mir/cache.rs index 95e9f098da3fb..0704771f6ee95 100644 --- a/src/librustc/mir/cache.rs +++ b/src/librustc/mir/cache.rs @@ -115,16 +115,16 @@ impl Cache { } #[derive(Clone, Debug, HashStable, RustcEncodable, RustcDecodable, TypeFoldable)] -pub struct BodyCache<'tcx> { - cache: Cache, +pub struct BodyAndCache<'tcx> { body: Body<'tcx>, + cache: Cache, } -impl BodyCache<'tcx> { +impl BodyAndCache<'tcx> { pub fn new(body: Body<'tcx>) -> Self { Self { - cache: Cache::new(), body, + cache: Cache::new(), } } } @@ -139,7 +139,7 @@ macro_rules! read_only { }; } -impl BodyCache<'tcx> { +impl BodyAndCache<'tcx> { pub fn ensure_predecessors(&mut self) { self.cache.ensure_predecessors(&self.body); } @@ -148,8 +148,8 @@ impl BodyCache<'tcx> { self.cache.predecessors(&self.body) } - pub fn unwrap_read_only(&self) -> ReadOnlyBodyCache<'_, 'tcx> { - ReadOnlyBodyCache::new(&self.cache, &self.body) + pub fn unwrap_read_only(&self) -> ReadOnlyBodyAndCache<'_, 'tcx> { + ReadOnlyBodyAndCache::new(&self.body, &self.cache) } pub fn basic_blocks_mut(&mut self) -> &mut IndexVec> { @@ -163,7 +163,7 @@ impl BodyCache<'tcx> { } } -impl<'tcx> Index for BodyCache<'tcx> { +impl<'tcx> Index for BodyAndCache<'tcx> { type Output = BasicBlockData<'tcx>; fn index(&self, index: BasicBlock) -> &BasicBlockData<'tcx> { @@ -171,13 +171,13 @@ impl<'tcx> Index for BodyCache<'tcx> { } } -impl<'tcx> IndexMut for BodyCache<'tcx> { +impl<'tcx> IndexMut for BodyAndCache<'tcx> { fn index_mut(&mut self, index: BasicBlock) -> &mut Self::Output { &mut self.basic_blocks_mut()[index] } } -impl<'tcx> Deref for BodyCache<'tcx> { +impl<'tcx> Deref for BodyAndCache<'tcx> { type Target = Body<'tcx>; fn deref(&self) -> &Self::Target { @@ -185,26 +185,26 @@ impl<'tcx> Deref for BodyCache<'tcx> { } } -impl<'tcx> DerefMut for BodyCache<'tcx> { +impl<'tcx> DerefMut for BodyAndCache<'tcx> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.body } } #[derive(Copy, Clone, Debug)] -pub struct ReadOnlyBodyCache<'a, 'tcx> { - cache: &'a Cache, +pub struct ReadOnlyBodyAndCache<'a, 'tcx> { body: &'a Body<'tcx>, + cache: &'a Cache, } -impl ReadOnlyBodyCache<'a, 'tcx> { - fn new(cache: &'a Cache, body: &'a Body<'tcx>) -> Self { +impl ReadOnlyBodyAndCache<'a, 'tcx> { + fn new(body: &'a Body<'tcx>, cache: &'a Cache) -> Self { assert!( cache.predecessors.is_some(), - "Cannot construct ReadOnlyBodyCache without computed predecessors"); + "Cannot construct ReadOnlyBodyAndCache without computed predecessors"); Self { - cache, body, + cache, } } @@ -220,10 +220,6 @@ impl ReadOnlyBodyCache<'a, 'tcx> { self.cache.unwrap_predecessor_locations(loc, self.body) } - pub fn body(&self) -> &'a Body<'tcx> { - self.body - } - pub fn basic_blocks(&self) -> &IndexVec> { &self.body.basic_blocks } @@ -233,16 +229,16 @@ impl ReadOnlyBodyCache<'a, 'tcx> { } } -impl graph::DirectedGraph for ReadOnlyBodyCache<'a, 'tcx> { +impl graph::DirectedGraph for ReadOnlyBodyAndCache<'a, 'tcx> { type Node = BasicBlock; } -impl graph::GraphPredecessors<'graph> for ReadOnlyBodyCache<'a, 'tcx> { +impl graph::GraphPredecessors<'graph> for ReadOnlyBodyAndCache<'a, 'tcx> { type Item = BasicBlock; type Iter = IntoIter; } -impl graph::WithPredecessors for ReadOnlyBodyCache<'a, 'tcx> { +impl graph::WithPredecessors for ReadOnlyBodyAndCache<'a, 'tcx> { fn predecessors( &self, node: Self::Node, @@ -251,19 +247,19 @@ impl graph::WithPredecessors for ReadOnlyBodyCache<'a, 'tcx> { } } -impl graph::WithNumNodes for ReadOnlyBodyCache<'a, 'tcx> { +impl graph::WithNumNodes for ReadOnlyBodyAndCache<'a, 'tcx> { fn num_nodes(&self) -> usize { self.body.num_nodes() } } -impl graph::WithStartNode for ReadOnlyBodyCache<'a, 'tcx> { +impl graph::WithStartNode for ReadOnlyBodyAndCache<'a, 'tcx> { fn start_node(&self) -> Self::Node { self.body.start_node() } } -impl graph::WithSuccessors for ReadOnlyBodyCache<'a, 'tcx> { +impl graph::WithSuccessors for ReadOnlyBodyAndCache<'a, 'tcx> { fn successors( &self, node: Self::Node, @@ -272,13 +268,13 @@ impl graph::WithSuccessors for ReadOnlyBodyCache<'a, 'tcx> { } } -impl<'a, 'b, 'tcx> graph::GraphSuccessors<'b> for ReadOnlyBodyCache<'a, 'tcx> { +impl<'a, 'b, 'tcx> graph::GraphSuccessors<'b> for ReadOnlyBodyAndCache<'a, 'tcx> { type Item = BasicBlock; type Iter = iter::Cloned>; } -impl Deref for ReadOnlyBodyCache<'a, 'tcx> { +impl Deref for ReadOnlyBodyAndCache<'a, 'tcx> { type Target = &'a Body<'tcx>; fn deref(&self) -> &Self::Target { diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index df5d4997e089a..f8fd096fd7c46 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -38,7 +38,7 @@ use syntax::symbol::Symbol; use syntax_pos::{Span, DUMMY_SP}; pub use crate::mir::interpret::AssertMessage; -pub use crate::mir::cache::{BodyCache, ReadOnlyBodyCache}; +pub use crate::mir::cache::{BodyAndCache, ReadOnlyBodyAndCache}; pub use crate::read_only; mod cache; @@ -108,7 +108,7 @@ pub struct Body<'tcx> { pub yield_ty: Option>, /// Generator drop glue. - pub generator_drop: Option>>, + pub generator_drop: Option>>, /// The layout of a generator. Produced by the state transformation. pub generator_layout: Option>, @@ -2601,7 +2601,7 @@ impl Location { pub fn is_predecessor_of<'tcx>( &self, other: Location, - body: ReadOnlyBodyCache<'_, 'tcx> + body: ReadOnlyBodyAndCache<'_, 'tcx> ) -> bool { // If we are in the same block as the other location and are an earlier statement // then we are a predecessor of `other`. diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 47a1d67d5d6db..703e0cc78c207 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -67,10 +67,10 @@ use syntax_pos::Span; macro_rules! body_cache_type { (mut $a:lifetime, $tcx:lifetime) => { - &mut BodyCache<$tcx> + &mut BodyAndCache<$tcx> }; ($a:lifetime, $tcx:lifetime) => { - ReadOnlyBodyCache<$a, $tcx> + ReadOnlyBodyAndCache<$a, $tcx> }; } diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs index a6d7e5c9291dc..538b13c79ce1c 100644 --- a/src/librustc/query/mod.rs +++ b/src/librustc/query/mod.rs @@ -106,30 +106,30 @@ rustc_queries! { /// Fetch the MIR for a given `DefId` right after it's built - this includes /// unreachable code. - query mir_built(_: DefId) -> &'tcx Steal> {} + query mir_built(_: DefId) -> &'tcx Steal> {} /// Fetch the MIR for a given `DefId` up till the point where it is /// ready for const evaluation. /// /// See the README for the `mir` module for details. - query mir_const(_: DefId) -> &'tcx Steal> { + query mir_const(_: DefId) -> &'tcx Steal> { no_hash } query mir_validated(_: DefId) -> ( - &'tcx Steal>, - &'tcx Steal>> + &'tcx Steal>, + &'tcx Steal>> ) { no_hash } /// MIR after our optimization passes have run. This is MIR that is ready /// for codegen. This is also the only query that can fetch non-local MIR, at present. - query optimized_mir(key: DefId) -> &'tcx mir::BodyCache<'tcx> { + query optimized_mir(key: DefId) -> &'tcx mir::BodyAndCache<'tcx> { cache_on_disk_if { key.is_local() } load_cached(tcx, id) { - let mir: Option> + let mir: Option> = tcx.queries.on_disk_cache.try_load_query_result(tcx, id); mir.map(|x| { let cache = tcx.arena.alloc(x); @@ -139,13 +139,13 @@ rustc_queries! { } } - query promoted_mir(key: DefId) -> &'tcx IndexVec> { + query promoted_mir(key: DefId) -> &'tcx IndexVec> { cache_on_disk_if { key.is_local() } load_cached(tcx, id) { let promoted: Option< rustc_index::vec::IndexVec< crate::mir::Promoted, - crate::mir::BodyCache<'tcx> + crate::mir::BodyAndCache<'tcx> >> = tcx.queries.on_disk_cache.try_load_query_result(tcx, id); promoted.map(|p| { let cache = tcx.arena.alloc(p); @@ -512,7 +512,7 @@ rustc_queries! { /// in the case of closures, this will be redirected to the enclosing function. query region_scope_tree(_: DefId) -> &'tcx region::ScopeTree {} - query mir_shims(key: ty::InstanceDef<'tcx>) -> &'tcx mir::BodyCache<'tcx> { + query mir_shims(key: ty::InstanceDef<'tcx>) -> &'tcx mir::BodyAndCache<'tcx> { no_force desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) } } diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 6a0002cd80fd0..2771058ccf45d 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -22,7 +22,7 @@ use crate::middle::cstore::EncodedMetadata; use crate::middle::lang_items; use crate::middle::resolve_lifetime::{self, ObjectLifetimeDefault}; use crate::middle::stability; -use crate::mir::{BodyCache, Field, interpret, Local, Place, PlaceElem, ProjectionKind, Promoted}; +use crate::mir::{BodyAndCache, Field, interpret, Local, Place, PlaceElem, ProjectionKind, Promoted}; use crate::mir::interpret::{ConstValue, Allocation, Scalar}; use crate::ty::subst::{GenericArg, InternalSubsts, SubstsRef, Subst}; use crate::ty::ReprOptions; @@ -1083,17 +1083,17 @@ impl<'tcx> TyCtxt<'tcx> { &self.hir_map } - pub fn alloc_steal_mir(self, mir: BodyCache<'tcx>) -> &'tcx Steal> { + pub fn alloc_steal_mir(self, mir: BodyAndCache<'tcx>) -> &'tcx Steal> { self.arena.alloc(Steal::new(mir)) } - pub fn alloc_steal_promoted(self, promoted: IndexVec>) -> - &'tcx Steal>> { + pub fn alloc_steal_promoted(self, promoted: IndexVec>) -> + &'tcx Steal>> { self.arena.alloc(Steal::new(promoted)) } - pub fn intern_promoted(self, promoted: IndexVec>) -> - &'tcx IndexVec> { + pub fn intern_promoted(self, promoted: IndexVec>) -> + &'tcx IndexVec> { self.arena.alloc(promoted) } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index c9a934e9ebd84..980e69e081491 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -18,7 +18,7 @@ use crate::infer::canonical::Canonical; use crate::middle::cstore::CrateStoreDyn; use crate::middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem}; use crate::middle::resolve_lifetime::ObjectLifetimeDefault; -use crate::mir::ReadOnlyBodyCache; +use crate::mir::ReadOnlyBodyAndCache; use crate::mir::interpret::{GlobalId, ErrorHandled}; use crate::mir::GeneratorLayout; use crate::session::CrateDisambiguator; @@ -2985,7 +2985,7 @@ impl<'tcx> TyCtxt<'tcx> { } /// Returns the possibly-auto-generated MIR of a `(DefId, Subst)` pair. - pub fn instance_mir(self, instance: ty::InstanceDef<'tcx>) -> ReadOnlyBodyCache<'tcx, 'tcx> { + pub fn instance_mir(self, instance: ty::InstanceDef<'tcx>) -> ReadOnlyBodyAndCache<'tcx, 'tcx> { match instance { ty::InstanceDef::Item(did) => { self.optimized_mir(did).unwrap_read_only() diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index 6dccf329c9f64..bee19457be6de 100644 --- a/src/librustc_codegen_ssa/mir/block.rs +++ b/src/librustc_codegen_ssa/mir/block.rs @@ -153,7 +153,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> { // a loop. fn maybe_sideeffect>( &self, - mir: mir::ReadOnlyBodyCache<'tcx, 'tcx>, + mir: mir::ReadOnlyBodyAndCache<'tcx, 'tcx>, bx: &mut Bx, targets: &[mir::BasicBlock], ) { diff --git a/src/librustc_codegen_ssa/mir/mod.rs b/src/librustc_codegen_ssa/mir/mod.rs index 3a157ca24a470..76b5ab4011183 100644 --- a/src/librustc_codegen_ssa/mir/mod.rs +++ b/src/librustc_codegen_ssa/mir/mod.rs @@ -21,7 +21,7 @@ use self::operand::{OperandRef, OperandValue}; pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> { instance: Instance<'tcx>, - mir: mir::ReadOnlyBodyCache<'tcx, 'tcx>, + mir: mir::ReadOnlyBodyAndCache<'tcx, 'tcx>, debug_context: Option>, diff --git a/src/librustc_metadata/rmeta/decoder.rs b/src/librustc_metadata/rmeta/decoder.rs index 6edd17fe9abef..0107a22772fd2 100644 --- a/src/librustc_metadata/rmeta/decoder.rs +++ b/src/librustc_metadata/rmeta/decoder.rs @@ -18,7 +18,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::svh::Svh; use rustc::dep_graph::{self, DepNodeIndex}; use rustc::middle::lang_items; -use rustc::mir::{self, BodyCache, interpret, Promoted}; +use rustc::mir::{self, BodyAndCache, interpret, Promoted}; use rustc::mir::interpret::{AllocDecodingSession, AllocDecodingState}; use rustc::session::Session; use rustc::ty::{self, Ty, TyCtxt}; @@ -1079,7 +1079,7 @@ impl<'a, 'tcx> CrateMetadata { self.root.per_def.mir.get(self, id).is_some() } - fn get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> BodyCache<'tcx> { + fn get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> BodyAndCache<'tcx> { let mut cache = self.root.per_def.mir.get(self, id) .filter(|_| !self.is_proc_macro(id)) .unwrap_or_else(|| { @@ -1094,7 +1094,7 @@ impl<'a, 'tcx> CrateMetadata { &self, tcx: TyCtxt<'tcx>, id: DefIndex, - ) -> IndexVec> { + ) -> IndexVec> { let mut cache = self.root.per_def.promoted_mir.get(self, id) .filter(|_| !self.is_proc_macro(id)) .unwrap_or_else(|| { diff --git a/src/librustc_metadata/rmeta/mod.rs b/src/librustc_metadata/rmeta/mod.rs index fdf43f06eb10f..5abae4293731d 100644 --- a/src/librustc_metadata/rmeta/mod.rs +++ b/src/librustc_metadata/rmeta/mod.rs @@ -276,8 +276,8 @@ define_per_def_tables! { // Also, as an optimization, a missing entry indicates an empty `&[]`. inferred_outlives: Table, Span)])>, super_predicates: Table)>, - mir: Table)>, - promoted_mir: Table>)>, + mir: Table)>, + promoted_mir: Table>)>, } #[derive(Copy, Clone, RustcEncodable, RustcDecodable)] diff --git a/src/librustc_mir/borrow_check/borrow_set.rs b/src/librustc_mir/borrow_check/borrow_set.rs index 802464ce86b86..2980483bfa4c7 100644 --- a/src/librustc_mir/borrow_check/borrow_set.rs +++ b/src/librustc_mir/borrow_check/borrow_set.rs @@ -5,7 +5,7 @@ use crate::dataflow::indexes::BorrowIndex; use crate::dataflow::move_paths::MoveData; use rustc::mir::traversal; use rustc::mir::visit::{PlaceContext, Visitor, NonUseContext, MutatingUseContext}; -use rustc::mir::{self, Location, Body, Local, ReadOnlyBodyCache}; +use rustc::mir::{self, Location, Body, Local, ReadOnlyBodyAndCache}; use rustc::ty::{RegionVid, TyCtxt}; use rustc::util::nodemap::{FxHashMap, FxHashSet}; use rustc_index::vec::IndexVec; @@ -90,7 +90,7 @@ crate enum LocalsStateAtExit { impl LocalsStateAtExit { fn build( locals_are_invalidated_at_exit: bool, - body: ReadOnlyBodyCache<'_, 'tcx>, + body: ReadOnlyBodyAndCache<'_, 'tcx>, move_data: &MoveData<'tcx> ) -> Self { struct HasStorageDead(BitSet); @@ -124,7 +124,7 @@ impl LocalsStateAtExit { impl<'tcx> BorrowSet<'tcx> { pub fn build( tcx: TyCtxt<'tcx>, - body: ReadOnlyBodyCache<'_, 'tcx>, + body: ReadOnlyBodyAndCache<'_, 'tcx>, locals_are_invalidated_at_exit: bool, move_data: &MoveData<'tcx>, ) -> Self { diff --git a/src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs b/src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs index 6449ae349abf2..016a3195c982d 100644 --- a/src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs @@ -1,6 +1,6 @@ use rustc::hir; use rustc::hir::Node; -use rustc::mir::{self, ClearCrossCrate, Local, LocalInfo, Location, ReadOnlyBodyCache}; +use rustc::mir::{self, ClearCrossCrate, Local, LocalInfo, Location, ReadOnlyBodyAndCache}; use rustc::mir::{Mutability, Place, PlaceRef, PlaceBase, ProjectionElem}; use rustc::ty::{self, Ty, TyCtxt}; use rustc_index::vec::Idx; @@ -533,7 +533,7 @@ fn suggest_ampmut_self<'tcx>( // by trying (3.), then (2.) and finally falling back on (1.). fn suggest_ampmut<'tcx>( tcx: TyCtxt<'tcx>, - body: ReadOnlyBodyCache<'_, 'tcx>, + body: ReadOnlyBodyAndCache<'_, 'tcx>, local: Local, local_decl: &mir::LocalDecl<'tcx>, opt_ty_info: Option, diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index a1932b551c144..427003f24cb14 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -9,8 +9,8 @@ use rustc::lint::builtin::UNUSED_MUT; use rustc::lint::builtin::{MUTABLE_BORROW_RESERVATION_CONFLICT}; use rustc::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind}; use rustc::mir::{ - ClearCrossCrate, Local, Location, Body, BodyCache, Mutability, Operand, Place, PlaceBase, - PlaceElem, PlaceRef, ReadOnlyBodyCache, Static, StaticKind, read_only + ClearCrossCrate, Local, Location, Body, BodyAndCache, Mutability, Operand, Place, PlaceBase, + PlaceElem, PlaceRef, ReadOnlyBodyAndCache, Static, StaticKind, read_only }; use rustc::mir::{Field, ProjectionElem, Promoted, Rvalue, Statement, StatementKind}; use rustc::mir::{Terminator, TerminatorKind}; @@ -99,7 +99,7 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def_id: DefId) -> BorrowCheckResult<'_> { fn do_mir_borrowck<'a, 'tcx>( infcx: &InferCtxt<'a, 'tcx>, input_body: &Body<'tcx>, - input_promoted: &IndexVec>, + input_promoted: &IndexVec>, def_id: DefId, ) -> BorrowCheckResult<'tcx> { debug!("do_mir_borrowck(def_id = {:?})", def_id); @@ -161,7 +161,7 @@ fn do_mir_borrowck<'a, 'tcx>( // will have a lifetime tied to the inference context. let body_clone: Body<'tcx> = input_body.clone(); let mut promoted = input_promoted.clone(); - let mut body = BodyCache::new(body_clone); + let mut body = BodyAndCache::new(body_clone); let free_regions = nll::replace_regions_in_mir(infcx, def_id, param_env, &mut body, &mut promoted); let body = read_only!(body); // no further changes @@ -402,7 +402,7 @@ fn do_mir_borrowck<'a, 'tcx>( crate struct MirBorrowckCtxt<'cx, 'tcx> { crate infcx: &'cx InferCtxt<'cx, 'tcx>, - body: ReadOnlyBodyCache<'cx, 'tcx>, + body: ReadOnlyBodyAndCache<'cx, 'tcx>, mir_def_id: DefId, param_env: ty::ParamEnv<'tcx>, move_data: &'cx MoveData<'tcx>, @@ -493,7 +493,7 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx type FlowState = Flows<'cx, 'tcx>; fn body(&self) -> &'cx Body<'tcx> { - self.body.body() + *self.body } fn visit_block_entry(&mut self, bb: BasicBlock, flow_state: &Self::FlowState) { diff --git a/src/librustc_mir/borrow_check/nll/invalidation.rs b/src/librustc_mir/borrow_check/nll/invalidation.rs index 98679f236db50..2442bdf8a9b4e 100644 --- a/src/librustc_mir/borrow_check/nll/invalidation.rs +++ b/src/librustc_mir/borrow_check/nll/invalidation.rs @@ -11,7 +11,7 @@ use crate::borrow_check::path_utils::*; use crate::dataflow::indexes::BorrowIndex; use rustc::ty::{self, TyCtxt}; use rustc::mir::visit::Visitor; -use rustc::mir::{BasicBlock, Location, Body, Place, ReadOnlyBodyCache, Rvalue}; +use rustc::mir::{BasicBlock, Location, Body, Place, ReadOnlyBodyAndCache, Rvalue}; use rustc::mir::{Statement, StatementKind}; use rustc::mir::TerminatorKind; use rustc::mir::{Operand, BorrowKind}; @@ -22,7 +22,7 @@ pub(super) fn generate_invalidates<'tcx>( param_env: ty::ParamEnv<'tcx>, all_facts: &mut Option, location_table: &LocationTable, - body: ReadOnlyBodyCache<'_, 'tcx>, + body: ReadOnlyBodyAndCache<'_, 'tcx>, borrow_set: &BorrowSet<'tcx>, ) { if all_facts.is_none() { diff --git a/src/librustc_mir/borrow_check/nll/mod.rs b/src/librustc_mir/borrow_check/nll/mod.rs index b9363200cdf28..985d72838fa26 100644 --- a/src/librustc_mir/borrow_check/nll/mod.rs +++ b/src/librustc_mir/borrow_check/nll/mod.rs @@ -12,8 +12,8 @@ use crate::borrow_check::Upvar; use rustc::hir::def_id::DefId; use rustc::infer::InferCtxt; use rustc::mir::{ClosureOutlivesSubject, ClosureRegionRequirements, - Local, Location, Body, BodyCache, LocalKind, BasicBlock, - Promoted, ReadOnlyBodyCache}; + Local, Location, Body, BodyAndCache, LocalKind, BasicBlock, + Promoted, ReadOnlyBodyAndCache}; use rustc::ty::{self, RegionKind, RegionVid}; use rustc_index::vec::IndexVec; use rustc_errors::Diagnostic; @@ -55,8 +55,8 @@ pub(in crate::borrow_check) fn replace_regions_in_mir<'cx, 'tcx>( infcx: &InferCtxt<'cx, 'tcx>, def_id: DefId, param_env: ty::ParamEnv<'tcx>, - body: &mut BodyCache<'tcx>, - promoted: &mut IndexVec>, + body: &mut BodyAndCache<'tcx>, + promoted: &mut IndexVec>, ) -> UniversalRegions<'tcx> { debug!("replace_regions_in_mir(def_id={:?})", def_id); @@ -158,8 +158,8 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>( infcx: &InferCtxt<'cx, 'tcx>, def_id: DefId, universal_regions: UniversalRegions<'tcx>, - body: ReadOnlyBodyCache<'_, 'tcx>, - promoted: &IndexVec>, + body: ReadOnlyBodyAndCache<'_, 'tcx>, + promoted: &IndexVec>, local_names: &IndexVec>, upvars: &[Upvar], location_table: &LocationTable, diff --git a/src/librustc_mir/borrow_check/nll/region_infer/values.rs b/src/librustc_mir/borrow_check/nll/region_infer/values.rs index b4414c514c532..0bf0cd37cd843 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/values.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/values.rs @@ -1,4 +1,4 @@ -use rustc::mir::{BasicBlock, Location, Body, ReadOnlyBodyCache}; +use rustc::mir::{BasicBlock, Location, Body, ReadOnlyBodyAndCache}; use rustc::ty::{self, RegionVid}; use rustc_index::bit_set::{HybridBitSet, SparseBitMatrix}; use rustc_data_structures::fx::FxHashMap; @@ -92,7 +92,7 @@ impl RegionValueElements { /// Pushes all predecessors of `index` onto `stack`. crate fn push_predecessors( &self, - body: ReadOnlyBodyCache<'_, '_>, + body: ReadOnlyBodyAndCache<'_, '_>, index: PointIndex, stack: &mut Vec, ) { diff --git a/src/librustc_mir/borrow_check/nll/renumber.rs b/src/librustc_mir/borrow_check/nll/renumber.rs index db15d2c54fdbc..ba323b113e9eb 100644 --- a/src/librustc_mir/borrow_check/nll/renumber.rs +++ b/src/librustc_mir/borrow_check/nll/renumber.rs @@ -1,6 +1,6 @@ use rustc::ty::subst::SubstsRef; use rustc::ty::{self, Ty, TyCtxt, TypeFoldable}; -use rustc::mir::{BodyCache, Location, PlaceElem, Promoted}; +use rustc::mir::{BodyAndCache, Location, PlaceElem, Promoted}; use rustc::mir::visit::{MutVisitor, TyContext}; use rustc::infer::{InferCtxt, NLLRegionVariableOrigin}; use rustc_index::vec::IndexVec; @@ -9,8 +9,8 @@ use rustc_index::vec::IndexVec; /// inference variables, returning the number of variables created. pub fn renumber_mir<'tcx>( infcx: &InferCtxt<'_, 'tcx>, - body: &mut BodyCache<'tcx>, - promoted: &mut IndexVec>, + body: &mut BodyAndCache<'tcx>, + promoted: &mut IndexVec>, ) { debug!("renumber_mir()"); debug!("renumber_mir: body.arg_count={:?}", body.arg_count); diff --git a/src/librustc_mir/borrow_check/nll/type_check/liveness/local_use_map.rs b/src/librustc_mir/borrow_check/nll/type_check/liveness/local_use_map.rs index d6aa31449daa7..ab8c6f279733b 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/liveness/local_use_map.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/liveness/local_use_map.rs @@ -1,7 +1,7 @@ use crate::borrow_check::nll::region_infer::values::{PointIndex, RegionValueElements}; use crate::util::liveness::{categorize, DefUse}; use rustc::mir::visit::{PlaceContext, Visitor}; -use rustc::mir::{Local, Location, ReadOnlyBodyCache}; +use rustc::mir::{Local, Location, ReadOnlyBodyAndCache}; use rustc_index::vec::{Idx, IndexVec}; use rustc_data_structures::vec_linked_list as vll; @@ -60,7 +60,7 @@ impl LocalUseMap { crate fn build( live_locals: &Vec, elements: &RegionValueElements, - body: ReadOnlyBodyCache<'_, '_>, + body: ReadOnlyBodyAndCache<'_, '_>, ) -> Self { let nones = IndexVec::from_elem_n(None, body.local_decls.len()); let mut local_use_map = LocalUseMap { diff --git a/src/librustc_mir/borrow_check/nll/type_check/liveness/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/liveness/mod.rs index dfd505f6b613a..8f8e9af797963 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/liveness/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/liveness/mod.rs @@ -7,7 +7,7 @@ use crate::borrow_check::nll::ToRegionVid; use crate::dataflow::move_paths::MoveData; use crate::dataflow::FlowAtLocation; use crate::dataflow::MaybeInitializedPlaces; -use rustc::mir::{Body, Local, ReadOnlyBodyCache}; +use rustc::mir::{Body, Local, ReadOnlyBodyAndCache}; use rustc::ty::{RegionVid, TyCtxt}; use rustc_data_structures::fx::FxHashSet; use std::rc::Rc; @@ -28,7 +28,7 @@ mod trace; /// performed before pub(super) fn generate<'tcx>( typeck: &mut TypeChecker<'_, 'tcx>, - body: ReadOnlyBodyCache<'_, 'tcx>, + body: ReadOnlyBodyAndCache<'_, 'tcx>, elements: &Rc, flow_inits: &mut FlowAtLocation<'tcx, MaybeInitializedPlaces<'_, 'tcx>>, move_data: &MoveData<'tcx>, diff --git a/src/librustc_mir/borrow_check/nll/type_check/liveness/polonius.rs b/src/librustc_mir/borrow_check/nll/type_check/liveness/polonius.rs index e67de6c99f026..810811f9f5cf3 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/liveness/polonius.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/liveness/polonius.rs @@ -3,7 +3,7 @@ use crate::dataflow::indexes::MovePathIndex; use crate::dataflow::move_paths::{LookupResult, MoveData}; use crate::util::liveness::{categorize, DefUse}; use rustc::mir::visit::{MutatingUseContext, PlaceContext, Visitor}; -use rustc::mir::{Local, Location, Place, ReadOnlyBodyCache}; +use rustc::mir::{Local, Location, Place, ReadOnlyBodyAndCache}; use rustc::ty::subst::GenericArg; use rustc::ty::Ty; @@ -97,7 +97,7 @@ fn add_var_uses_regions(typeck: &mut TypeChecker<'_, 'tcx>, local: Local, ty: Ty pub(super) fn populate_access_facts( typeck: &mut TypeChecker<'_, 'tcx>, - body: ReadOnlyBodyCache<'_, 'tcx>, + body: ReadOnlyBodyAndCache<'_, 'tcx>, location_table: &LocationTable, move_data: &MoveData<'_>, drop_used: &mut Vec<(Local, Location)>, diff --git a/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs b/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs index 229cbed64c272..bdd7c84fcd7dc 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs @@ -7,7 +7,7 @@ use crate::dataflow::indexes::MovePathIndex; use crate::dataflow::move_paths::MoveData; use crate::dataflow::{FlowAtLocation, FlowsAtLocation, MaybeInitializedPlaces}; use rustc::infer::canonical::QueryRegionConstraints; -use rustc::mir::{BasicBlock, ConstraintCategory, Local, Location, ReadOnlyBodyCache}; +use rustc::mir::{BasicBlock, ConstraintCategory, Local, Location, ReadOnlyBodyAndCache}; use rustc::traits::query::dropck_outlives::DropckOutlivesResult; use rustc::traits::query::type_op::outlives::DropckOutlives; use rustc::traits::query::type_op::TypeOp; @@ -32,7 +32,7 @@ use std::rc::Rc; /// this respects `#[may_dangle]` annotations). pub(super) fn trace( typeck: &mut TypeChecker<'_, 'tcx>, - body: ReadOnlyBodyCache<'_, 'tcx>, + body: ReadOnlyBodyAndCache<'_, 'tcx>, elements: &Rc, flow_inits: &mut FlowAtLocation<'tcx, MaybeInitializedPlaces<'_, 'tcx>>, move_data: &MoveData<'tcx>, @@ -71,7 +71,7 @@ struct LivenessContext<'me, 'typeck, 'flow, 'tcx> { elements: &'me RegionValueElements, /// MIR we are analyzing. - body: ReadOnlyBodyCache<'me, 'tcx>, + body: ReadOnlyBodyAndCache<'me, 'tcx>, /// Mapping to/from the various indices used for initialization tracking. move_data: &'me MoveData<'tcx>, diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index de304202a0840..8d4e76cadbfc2 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -117,8 +117,8 @@ mod relate_tys; pub(crate) fn type_check<'tcx>( infcx: &InferCtxt<'_, 'tcx>, param_env: ty::ParamEnv<'tcx>, - body: ReadOnlyBodyCache<'_, 'tcx>, - promoted: &IndexVec>, + body: ReadOnlyBodyAndCache<'_, 'tcx>, + promoted: &IndexVec>, mir_def_id: DefId, universal_regions: &Rc>, location_table: &LocationTable, @@ -196,8 +196,8 @@ fn type_check_internal<'a, 'tcx, R>( infcx: &'a InferCtxt<'a, 'tcx>, mir_def_id: DefId, param_env: ty::ParamEnv<'tcx>, - body: ReadOnlyBodyCache<'a, 'tcx>, - promoted: &'a IndexVec>, + body: ReadOnlyBodyAndCache<'a, 'tcx>, + promoted: &'a IndexVec>, region_bound_pairs: &'a RegionBoundPairs<'tcx>, implicit_region_bound: ty::Region<'tcx>, borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>, @@ -206,7 +206,7 @@ fn type_check_internal<'a, 'tcx, R>( ) -> R { let mut checker = TypeChecker::new( infcx, - body.body(), + *body, mir_def_id, param_env, region_bound_pairs, @@ -215,7 +215,7 @@ fn type_check_internal<'a, 'tcx, R>( universal_region_relations, ); let errors_reported = { - let mut verifier = TypeVerifier::new(&mut checker, body.body(), promoted); + let mut verifier = TypeVerifier::new(&mut checker, *body, promoted); verifier.visit_body(body); verifier.errors_reported }; @@ -272,7 +272,7 @@ enum FieldAccessError { struct TypeVerifier<'a, 'b, 'tcx> { cx: &'a mut TypeChecker<'b, 'tcx>, body: &'b Body<'tcx>, - promoted: &'b IndexVec>, + promoted: &'b IndexVec>, last_span: Span, mir_def_id: DefId, errors_reported: bool, @@ -396,7 +396,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { } } - fn visit_body(&mut self, body: ReadOnlyBodyCache<'_, 'tcx>) { + fn visit_body(&mut self, body: ReadOnlyBodyAndCache<'_, 'tcx>) { self.sanitize_type(&"return type", body.return_ty()); for local_decl in &body.local_decls { self.sanitize_type(local_decl, local_decl.ty); @@ -412,7 +412,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { fn new( cx: &'a mut TypeChecker<'b, 'tcx>, body: &'b Body<'tcx>, - promoted: &'b IndexVec>, + promoted: &'b IndexVec>, ) -> Self { TypeVerifier { body, @@ -548,14 +548,14 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { fn sanitize_promoted( &mut self, - promoted_body: ReadOnlyBodyCache<'b, 'tcx>, + promoted_body: ReadOnlyBodyAndCache<'b, 'tcx>, location: Location ) { // Determine the constraints from the promoted MIR by running the type // checker on the promoted MIR, then transfer the constraints back to // the main MIR, changing the locations to the provided location. - let parent_body = mem::replace(&mut self.body, promoted_body.body()); + let parent_body = mem::replace(&mut self.body, *promoted_body); // Use new sets of constraints and closure bounds so that we can // modify their locations. @@ -1378,7 +1378,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { fn check_stmt( &mut self, - body: ReadOnlyBodyCache<'_, 'tcx>, + body: ReadOnlyBodyAndCache<'_, 'tcx>, stmt: &Statement<'tcx>, location: Location) { @@ -1994,7 +1994,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { fn check_rvalue( &mut self, - body: ReadOnlyBodyCache<'_, 'tcx>, + body: ReadOnlyBodyAndCache<'_, 'tcx>, rvalue: &Rvalue<'tcx>, location: Location) { @@ -2766,7 +2766,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { }) } - fn typeck_mir(&mut self, body: ReadOnlyBodyCache<'_, 'tcx>) { + fn typeck_mir(&mut self, body: ReadOnlyBodyAndCache<'_, 'tcx>) { self.last_span = body.span; debug!("run_on_mir: {:?}", body.span); diff --git a/src/librustc_mir/borrow_check/prefixes.rs b/src/librustc_mir/borrow_check/prefixes.rs index b58bf737a3575..248faa56777de 100644 --- a/src/librustc_mir/borrow_check/prefixes.rs +++ b/src/librustc_mir/borrow_check/prefixes.rs @@ -11,7 +11,7 @@ use super::MirBorrowckCtxt; use rustc::hir; use rustc::ty::{self, TyCtxt}; -use rustc::mir::{Place, PlaceBase, PlaceRef, ProjectionElem, ReadOnlyBodyCache}; +use rustc::mir::{Place, PlaceBase, PlaceRef, ProjectionElem, ReadOnlyBodyAndCache}; pub trait IsPrefixOf<'cx, 'tcx> { fn is_prefix_of(&self, other: PlaceRef<'cx, 'tcx>) -> bool; @@ -26,7 +26,7 @@ impl<'cx, 'tcx> IsPrefixOf<'cx, 'tcx> for PlaceRef<'cx, 'tcx> { } pub(super) struct Prefixes<'cx, 'tcx> { - body: ReadOnlyBodyCache<'cx, 'tcx>, + body: ReadOnlyBodyAndCache<'cx, 'tcx>, tcx: TyCtxt<'tcx>, kind: PrefixSet, next: Option>, diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index b84461d6b9275..0009eb45cc035 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -24,7 +24,7 @@ use syntax_pos::Span; use super::lints; /// Construct the MIR for a given `DefId`. -pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> BodyCache<'_> { +pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> BodyAndCache<'_> { let id = tcx.hir().as_local_hir_id(def_id).unwrap(); // Figure out what primary body this item has. @@ -196,7 +196,7 @@ pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> BodyCache<'_> { lints::check(tcx, &body, def_id); - let mut body = BodyCache::new(body); + let mut body = BodyAndCache::new(body); body.ensure_predecessors(); body }) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 968a8a71ba0ba..697ef58b0aa05 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -366,7 +366,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, } // This is a const fn. Call it. Ok(Some(match ecx.load_mir(instance.def, None) { - Ok(body) => body.body(), + Ok(body) => *body, Err(err) => { if let err_unsup!(NoMirFor(ref path)) = err.kind { return Err( @@ -743,7 +743,7 @@ pub fn const_eval_raw_provider<'tcx>( let res = ecx.load_mir(cid.instance.def, cid.promoted); res.and_then( - |body| eval_body_using_ecx(&mut ecx, cid, body.body()) + |body| eval_body_using_ecx(&mut ecx, cid, *body) ).and_then(|place| { Ok(RawConst { alloc_id: place.ptr.assert_ptr().alloc_id, diff --git a/src/librustc_mir/dataflow/impls/storage_liveness.rs b/src/librustc_mir/dataflow/impls/storage_liveness.rs index c4b97d12e6270..b8abe6d70edbd 100644 --- a/src/librustc_mir/dataflow/impls/storage_liveness.rs +++ b/src/librustc_mir/dataflow/impls/storage_liveness.rs @@ -75,20 +75,20 @@ impl<'a, 'tcx> BottomValue for MaybeStorageLive<'a, 'tcx> { /// Dataflow analysis that determines whether each local requires storage at a /// given location; i.e. whether its storage can go away without being observed. pub struct RequiresStorage<'mir, 'tcx> { - body: ReadOnlyBodyCache<'mir, 'tcx>, + body: ReadOnlyBodyAndCache<'mir, 'tcx>, borrowed_locals: RefCell>>, } impl<'mir, 'tcx: 'mir> RequiresStorage<'mir, 'tcx> { pub fn new( - body: ReadOnlyBodyCache<'mir, 'tcx>, + body: ReadOnlyBodyAndCache<'mir, 'tcx>, borrowed_locals: &'mir DataflowResults<'tcx, HaveBeenBorrowedLocals<'mir, 'tcx>>, ) -> Self { RequiresStorage { body, borrowed_locals: RefCell::new( - DataflowResultsCursor::new(borrowed_locals, body.body()) + DataflowResultsCursor::new(borrowed_locals, *body) ), } } diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 9af47f3e77f93..653718c462f07 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -312,7 +312,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { &self, instance: ty::InstanceDef<'tcx>, promoted: Option, - ) -> InterpResult<'tcx, mir::ReadOnlyBodyCache<'tcx, 'tcx>> { + ) -> InterpResult<'tcx, mir::ReadOnlyBodyAndCache<'tcx, 'tcx>> { // do not continue if typeck errors occurred (can only occur in local crate) let did = instance.def_id(); if did.is_local() diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 5b208dd858763..5fe47c45b15ac 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -26,7 +26,7 @@ pub fn provide(providers: &mut Providers<'_>) { providers.mir_shims = make_shim; } -fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx BodyCache<'tcx> { +fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx BodyAndCache<'tcx> { debug!("make_shim({:?})", instance); let mut result = match instance { @@ -170,7 +170,7 @@ fn local_decls_for_sig<'tcx>(sig: &ty::FnSig<'tcx>, span: Span) fn build_drop_shim<'tcx>( tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option> -) -> BodyCache<'tcx> { +) -> BodyAndCache<'tcx> { debug!("build_drop_shim(def_id={:?}, ty={:?})", def_id, ty); // Check if this is a generator, if so, return the drop glue for it @@ -208,7 +208,7 @@ fn build_drop_shim<'tcx>( sig.inputs().len(), span); - let mut body = BodyCache::new(body); + let mut body = BodyAndCache::new(body); if let Some(..) = ty { // The first argument (index 0), but add 1 for the return value. @@ -322,7 +322,7 @@ impl<'a, 'tcx> DropElaborator<'a, 'tcx> for DropShimElaborator<'a, 'tcx> { } /// Builds a `Clone::clone` shim for `self_ty`. Here, `def_id` is `Clone::clone`. -fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -> BodyCache<'tcx> { +fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -> BodyAndCache<'tcx> { debug!("build_clone_shim(def_id={:?})", def_id); let param_env = tcx.param_env(def_id); @@ -351,7 +351,7 @@ fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) - } }; - BodyCache::new(builder.into_mir()) + BodyAndCache::new(builder.into_mir()) } struct CloneShimBuilder<'tcx> { @@ -712,7 +712,7 @@ fn build_call_shim<'tcx>( rcvr_adjustment: Adjustment, call_kind: CallKind, untuple_args: Option<&[Ty<'tcx>]>, -) -> BodyCache<'tcx> { +) -> BodyAndCache<'tcx> { debug!("build_call_shim(instance={:?}, rcvr_adjustment={:?}, \ call_kind={:?}, untuple_args={:?})", instance, rcvr_adjustment, call_kind, untuple_args); @@ -853,10 +853,10 @@ fn build_call_shim<'tcx>( if let Abi::RustCall = sig.abi { body.spread_arg = Some(Local::new(sig.inputs().len())); } - BodyCache::new(body) + BodyAndCache::new(body) } -pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> &BodyCache<'_> { +pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> &BodyAndCache<'_> { debug_assert!(tcx.is_constructor(ctor_id)); let span = tcx.hir().span_if_local(ctor_id) @@ -940,7 +940,7 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> &BodyCache<'_> { |_, _| Ok(()), ); - let mut body = BodyCache::new(body); + let mut body = BodyAndCache::new(body); body.ensure_predecessors(); tcx.arena.alloc(body) } diff --git a/src/librustc_mir/transform/add_call_guards.rs b/src/librustc_mir/transform/add_call_guards.rs index 35238e2d08a2e..d1832ebf962a4 100644 --- a/src/librustc_mir/transform/add_call_guards.rs +++ b/src/librustc_mir/transform/add_call_guards.rs @@ -32,14 +32,14 @@ pub use self::AddCallGuards::*; impl<'tcx> MirPass<'tcx> for AddCallGuards { fn run_pass( - &self, _tcx: TyCtxt<'tcx>, _src: MirSource<'tcx>, body: &mut BodyCache<'tcx> + &self, _tcx: TyCtxt<'tcx>, _src: MirSource<'tcx>, body: &mut BodyAndCache<'tcx> ) { self.add_call_guards(body); } } impl AddCallGuards { - pub fn add_call_guards(&self, body: &mut BodyCache<'_>) { + pub fn add_call_guards(&self, body: &mut BodyAndCache<'_>) { let pred_count: IndexVec<_, _> = body.predecessors().iter().map(|ps| ps.len()).collect(); // We need a place to store the new blocks generated diff --git a/src/librustc_mir/transform/add_moves_for_packed_drops.rs b/src/librustc_mir/transform/add_moves_for_packed_drops.rs index 98c6a5ed07780..861e7fea4f903 100644 --- a/src/librustc_mir/transform/add_moves_for_packed_drops.rs +++ b/src/librustc_mir/transform/add_moves_for_packed_drops.rs @@ -40,14 +40,14 @@ use crate::util; pub struct AddMovesForPackedDrops; impl<'tcx> MirPass<'tcx> for AddMovesForPackedDrops { - fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { debug!("add_moves_for_packed_drops({:?} @ {:?})", src, body.span); add_moves_for_packed_drops(tcx, body, src.def_id()); } } pub fn add_moves_for_packed_drops<'tcx>( - tcx: TyCtxt<'tcx>, body: &mut BodyCache<'tcx>, def_id: DefId + tcx: TyCtxt<'tcx>, body: &mut BodyAndCache<'tcx>, def_id: DefId ) { let patch = add_moves_for_packed_drops_patch(tcx, body, def_id); patch.apply(body); diff --git a/src/librustc_mir/transform/add_retag.rs b/src/librustc_mir/transform/add_retag.rs index e6ad37ae11362..dc21c674eea2f 100644 --- a/src/librustc_mir/transform/add_retag.rs +++ b/src/librustc_mir/transform/add_retag.rs @@ -59,7 +59,7 @@ fn may_be_reference<'tcx>(ty: Ty<'tcx>) -> bool { } impl<'tcx> MirPass<'tcx> for AddRetag { - fn run_pass(&self, tcx: TyCtxt<'tcx>, _src: MirSource<'tcx>, body: &mut BodyCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _src: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { if !tcx.sess.opts.debugging_opts.mir_emit_retag { return; } diff --git a/src/librustc_mir/transform/check_consts/mod.rs b/src/librustc_mir/transform/check_consts/mod.rs index 82ffafbedf858..89672e81c7cd4 100644 --- a/src/librustc_mir/transform/check_consts/mod.rs +++ b/src/librustc_mir/transform/check_consts/mod.rs @@ -20,7 +20,7 @@ pub mod validation; /// Information about the item currently being const-checked, as well as a reference to the global /// context. pub struct Item<'mir, 'tcx> { - pub body: mir::ReadOnlyBodyCache<'mir, 'tcx>, + pub body: mir::ReadOnlyBodyAndCache<'mir, 'tcx>, pub tcx: TyCtxt<'tcx>, pub def_id: DefId, pub param_env: ty::ParamEnv<'tcx>, @@ -31,7 +31,7 @@ impl Item<'mir, 'tcx> { pub fn new( tcx: TyCtxt<'tcx>, def_id: DefId, - body: mir::ReadOnlyBodyCache<'mir, 'tcx>, + body: mir::ReadOnlyBodyAndCache<'mir, 'tcx>, ) -> Self { let param_env = tcx.param_env(def_id); let const_kind = ConstKind::for_item(tcx, def_id); diff --git a/src/librustc_mir/transform/check_consts/validation.rs b/src/librustc_mir/transform/check_consts/validation.rs index f44bac126f276..4f45e3bb0c96d 100644 --- a/src/librustc_mir/transform/check_consts/validation.rs +++ b/src/librustc_mir/transform/check_consts/validation.rs @@ -40,7 +40,7 @@ impl QualifCursor<'a, 'mir, 'tcx, Q> { let results = dataflow::Engine::new(item.tcx, &item.body, item.def_id, dead_unwinds, analysis) .iterate_to_fixpoint(); - let cursor = dataflow::ResultsCursor::new(item.body.body(), results); + let cursor = dataflow::ResultsCursor::new(*item.body, results); let mut in_any_value_of_ty = BitSet::new_empty(item.body.local_decls.len()); for (local, decl) in item.body.local_decls.iter_enumerated() { @@ -175,13 +175,13 @@ impl Validator<'a, 'mir, 'tcx> { item.def_id, &item.tcx.get_attrs(item.def_id), &dead_unwinds, - old_dataflow::IndirectlyMutableLocals::new(item.tcx, item.body.body(), item.param_env), + old_dataflow::IndirectlyMutableLocals::new(item.tcx, *item.body, item.param_env), |_, local| old_dataflow::DebugFormatted::new(&local), ); let indirectly_mutable = old_dataflow::DataflowResultsCursor::new( indirectly_mutable, - item.body.body(), + *item.body, ); let qualifs = Qualifs { diff --git a/src/librustc_mir/transform/cleanup_post_borrowck.rs b/src/librustc_mir/transform/cleanup_post_borrowck.rs index d9dd7c9d84776..34519bc9fa627 100644 --- a/src/librustc_mir/transform/cleanup_post_borrowck.rs +++ b/src/librustc_mir/transform/cleanup_post_borrowck.rs @@ -16,7 +16,7 @@ //! [`FakeRead`]: rustc::mir::StatementKind::FakeRead //! [`Nop`]: rustc::mir::StatementKind::Nop -use rustc::mir::{BodyCache, BorrowKind, Rvalue, Location}; +use rustc::mir::{BodyAndCache, BorrowKind, Rvalue, Location}; use rustc::mir::{Statement, StatementKind}; use rustc::mir::visit::MutVisitor; use rustc::ty::TyCtxt; @@ -30,7 +30,7 @@ pub struct DeleteNonCodegenStatements<'tcx> { impl<'tcx> MirPass<'tcx> for CleanupNonCodegenStatements { fn run_pass( - &self, tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, body: &mut BodyCache<'tcx> + &self, tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx> ) { let mut delete = DeleteNonCodegenStatements { tcx }; delete.visit_body(body); diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 95de635d634e4..884312514e47e 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -7,9 +7,9 @@ use std::cell::Cell; use rustc::hir::def::DefKind; use rustc::hir::def_id::DefId; use rustc::mir::{ - AggregateKind, Constant, Location, Place, PlaceBase, Body, BodyCache, Operand, Local, UnOp, - Rvalue, StatementKind, Statement, LocalKind, TerminatorKind, Terminator, ClearCrossCrate, - SourceInfo, BinOp, SourceScope, SourceScopeData, LocalDecl, BasicBlock, ReadOnlyBodyCache, + AggregateKind, Constant, Location, Place, PlaceBase, Body, BodyAndCache, Operand, Local, UnOp, + Rvalue, StatementKind, Statement, LocalKind, TerminatorKind, Terminator, ClearCrossCrate, + SourceInfo, BinOp, SourceScope, SourceScopeData, LocalDecl, BasicBlock, ReadOnlyBodyAndCache, read_only, RETURN_PLACE }; use rustc::mir::visit::{ @@ -43,7 +43,7 @@ pub struct ConstProp; impl<'tcx> MirPass<'tcx> for ConstProp { fn run_pass( - &self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut BodyCache<'tcx> + &self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx> ) { // will be evaluated by miri and produce its errors there if source.promoted.is_some() { @@ -296,7 +296,7 @@ impl<'mir, 'tcx> HasTyCtxt<'tcx> for ConstPropagator<'mir, 'tcx> { impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { fn new( - body: ReadOnlyBodyCache<'_, 'tcx>, + body: ReadOnlyBodyAndCache<'_, 'tcx>, dummy_body: &'mir Body<'tcx>, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, @@ -690,7 +690,7 @@ struct CanConstProp { impl CanConstProp { /// returns true if `local` can be propagated - fn check(body: ReadOnlyBodyCache<'_, '_>) -> IndexVec { + fn check(body: ReadOnlyBodyAndCache<'_, '_>) -> IndexVec { let mut cpv = CanConstProp { can_const_prop: IndexVec::from_elem(true, &body.local_decls), found_assignment: IndexVec::from_elem(false, &body.local_decls), diff --git a/src/librustc_mir/transform/copy_prop.rs b/src/librustc_mir/transform/copy_prop.rs index 5e4caf2f36d2d..272f6e9ce1937 100644 --- a/src/librustc_mir/transform/copy_prop.rs +++ b/src/librustc_mir/transform/copy_prop.rs @@ -20,7 +20,7 @@ //! future. use rustc::mir::{ - Constant, Local, LocalKind, Location, Place, Body, BodyCache, Operand, Rvalue, + Constant, Local, LocalKind, Location, Place, Body, BodyAndCache, Operand, Rvalue, StatementKind, read_only }; use rustc::mir::visit::MutVisitor; @@ -32,7 +32,7 @@ pub struct CopyPropagation; impl<'tcx> MirPass<'tcx> for CopyPropagation { fn run_pass( - &self, tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, body: &mut BodyCache<'tcx> + &self, tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx> ) { // We only run when the MIR optimization level is > 1. // This avoids a slow pass, and messing up debug info. @@ -250,7 +250,7 @@ impl<'tcx> Action<'tcx> { } fn perform(self, - body: &mut BodyCache<'tcx>, + body: &mut BodyAndCache<'tcx>, def_use_analysis: &DefUseAnalysis, dest_local: Local, location: Location, diff --git a/src/librustc_mir/transform/deaggregator.rs b/src/librustc_mir/transform/deaggregator.rs index 933936e7efff7..cd77c9c60fa5a 100644 --- a/src/librustc_mir/transform/deaggregator.rs +++ b/src/librustc_mir/transform/deaggregator.rs @@ -7,7 +7,7 @@ pub struct Deaggregator; impl<'tcx> MirPass<'tcx> for Deaggregator { fn run_pass( - &self, tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, body: &mut BodyCache<'tcx> + &self, tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx> ) { let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut(); let local_decls = &*local_decls; diff --git a/src/librustc_mir/transform/dump_mir.rs b/src/librustc_mir/transform/dump_mir.rs index 13b3bb6da4ef9..221ced3a71c4b 100644 --- a/src/librustc_mir/transform/dump_mir.rs +++ b/src/librustc_mir/transform/dump_mir.rs @@ -5,7 +5,7 @@ use std::fmt; use std::fs::File; use std::io; -use rustc::mir::{Body, BodyCache}; +use rustc::mir::{Body, BodyAndCache}; use rustc::session::config::{OutputFilenames, OutputType}; use rustc::ty::TyCtxt; use crate::transform::{MirPass, MirSource}; @@ -19,7 +19,7 @@ impl<'tcx> MirPass<'tcx> for Marker { } fn run_pass( - &self, _tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, _body: &mut BodyCache<'tcx> + &self, _tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, _body: &mut BodyAndCache<'tcx> ) {} } diff --git a/src/librustc_mir/transform/elaborate_drops.rs b/src/librustc_mir/transform/elaborate_drops.rs index 42daba93bd293..9970752a37698 100644 --- a/src/librustc_mir/transform/elaborate_drops.rs +++ b/src/librustc_mir/transform/elaborate_drops.rs @@ -21,7 +21,7 @@ use syntax_pos::Span; pub struct ElaborateDrops; impl<'tcx> MirPass<'tcx> for ElaborateDrops { - fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { debug!("elaborate_drops({:?} @ {:?})", src, body.span); let def_id = src.def_id(); diff --git a/src/librustc_mir/transform/erase_regions.rs b/src/librustc_mir/transform/erase_regions.rs index 882e67432a5ed..1eef3f254f053 100644 --- a/src/librustc_mir/transform/erase_regions.rs +++ b/src/librustc_mir/transform/erase_regions.rs @@ -62,7 +62,7 @@ impl MutVisitor<'tcx> for EraseRegionsVisitor<'tcx> { pub struct EraseRegions; impl<'tcx> MirPass<'tcx> for EraseRegions { - fn run_pass(&self, tcx: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut BodyCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { EraseRegionsVisitor::new(tcx).visit_body(body); } } diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index e55737e8859ef..3d15d04717211 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -378,7 +378,7 @@ impl MutVisitor<'tcx> for TransformVisitor<'tcx> { fn make_generator_state_argument_indirect<'tcx>( tcx: TyCtxt<'tcx>, def_id: DefId, - body: &mut BodyCache<'tcx>, + body: &mut BodyAndCache<'tcx>, ) { let gen_ty = body.local_decls.raw[1].ty; @@ -401,7 +401,7 @@ fn make_generator_state_argument_indirect<'tcx>( DerefArgVisitor { tcx }.visit_body(body); } -fn make_generator_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut BodyCache<'tcx>) { +fn make_generator_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut BodyAndCache<'tcx>) { let ref_gen_ty = body.local_decls.raw[1].ty; let pin_did = tcx.lang_items().pin_type().unwrap(); @@ -418,7 +418,7 @@ fn make_generator_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body fn replace_result_variable<'tcx>( ret_ty: Ty<'tcx>, - body: &mut BodyCache<'tcx>, + body: &mut BodyAndCache<'tcx>, tcx: TyCtxt<'tcx>, ) -> Local { let source_info = source_info(body); @@ -481,7 +481,7 @@ struct LivenessInfo { fn locals_live_across_suspend_points( tcx: TyCtxt<'tcx>, - body: ReadOnlyBodyCache<'_, 'tcx>, + body: ReadOnlyBodyAndCache<'_, 'tcx>, source: MirSource<'tcx>, movable: bool, ) -> LivenessInfo { @@ -751,7 +751,7 @@ fn compute_layout<'tcx>( upvars: &Vec>, interior: Ty<'tcx>, movable: bool, - body: &mut BodyCache<'tcx>, + body: &mut BodyAndCache<'tcx>, ) -> ( FxHashMap, VariantIdx, usize)>, GeneratorLayout<'tcx>, @@ -830,7 +830,7 @@ fn compute_layout<'tcx>( } fn insert_switch<'tcx>( - body: &mut BodyCache<'tcx>, + body: &mut BodyAndCache<'tcx>, cases: Vec<(usize, BasicBlock)>, transform: &TransformVisitor<'tcx>, default: TerminatorKind<'tcx>, @@ -862,7 +862,7 @@ fn insert_switch<'tcx>( } fn elaborate_generator_drops<'tcx>( - tcx: TyCtxt<'tcx>, def_id: DefId, body: &mut BodyCache<'tcx> + tcx: TyCtxt<'tcx>, def_id: DefId, body: &mut BodyAndCache<'tcx> ) { use crate::util::elaborate_drops::{elaborate_drop, Unwind}; use crate::util::patch::MirPatch; @@ -928,9 +928,9 @@ fn create_generator_drop_shim<'tcx>( def_id: DefId, source: MirSource<'tcx>, gen_ty: Ty<'tcx>, - body: &mut BodyCache<'tcx>, + body: &mut BodyAndCache<'tcx>, drop_clean: BasicBlock, -) -> BodyCache<'tcx> { +) -> BodyAndCache<'tcx> { let mut body = body.clone(); let source_info = source_info(&body); @@ -997,7 +997,7 @@ fn create_generator_drop_shim<'tcx>( } fn insert_term_block<'tcx>( - body: &mut BodyCache<'tcx>, kind: TerminatorKind<'tcx> + body: &mut BodyAndCache<'tcx>, kind: TerminatorKind<'tcx> ) -> BasicBlock { let term_block = BasicBlock::new(body.basic_blocks().len()); let source_info = source_info(body); @@ -1014,7 +1014,7 @@ fn insert_term_block<'tcx>( fn insert_panic_block<'tcx>( tcx: TyCtxt<'tcx>, - body: &mut BodyCache<'tcx>, + body: &mut BodyAndCache<'tcx>, message: AssertMessage<'tcx>, ) -> BasicBlock { let assert_block = BasicBlock::new(body.basic_blocks().len()); @@ -1048,7 +1048,7 @@ fn create_generator_resume_function<'tcx>( transform: TransformVisitor<'tcx>, def_id: DefId, source: MirSource<'tcx>, - body: &mut BodyCache<'tcx>, + body: &mut BodyAndCache<'tcx>, ) { // Poison the generator when it unwinds for block in body.basic_blocks_mut() { @@ -1101,7 +1101,7 @@ fn source_info(body: &Body<'_>) -> SourceInfo { } } -fn insert_clean_drop(body: &mut BodyCache<'_>) -> BasicBlock { +fn insert_clean_drop(body: &mut BodyAndCache<'_>) -> BasicBlock { let return_block = insert_term_block(body, TerminatorKind::Return); // Create a block to destroy an unresumed generators. This can only destroy upvars. @@ -1125,7 +1125,7 @@ fn insert_clean_drop(body: &mut BodyCache<'_>) -> BasicBlock { } fn create_cases<'tcx, F>( - body: &mut BodyCache<'tcx>, + body: &mut BodyAndCache<'tcx>, transform: &TransformVisitor<'tcx>, target: F, ) -> Vec<(usize, BasicBlock)> @@ -1170,7 +1170,7 @@ where impl<'tcx> MirPass<'tcx> for StateTransform { fn run_pass( - &self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut BodyCache<'tcx> + &self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx> ) { let yield_ty = if let Some(yield_ty) = body.yield_ty { yield_ty diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 79cb7fb0b7692..05b58d2e49bf1 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -39,7 +39,7 @@ struct CallSite<'tcx> { impl<'tcx> MirPass<'tcx> for Inline { fn run_pass( - &self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut BodyCache<'tcx> + &self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx> ) { if tcx.sess.opts.debugging_opts.mir_opt_level >= 2 { Inliner { tcx, source }.run_pass(body); @@ -53,7 +53,7 @@ struct Inliner<'tcx> { } impl Inliner<'tcx> { - fn run_pass(&self, caller_body: &mut BodyCache<'tcx>) { + fn run_pass(&self, caller_body: &mut BodyAndCache<'tcx>) { // Keep a queue of callsites to try inlining on. We take // advantage of the fact that queries detect cycles here to // allow us to try and fetch the fully optimized MIR of a @@ -380,8 +380,8 @@ impl Inliner<'tcx> { fn inline_call(&self, callsite: CallSite<'tcx>, - caller_body: &mut BodyCache<'tcx>, - mut callee_body: BodyCache<'tcx>) -> bool { + caller_body: &mut BodyAndCache<'tcx>, + mut callee_body: BodyAndCache<'tcx>) -> bool { let terminator = caller_body[callsite.bb].terminator.take().unwrap(); match terminator.kind { // FIXME: Handle inlining of diverging calls @@ -517,7 +517,7 @@ impl Inliner<'tcx> { &self, args: Vec>, callsite: &CallSite<'tcx>, - caller_body: &mut BodyCache<'tcx>, + caller_body: &mut BodyAndCache<'tcx>, ) -> Vec { let tcx = self.tcx; @@ -590,7 +590,7 @@ impl Inliner<'tcx> { &self, arg: Operand<'tcx>, callsite: &CallSite<'tcx>, - caller_body: &mut BodyCache<'tcx>, + caller_body: &mut BodyAndCache<'tcx>, ) -> Local { // FIXME: Analysis of the usage of the arguments to avoid // unnecessary temporaries. diff --git a/src/librustc_mir/transform/instcombine.rs b/src/librustc_mir/transform/instcombine.rs index bd237b5813298..eca1b596a4846 100644 --- a/src/librustc_mir/transform/instcombine.rs +++ b/src/librustc_mir/transform/instcombine.rs @@ -1,7 +1,7 @@ //! Performs various peephole optimizations. use rustc::mir::{ - Constant, Location, Place, PlaceBase, PlaceRef, Body, BodyCache, Operand, ProjectionElem, + Constant, Location, Place, PlaceBase, PlaceRef, Body, BodyAndCache, Operand, ProjectionElem, Rvalue, Local, read_only }; use rustc::mir::visit::{MutVisitor, Visitor}; @@ -14,7 +14,7 @@ use crate::transform::{MirPass, MirSource}; pub struct InstCombine; impl<'tcx> MirPass<'tcx> for InstCombine { - fn run_pass(&self, tcx: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut BodyCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { // We only run when optimizing MIR (at any level). if tcx.sess.opts.debugging_opts.mir_opt_level == 0 { return diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index df4cb7615336a..bedf2a95c026e 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -1,7 +1,7 @@ use crate::{build, shim}; use rustc_index::vec::IndexVec; use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; -use rustc::mir::{BodyCache, MirPhase, Promoted, ConstQualifs}; +use rustc::mir::{BodyAndCache, MirPhase, Promoted, ConstQualifs}; use rustc::ty::{TyCtxt, InstanceDef, TypeFoldable}; use rustc::ty::query::Providers; use rustc::ty::steal::Steal; @@ -97,7 +97,7 @@ fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> &DefIdSet { tcx.arena.alloc(set) } -fn mir_built(tcx: TyCtxt<'_>, def_id: DefId) -> &Steal> { +fn mir_built(tcx: TyCtxt<'_>, def_id: DefId) -> &Steal> { let mir = build::mir_build(tcx, def_id); tcx.alloc_steal_mir(mir) } @@ -144,12 +144,12 @@ pub trait MirPass<'tcx> { default_name::() } - fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut BodyCache<'tcx>); + fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>); } pub fn run_passes( tcx: TyCtxt<'tcx>, - body: &mut BodyCache<'tcx>, + body: &mut BodyAndCache<'tcx>, instance: InstanceDef<'tcx>, promoted: Option, mir_phase: MirPhase, @@ -220,7 +220,7 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs { validator.qualifs_in_return_place().into() } -fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> &Steal> { +fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> &Steal> { // Unsafety check uses the raw mir, so make sure it is run let _ = tcx.unsafety_check_result(def_id); @@ -238,7 +238,7 @@ fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> &Steal> { fn mir_validated( tcx: TyCtxt<'tcx>, def_id: DefId, -) -> (&'tcx Steal>, &'tcx Steal>>) { +) -> (&'tcx Steal>, &'tcx Steal>>) { // Ensure that we compute the `mir_const_qualif` for constants at // this point, before we steal the mir-const result. let _ = tcx.mir_const_qualif(def_id); @@ -257,7 +257,7 @@ fn mir_validated( fn run_optimization_passes<'tcx>( tcx: TyCtxt<'tcx>, - body: &mut BodyCache<'tcx>, + body: &mut BodyAndCache<'tcx>, def_id: DefId, promoted: Option, ) { @@ -319,7 +319,7 @@ fn run_optimization_passes<'tcx>( ]); } -fn optimized_mir(tcx: TyCtxt<'_>, def_id: DefId) -> &BodyCache<'_> { +fn optimized_mir(tcx: TyCtxt<'_>, def_id: DefId) -> &BodyAndCache<'_> { if tcx.is_constructor(def_id) { // There's no reason to run all of the MIR passes on constructors when // we can just output the MIR we want directly. This also saves const @@ -339,7 +339,7 @@ fn optimized_mir(tcx: TyCtxt<'_>, def_id: DefId) -> &BodyCache<'_> { tcx.arena.alloc(body) } -fn promoted_mir(tcx: TyCtxt<'_>, def_id: DefId) -> &IndexVec> { +fn promoted_mir(tcx: TyCtxt<'_>, def_id: DefId) -> &IndexVec> { if tcx.is_constructor(def_id) { return tcx.intern_promoted(IndexVec::new()); } diff --git a/src/librustc_mir/transform/no_landing_pads.rs b/src/librustc_mir/transform/no_landing_pads.rs index 5e1d29d47ade9..d4fe72f6ed7c8 100644 --- a/src/librustc_mir/transform/no_landing_pads.rs +++ b/src/librustc_mir/transform/no_landing_pads.rs @@ -17,12 +17,12 @@ impl<'tcx> NoLandingPads<'tcx> { } impl<'tcx> MirPass<'tcx> for NoLandingPads<'tcx> { - fn run_pass(&self, tcx: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut BodyCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { no_landing_pads(tcx, body) } } -pub fn no_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut BodyCache<'tcx>) { +pub fn no_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut BodyAndCache<'tcx>) { if tcx.sess.no_landing_pads() { NoLandingPads::new(tcx).visit_body(body); } diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index c758ccfd11d91..4c723199102be 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -41,11 +41,11 @@ use crate::transform::check_consts::{qualifs, Item, ConstKind, is_lang_panic_fn} /// newly created `StaticKind::Promoted`. #[derive(Default)] pub struct PromoteTemps<'tcx> { - pub promoted_fragments: Cell>>, + pub promoted_fragments: Cell>>, } impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> { - fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { // There's not really any point in promoting errorful MIR. // // This does not include MIR that failed const-checking, which we still try to promote. @@ -742,7 +742,7 @@ impl<'tcx> Validator<'_, 'tcx> { // FIXME(eddyb) remove the differences for promotability in `static`, `const`, `const fn`. pub fn validate_candidates( tcx: TyCtxt<'tcx>, - body: ReadOnlyBodyCache<'_, 'tcx>, + body: ReadOnlyBodyAndCache<'_, 'tcx>, def_id: DefId, temps: &IndexVec, candidates: &[Candidate], @@ -775,8 +775,8 @@ pub fn validate_candidates( struct Promoter<'a, 'tcx> { tcx: TyCtxt<'tcx>, - source: &'a mut BodyCache<'tcx>, - promoted: BodyCache<'tcx>, + source: &'a mut BodyAndCache<'tcx>, + promoted: BodyAndCache<'tcx>, temps: &'a mut IndexVec, /// If true, all nested temps are also kept in the @@ -924,7 +924,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { def_id: DefId, candidate: Candidate, next_promoted_id: usize, - ) -> Option> { + ) -> Option> { let mut operand = { let promoted = &mut self.promoted; let promoted_id = Promoted::new(next_promoted_id); @@ -1045,11 +1045,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> { pub fn promote_candidates<'tcx>( def_id: DefId, - body: &mut BodyCache<'tcx>, + body: &mut BodyAndCache<'tcx>, tcx: TyCtxt<'tcx>, mut temps: IndexVec, candidates: Vec, -) -> IndexVec> { +) -> IndexVec> { // Visit candidates in reverse, in case they're nested. debug!("promote_candidates({:?})", candidates); @@ -1081,7 +1081,7 @@ pub fn promote_candidates<'tcx>( ).collect(); let promoter = Promoter { - promoted: BodyCache::new(Body::new( + promoted: BodyAndCache::new(Body::new( IndexVec::new(), // FIXME: maybe try to filter this to avoid blowing up // memory usage? @@ -1150,7 +1150,7 @@ pub fn promote_candidates<'tcx>( crate fn should_suggest_const_in_array_repeat_expressions_attribute<'tcx>( tcx: TyCtxt<'tcx>, mir_def_id: DefId, - body: ReadOnlyBodyCache<'_, 'tcx>, + body: ReadOnlyBodyAndCache<'_, 'tcx>, operand: &Operand<'tcx>, ) -> bool { let mut rpo = traversal::reverse_postorder(&body); diff --git a/src/librustc_mir/transform/remove_noop_landing_pads.rs b/src/librustc_mir/transform/remove_noop_landing_pads.rs index c636aba9fc607..5799d0c38b01d 100644 --- a/src/librustc_mir/transform/remove_noop_landing_pads.rs +++ b/src/librustc_mir/transform/remove_noop_landing_pads.rs @@ -9,7 +9,7 @@ use crate::util::patch::MirPatch; /// code for these. pub struct RemoveNoopLandingPads; -pub fn remove_noop_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut BodyCache<'tcx>) { +pub fn remove_noop_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut BodyAndCache<'tcx>) { if tcx.sess.no_landing_pads() { return } @@ -19,7 +19,7 @@ pub fn remove_noop_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut BodyCache<'t } impl<'tcx> MirPass<'tcx> for RemoveNoopLandingPads { - fn run_pass(&self, tcx: TyCtxt<'tcx>, _src: MirSource<'tcx>, body: &mut BodyCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _src: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { remove_noop_landing_pads(tcx, body); } } @@ -84,7 +84,7 @@ impl RemoveNoopLandingPads { } } - fn remove_nop_landing_pads(&self, body: &mut BodyCache<'_>) { + fn remove_nop_landing_pads(&self, body: &mut BodyAndCache<'_>) { // make sure there's a single resume block let resume_block = { let patch = MirPatch::new(body); diff --git a/src/librustc_mir/transform/rustc_peek.rs b/src/librustc_mir/transform/rustc_peek.rs index 794ced1cb0ef5..2a81e97b8ff25 100644 --- a/src/librustc_mir/transform/rustc_peek.rs +++ b/src/librustc_mir/transform/rustc_peek.rs @@ -5,7 +5,7 @@ use syntax_pos::Span; use rustc::ty::{self, TyCtxt, Ty}; use rustc::hir::def_id::DefId; -use rustc::mir::{self, Body, BodyCache, Location, Local}; +use rustc::mir::{self, Body, BodyAndCache, Location, Local}; use rustc_index::bit_set::BitSet; use crate::transform::{MirPass, MirSource}; @@ -26,7 +26,7 @@ use crate::dataflow::has_rustc_mir_with; pub struct SanityCheck; impl<'tcx> MirPass<'tcx> for SanityCheck { - fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { let def_id = src.def_id(); if !tcx.has_attr(def_id, sym::rustc_mir) { debug!("skipping rustc_peek::SanityCheck on {}", tcx.def_path_str(def_id)); diff --git a/src/librustc_mir/transform/simplify.rs b/src/librustc_mir/transform/simplify.rs index 900752d3ce06c..eef39f8040ea0 100644 --- a/src/librustc_mir/transform/simplify.rs +++ b/src/librustc_mir/transform/simplify.rs @@ -43,7 +43,7 @@ impl SimplifyCfg { } } -pub fn simplify_cfg(body: &mut BodyCache<'_>) { +pub fn simplify_cfg(body: &mut BodyAndCache<'_>) { CfgSimplifier::new(body).simplify(); remove_dead_blocks(body); @@ -57,7 +57,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyCfg { } fn run_pass( - &self, _tcx: TyCtxt<'tcx>, _src: MirSource<'tcx>, body: &mut BodyCache<'tcx> + &self, _tcx: TyCtxt<'tcx>, _src: MirSource<'tcx>, body: &mut BodyAndCache<'tcx> ) { debug!("SimplifyCfg({:?}) - simplifying {:?}", self.label, body); simplify_cfg(body); @@ -70,7 +70,7 @@ pub struct CfgSimplifier<'a, 'tcx> { } impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> { - pub fn new(body: &'a mut BodyCache<'tcx>) -> Self { + pub fn new(body: &'a mut BodyAndCache<'tcx>) -> Self { let mut pred_count = IndexVec::from_elem(0u32, body.basic_blocks()); // we can't use mir.predecessors() here because that counts @@ -262,7 +262,7 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> { } } -pub fn remove_dead_blocks(body: &mut BodyCache<'_>) { +pub fn remove_dead_blocks(body: &mut BodyAndCache<'_>) { let mut seen = BitSet::new_empty(body.basic_blocks().len()); for (bb, _) in traversal::preorder(body) { seen.insert(bb.index()); @@ -296,7 +296,7 @@ pub struct SimplifyLocals; impl<'tcx> MirPass<'tcx> for SimplifyLocals { fn run_pass( - &self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut BodyCache<'tcx> + &self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx> ) { trace!("running SimplifyLocals on {:?}", source); let locals = { diff --git a/src/librustc_mir/transform/simplify_branches.rs b/src/librustc_mir/transform/simplify_branches.rs index c8d0f37f9a509..aa3c5b01be35f 100644 --- a/src/librustc_mir/transform/simplify_branches.rs +++ b/src/librustc_mir/transform/simplify_branches.rs @@ -19,7 +19,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyBranches { Cow::Borrowed(&self.label) } - fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { let param_env = tcx.param_env(src.def_id()); for block in body.basic_blocks_mut() { let terminator = block.terminator_mut(); diff --git a/src/librustc_mir/transform/simplify_try.rs b/src/librustc_mir/transform/simplify_try.rs index 2235de9a1533a..752e852895738 100644 --- a/src/librustc_mir/transform/simplify_try.rs +++ b/src/librustc_mir/transform/simplify_try.rs @@ -33,7 +33,7 @@ use itertools::Itertools as _; pub struct SimplifyArmIdentity; impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity { - fn run_pass(&self, _: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut BodyCache<'tcx>) { + fn run_pass(&self, _: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut(); for bb in basic_blocks { // Need 3 statements: @@ -151,7 +151,7 @@ fn match_variant_field_place<'tcx>(place: &Place<'tcx>) -> Option<(Local, VarFie pub struct SimplifyBranchSame; impl<'tcx> MirPass<'tcx> for SimplifyBranchSame { - fn run_pass(&self, _: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut BodyCache<'tcx>) { + fn run_pass(&self, _: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { let mut did_remove_blocks = false; let bbs = body.basic_blocks_mut(); for bb_idx in bbs.indices() { diff --git a/src/librustc_mir/transform/uniform_array_move_out.rs b/src/librustc_mir/transform/uniform_array_move_out.rs index 3fc76ef6b00e0..71dd405386aa7 100644 --- a/src/librustc_mir/transform/uniform_array_move_out.rs +++ b/src/librustc_mir/transform/uniform_array_move_out.rs @@ -37,7 +37,7 @@ use crate::util::patch::MirPatch; pub struct UniformArrayMoveOut; impl<'tcx> MirPass<'tcx> for UniformArrayMoveOut { - fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { let mut patch = MirPatch::new(body); let param_env = tcx.param_env(src.def_id()); { @@ -186,7 +186,7 @@ pub struct RestoreSubsliceArrayMoveOut<'tcx> { } impl<'tcx> MirPass<'tcx> for RestoreSubsliceArrayMoveOut<'tcx> { - fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { let mut patch = MirPatch::new(body); let param_env = tcx.param_env(src.def_id()); { diff --git a/src/librustc_mir/transform/uninhabited_enum_branching.rs b/src/librustc_mir/transform/uninhabited_enum_branching.rs index de070d75ad8e2..b93da831b7005 100644 --- a/src/librustc_mir/transform/uninhabited_enum_branching.rs +++ b/src/librustc_mir/transform/uninhabited_enum_branching.rs @@ -2,7 +2,7 @@ use crate::transform::{MirPass, MirSource}; use rustc::mir::{ - BasicBlock, BasicBlockData, Body, BodyCache, Local, Operand, Rvalue, StatementKind, + BasicBlock, BasicBlockData, Body, BodyAndCache, Local, Operand, Rvalue, StatementKind, TerminatorKind, }; use rustc::ty::layout::{Abi, TyLayout, Variants}; @@ -66,7 +66,7 @@ fn variant_discriminants<'tcx>( } impl<'tcx> MirPass<'tcx> for UninhabitedEnumBranching { - fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut BodyCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { if source.promoted.is_some() { return; } diff --git a/src/librustc_mir/util/collect_writes.rs b/src/librustc_mir/util/collect_writes.rs index f94bea2002461..4006787f260fc 100644 --- a/src/librustc_mir/util/collect_writes.rs +++ b/src/librustc_mir/util/collect_writes.rs @@ -1,5 +1,5 @@ use rustc::mir::{Local, Location}; -use rustc::mir::ReadOnlyBodyCache; +use rustc::mir::ReadOnlyBodyAndCache; use rustc::mir::visit::PlaceContext; use rustc::mir::visit::Visitor; @@ -9,7 +9,7 @@ crate trait FindAssignments { fn find_assignments(&self, local: Local) -> Vec; } -impl<'a, 'tcx> FindAssignments for ReadOnlyBodyCache<'a, 'tcx>{ +impl<'a, 'tcx> FindAssignments for ReadOnlyBodyAndCache<'a, 'tcx>{ fn find_assignments(&self, local: Local) -> Vec{ let mut visitor = FindLocalAssignmentVisitor{ needle: local, locations: vec![]}; visitor.visit_body(*self); diff --git a/src/librustc_mir/util/def_use.rs b/src/librustc_mir/util/def_use.rs index 1907e9bdc9746..c5f0ae3cd0c69 100644 --- a/src/librustc_mir/util/def_use.rs +++ b/src/librustc_mir/util/def_use.rs @@ -1,6 +1,6 @@ //! Def-use analysis. -use rustc::mir::{Body, BodyCache, Local, Location, PlaceElem, ReadOnlyBodyCache, VarDebugInfo}; +use rustc::mir::{Body, BodyAndCache, Local, Location, PlaceElem, ReadOnlyBodyAndCache, VarDebugInfo}; use rustc::mir::visit::{PlaceContext, MutVisitor, Visitor}; use rustc::ty::TyCtxt; use rustc_index::vec::IndexVec; @@ -30,7 +30,7 @@ impl DefUseAnalysis { } } - pub fn analyze(&mut self, body: ReadOnlyBodyCache<'_, '_>) { + pub fn analyze(&mut self, body: ReadOnlyBodyAndCache<'_, '_>) { self.clear(); let mut finder = DefUseFinder { @@ -55,7 +55,7 @@ impl DefUseAnalysis { fn mutate_defs_and_uses( &self, local: Local, - body: &mut BodyCache<'tcx>, + body: &mut BodyAndCache<'tcx>, new_local: Local, tcx: TyCtxt<'tcx>, ) { @@ -73,7 +73,7 @@ impl DefUseAnalysis { // FIXME(pcwalton): this should update the def-use chains. pub fn replace_all_defs_and_uses_with(&self, local: Local, - body: &mut BodyCache<'tcx>, + body: &mut BodyAndCache<'tcx>, new_local: Local, tcx: TyCtxt<'tcx>) { self.mutate_defs_and_uses(local, body, new_local, tcx) diff --git a/src/librustc_mir/util/liveness.rs b/src/librustc_mir/util/liveness.rs index 334975373e5f3..68c2e16399a59 100644 --- a/src/librustc_mir/util/liveness.rs +++ b/src/librustc_mir/util/liveness.rs @@ -57,7 +57,7 @@ pub struct LivenessResult { /// Computes which local variables are live within the given function /// `mir`, including drops. pub fn liveness_of_locals( - body: ReadOnlyBodyCache<'_, '_>, + body: ReadOnlyBodyAndCache<'_, '_>, ) -> LivenessResult { let num_live_vars = body.local_decls.len(); diff --git a/src/librustc_mir/util/patch.rs b/src/librustc_mir/util/patch.rs index 47bb0b699c048..575b6d25de20d 100644 --- a/src/librustc_mir/util/patch.rs +++ b/src/librustc_mir/util/patch.rs @@ -127,7 +127,7 @@ impl<'tcx> MirPatch<'tcx> { self.make_nop.push(loc); } - pub fn apply(self, body: &mut BodyCache<'tcx>) { + pub fn apply(self, body: &mut BodyAndCache<'tcx>) { debug!("MirPatch: make nops at: {:?}", self.make_nop); for loc in self.make_nop { body.make_statement_nop(loc); From 9a21f6ea8d5dab7eb2dc645a83543b3154d0a463 Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Tue, 3 Dec 2019 13:30:58 -0500 Subject: [PATCH 2/3] rustc_mir: Fix tidy line lengths --- src/librustc_mir/shim.rs | 6 +++++- src/librustc_mir/util/def_use.rs | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 5fe47c45b15ac..47b08048f8389 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -322,7 +322,11 @@ impl<'a, 'tcx> DropElaborator<'a, 'tcx> for DropShimElaborator<'a, 'tcx> { } /// Builds a `Clone::clone` shim for `self_ty`. Here, `def_id` is `Clone::clone`. -fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -> BodyAndCache<'tcx> { +fn build_clone_shim<'tcx>( + tcx: TyCtxt<'tcx>, + def_id: DefId, + self_ty: Ty<'tcx>, +) -> BodyAndCache<'tcx> { debug!("build_clone_shim(def_id={:?})", def_id); let param_env = tcx.param_env(def_id); diff --git a/src/librustc_mir/util/def_use.rs b/src/librustc_mir/util/def_use.rs index c5f0ae3cd0c69..cf98755eb6d90 100644 --- a/src/librustc_mir/util/def_use.rs +++ b/src/librustc_mir/util/def_use.rs @@ -1,6 +1,8 @@ //! Def-use analysis. -use rustc::mir::{Body, BodyAndCache, Local, Location, PlaceElem, ReadOnlyBodyAndCache, VarDebugInfo}; +use rustc::mir::{ + Body, BodyAndCache, Local, Location, PlaceElem, ReadOnlyBodyAndCache, VarDebugInfo, +}; use rustc::mir::visit::{PlaceContext, MutVisitor, Visitor}; use rustc::ty::TyCtxt; use rustc_index::vec::IndexVec; From a5e144b954df6a4e2db974a292a3328b100fd41c Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Wed, 4 Dec 2019 22:16:40 -0500 Subject: [PATCH 3/3] rustc_codegen_ssa: Fix line accidentally reverted during rebase --- src/librustc_codegen_ssa/mir/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_codegen_ssa/mir/mod.rs b/src/librustc_codegen_ssa/mir/mod.rs index 76b5ab4011183..0bdccd81408bd 100644 --- a/src/librustc_codegen_ssa/mir/mod.rs +++ b/src/librustc_codegen_ssa/mir/mod.rs @@ -156,7 +156,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( }).collect(); let (landing_pads, funclets) = create_funclets(&mir, &mut bx, &cleanup_kinds, &block_bxs); - let mir_body: &mir::Body<'_> = mir.body(); + let mir_body: &mir::Body<'_> = *mir; let mut fx = FunctionCx { instance, mir,