From: Dylan MacKenzie Date: Sun, 12 Apr 2020 17:31:00 +0000 (-0700) Subject: Use `Body` everywhere X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=8287842eb4bdc59d407ffcae29b0b5e8a4abb1be;p=rust.git Use `Body` everywhere --- diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index bea1d319fe7..dfb1656a6e0 100644 --- a/src/librustc_codegen_ssa/mir/block.rs +++ b/src/librustc_codegen_ssa/mir/block.rs @@ -152,7 +152,7 @@ fn do_call>( // a loop. fn maybe_sideeffect>( &self, - mir: mir::ReadOnlyBodyAndCache<'tcx, 'tcx>, + mir: &'tcx mir::Body<'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 fd20cf5404c..cb6d2d297cd 100644 --- a/src/librustc_codegen_ssa/mir/mod.rs +++ b/src/librustc_codegen_ssa/mir/mod.rs @@ -21,7 +21,7 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> { instance: Instance<'tcx>, - mir: mir::ReadOnlyBodyAndCache<'tcx, 'tcx>, + mir: &'tcx mir::Body<'tcx>, debug_context: Option>, @@ -169,7 +169,6 @@ 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; let mut fx = FunctionCx { instance, mir, @@ -197,7 +196,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( let args = arg_local_refs(&mut bx, &mut fx, &memory_locals); let mut allocate_local = |local| { - let decl = &mir_body.local_decls[local]; + let decl = &mir.local_decls[local]; let layout = bx.layout_of(fx.monomorphize(&decl.ty)); assert!(!layout.ty.has_erasable_regions()); @@ -223,7 +222,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( let retptr = allocate_local(mir::RETURN_PLACE); iter::once(retptr) .chain(args.into_iter()) - .chain(mir_body.vars_and_temps_iter().map(allocate_local)) + .chain(mir.vars_and_temps_iter().map(allocate_local)) .collect() }; @@ -235,8 +234,8 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx.br(fx.blocks[mir::START_BLOCK]); } - let rpo = traversal::reverse_postorder(&mir_body); - let mut visited = BitSet::new_empty(mir_body.basic_blocks().len()); + let rpo = traversal::reverse_postorder(&mir); + let mut visited = BitSet::new_empty(mir.basic_blocks().len()); // Codegen the body of each block using reverse postorder for (bb, _) in rpo { @@ -246,7 +245,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( // Remove blocks that haven't been visited, or have no // predecessors. - for bb in mir_body.basic_blocks().indices() { + for bb in mir.basic_blocks().indices() { // Unreachable block if !visited.contains(bb.index()) { debug!("codegen_mir: block {:?} was not visited", bb); diff --git a/src/librustc_metadata/rmeta/decoder.rs b/src/librustc_metadata/rmeta/decoder.rs index e1ac4d13416..1fb260f66fa 100644 --- a/src/librustc_metadata/rmeta/decoder.rs +++ b/src/librustc_metadata/rmeta/decoder.rs @@ -26,7 +26,7 @@ use rustc_middle::middle::cstore::{ForeignModule, LinkagePreference, NativeLibrary}; use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState}; -use rustc_middle::mir::{self, interpret, BodyAndCache, Promoted}; +use rustc_middle::mir::{self, interpret, Body, Promoted}; use rustc_middle::ty::codec::TyDecoder; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::util::common::record_time; @@ -1099,9 +1099,8 @@ fn is_item_mir_available(&self, id: DefIndex) -> bool { !self.is_proc_macro(id) && self.root.tables.mir.get(self, id).is_some() } - fn get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> BodyAndCache<'tcx> { - let mut cache = self - .root + fn get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> Body<'tcx> { + self.root .tables .mir .get(self, id) @@ -1109,18 +1108,11 @@ fn get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> BodyAndCache<'tc .unwrap_or_else(|| { bug!("get_optimized_mir: missing MIR for `{:?}`", self.local_def_id(id)) }) - .decode((self, tcx)); - cache.ensure_predecessors(); - cache + .decode((self, tcx)) } - fn get_promoted_mir( - &self, - tcx: TyCtxt<'tcx>, - id: DefIndex, - ) -> IndexVec> { - let mut cache = self - .root + fn get_promoted_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> IndexVec> { + self.root .tables .promoted_mir .get(self, id) @@ -1128,11 +1120,7 @@ fn get_promoted_mir( .unwrap_or_else(|| { bug!("get_promoted_mir: missing MIR for `{:?}`", self.local_def_id(id)) }) - .decode((self, tcx)); - for body in cache.iter_mut() { - body.ensure_predecessors(); - } - cache + .decode((self, tcx)) } fn mir_const_qualif(&self, id: DefIndex) -> mir::ConstQualifs { diff --git a/src/librustc_metadata/rmeta/mod.rs b/src/librustc_metadata/rmeta/mod.rs index 71872d53a56..e2d979ae488 100644 --- a/src/librustc_metadata/rmeta/mod.rs +++ b/src/librustc_metadata/rmeta/mod.rs @@ -275,8 +275,8 @@ fn encode(&self, buf: &mut Encoder) -> LazyTables<'tcx> { // 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_middle/arena.rs b/src/librustc_middle/arena.rs index 9d64823d352..0409f1f38e1 100644 --- a/src/librustc_middle/arena.rs +++ b/src/librustc_middle/arena.rs @@ -15,17 +15,17 @@ macro_rules! arena_types { [] generics: rustc_middle::ty::Generics, [] trait_def: rustc_middle::ty::TraitDef, [] adt_def: rustc_middle::ty::AdtDef, - [] steal_mir: rustc_middle::ty::steal::Steal>, - [] mir: rustc_middle::mir::BodyAndCache<$tcx>, + [] steal_mir: rustc_middle::ty::steal::Steal>, + [] mir: rustc_middle::mir::Body<$tcx>, [] steal_promoted: rustc_middle::ty::steal::Steal< rustc_index::vec::IndexVec< rustc_middle::mir::Promoted, - rustc_middle::mir::BodyAndCache<$tcx> + rustc_middle::mir::Body<$tcx> > >, [] promoted: rustc_index::vec::IndexVec< rustc_middle::mir::Promoted, - rustc_middle::mir::BodyAndCache<$tcx> + rustc_middle::mir::Body<$tcx> >, [decode] tables: rustc_middle::ty::TypeckTables<$tcx>, [decode] borrowck_result: rustc_middle::mir::BorrowCheckResult<$tcx>, diff --git a/src/librustc_middle/mir/visit.rs b/src/librustc_middle/mir/visit.rs index efc12138d34..edd9f8803b0 100644 --- a/src/librustc_middle/mir/visit.rs +++ b/src/librustc_middle/mir/visit.rs @@ -65,15 +65,6 @@ // variant argument) that does not require visiting, as in // `is_cleanup` above. -macro_rules! body_type { - (mut $tcx:lifetime) => { - &mut BodyAndCache<$tcx> - }; - ($tcx:lifetime) => { - &Body<$tcx> - }; -} - macro_rules! make_mir_visitor { ($visitor_trait_name:ident, $($mutability:ident)?) => { pub trait $visitor_trait_name<'tcx> { @@ -82,7 +73,7 @@ pub trait $visitor_trait_name<'tcx> { fn visit_body( &mut self, - body: body_type!($($mutability)? 'tcx) + body: &$($mutability)? Body<'tcx>, ) { self.super_body(body); } @@ -254,7 +245,7 @@ fn visit_source_scope(&mut self, fn super_body( &mut self, - $($mutability)? body: body_type!($($mutability)? 'tcx) + body: &$($mutability)? Body<'tcx>, ) { let span = body.span; if let Some(yield_ty) = &$($mutability)? body.yield_ty { @@ -275,7 +266,6 @@ macro_rules! basic_blocks { self.visit_basic_block_data(bb, data); } - let body: & $($mutability)? Body<'_> = & $($mutability)? body; for scope in &$($mutability)? body.source_scopes { self.visit_source_scope_data(scope); } @@ -819,10 +809,14 @@ fn super_substs(&mut self, _substs: & $($mutability)? SubstsRef<'tcx>) { fn visit_location( &mut self, - body: body_type!($($mutability)? 'tcx), + body: &$($mutability)? Body<'tcx>, location: Location ) { - let basic_block = & $($mutability)? body[location.block]; + macro_rules! basic_blocks { + (mut) => (body.basic_blocks_mut()); + () => (body.basic_blocks()); + }; + let basic_block = & $($mutability)? basic_blocks!($($mutability)?)[location.block]; if basic_block.statements.len() == location.statement_index { if let Some(ref $($mutability)? terminator) = basic_block.terminator { self.visit_terminator(terminator, location) diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index fc5deab5725..c7eaf9cdbd0 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -170,7 +170,7 @@ fn describe_as_module(def_id: DefId, tcx: TyCtxt<'_>) -> String { /// 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> { desc { "building MIR for" } } @@ -178,48 +178,38 @@ fn describe_as_module(def_id: DefId, tcx: TyCtxt<'_>) -> String { /// 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::BodyAndCache<'tcx> { + query optimized_mir(key: DefId) -> &'tcx mir::Body<'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); - cache.ensure_predecessors(); - &*cache - }) + mir.map(|x| &*tcx.arena.alloc(x)) } } - 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::BodyAndCache<'tcx> + crate::mir::Body<'tcx> >> = tcx.queries.on_disk_cache.try_load_query_result(tcx, id); - promoted.map(|p| { - let cache = tcx.arena.alloc(p); - for body in cache.iter_mut() { - body.ensure_predecessors(); - } - &*cache - }) + promoted.map(|p| &*tcx.arena.alloc(p)) } } } @@ -618,7 +608,7 @@ fn describe_as_module(def_id: DefId, tcx: TyCtxt<'_>) -> String { /// 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::BodyAndCache<'tcx> { + query mir_shims(key: ty::InstanceDef<'tcx>) -> &'tcx mir::Body<'tcx> { desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) } } diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index 9a23f8813fe..7f15179f707 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -14,9 +14,7 @@ use crate::middle::resolve_lifetime::{self, ObjectLifetimeDefault}; use crate::middle::stability; use crate::mir::interpret::{Allocation, ConstValue, Scalar}; -use crate::mir::{ - interpret, BodyAndCache, Field, Local, Place, PlaceElem, ProjectionKind, Promoted, -}; +use crate::mir::{interpret, Body, Field, Local, Place, PlaceElem, ProjectionKind, Promoted}; use crate::traits; use crate::traits::{Clause, Clauses, Goal, GoalKind, Goals}; use crate::ty::query; @@ -993,21 +991,21 @@ pub struct GlobalCtxt<'tcx> { } impl<'tcx> TyCtxt<'tcx> { - pub fn alloc_steal_mir(self, mir: BodyAndCache<'tcx>) -> &'tcx Steal> { + pub fn alloc_steal_mir(self, mir: Body<'tcx>) -> &'tcx Steal> { self.arena.alloc(Steal::new(mir)) } pub fn alloc_steal_promoted( self, - promoted: IndexVec>, - ) -> &'tcx Steal>> { + promoted: IndexVec>, + ) -> &'tcx Steal>> { self.arena.alloc(Steal::new(promoted)) } pub fn intern_promoted( self, - promoted: IndexVec>, - ) -> &'tcx IndexVec> { + promoted: IndexVec>, + ) -> &'tcx IndexVec> { self.arena.alloc(promoted) } diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 73e7e623b12..97bc3fdb100 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -11,8 +11,8 @@ use crate::middle::cstore::CrateStoreDyn; use crate::middle::resolve_lifetime::ObjectLifetimeDefault; use crate::mir::interpret::ErrorHandled; +use crate::mir::Body; use crate::mir::GeneratorLayout; -use crate::mir::ReadOnlyBodyAndCache; use crate::traits::{self, Reveal}; use crate::ty; use crate::ty::subst::{InternalSubsts, Subst, SubstsRef}; @@ -2808,9 +2808,9 @@ pub fn item_name(self, id: DefId) -> Symbol { } /// Returns the possibly-auto-generated MIR of a `(DefId, Subst)` pair. - pub fn instance_mir(self, instance: ty::InstanceDef<'tcx>) -> ReadOnlyBodyAndCache<'tcx, 'tcx> { + pub fn instance_mir(self, instance: ty::InstanceDef<'tcx>) -> &'tcx Body<'tcx> { match instance { - ty::InstanceDef::Item(did) => self.optimized_mir(did).unwrap_read_only(), + ty::InstanceDef::Item(did) => self.optimized_mir(did), ty::InstanceDef::VtableShim(..) | ty::InstanceDef::ReifyShim(..) | ty::InstanceDef::Intrinsic(..) @@ -2818,7 +2818,7 @@ pub fn instance_mir(self, instance: ty::InstanceDef<'tcx>) -> ReadOnlyBodyAndCac | ty::InstanceDef::Virtual(..) | ty::InstanceDef::ClosureOnceShim { .. } | ty::InstanceDef::DropGlue(..) - | ty::InstanceDef::CloneShim(..) => self.mir_shims(instance).unwrap_read_only(), + | ty::InstanceDef::CloneShim(..) => self.mir_shims(instance), } } diff --git a/src/librustc_mir/borrow_check/borrow_set.rs b/src/librustc_mir/borrow_check/borrow_set.rs index 7242bbcd2eb..ef9af7bace9 100644 --- a/src/librustc_mir/borrow_check/borrow_set.rs +++ b/src/librustc_mir/borrow_check/borrow_set.rs @@ -8,7 +8,7 @@ use rustc_index::vec::IndexVec; use rustc_middle::mir::traversal; use rustc_middle::mir::visit::{MutatingUseContext, NonUseContext, PlaceContext, Visitor}; -use rustc_middle::mir::{self, Body, Local, Location, ReadOnlyBodyAndCache}; +use rustc_middle::mir::{self, Body, Local, Location}; use rustc_middle::ty::{RegionVid, TyCtxt}; use std::fmt; use std::ops::Index; @@ -90,7 +90,7 @@ fn fmt(&self, w: &mut fmt::Formatter<'_>) -> fmt::Result { impl LocalsStateAtExit { fn build( locals_are_invalidated_at_exit: bool, - body: ReadOnlyBodyAndCache<'_, 'tcx>, + body: &Body<'tcx>, move_data: &MoveData<'tcx>, ) -> Self { struct HasStorageDead(BitSet); @@ -122,7 +122,7 @@ fn visit_local(&mut self, local: &Local, ctx: PlaceContext, _: Location) { impl<'tcx> BorrowSet<'tcx> { pub fn build( tcx: TyCtxt<'tcx>, - body: ReadOnlyBodyAndCache<'_, 'tcx>, + body: &Body<'tcx>, locals_are_invalidated_at_exit: bool, move_data: &MoveData<'tcx>, ) -> Self { diff --git a/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs b/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs index 860300d834d..22947610448 100644 --- a/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs @@ -1,3 +1,4 @@ +use either::Either; use rustc_data_structures::fx::FxHashSet; use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir as hir; @@ -1262,8 +1263,23 @@ fn report_escaping_data( } fn get_moved_indexes(&mut self, location: Location, mpi: MovePathIndex) -> Vec { + fn predecessor_locations( + body: &'a mir::Body<'tcx>, + location: Location, + ) -> impl Iterator + 'a { + if location.statement_index == 0 { + let predecessors = body.predecessors_for(location.block).to_vec(); + Either::Left(predecessors.into_iter().map(move |bb| body.terminator_loc(bb))) + } else { + Either::Right(std::iter::once(Location { + statement_index: location.statement_index - 1, + ..location + })) + } + } + let mut stack = Vec::new(); - stack.extend(self.body.predecessor_locations(location).map(|predecessor| { + stack.extend(predecessor_locations(self.body, location).map(|predecessor| { let is_back_edge = location.dominates(predecessor, &self.dominators); (predecessor, is_back_edge) })); @@ -1345,7 +1361,7 @@ fn get_moved_indexes(&mut self, location: Location, mpi: MovePathIndex) -> Vec( tcx: TyCtxt<'tcx>, all_facts: &mut Option, location_table: &LocationTable, - body: ReadOnlyBodyAndCache<'_, 'tcx>, + body: &Body<'tcx>, borrow_set: &BorrowSet<'tcx>, ) { if all_facts.is_none() { @@ -37,7 +37,7 @@ pub(super) fn generate_invalidates<'tcx>( body: &body, dominators, }; - ig.visit_body(&body); + ig.visit_body(body); } } diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index a1f005e3b45..a330dc95f23 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -10,8 +10,8 @@ use rustc_index::vec::IndexVec; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_middle::mir::{ - read_only, traversal, Body, BodyAndCache, ClearCrossCrate, Local, Location, Mutability, - Operand, Place, PlaceElem, PlaceRef, ReadOnlyBodyAndCache, + traversal, Body, ClearCrossCrate, Local, Location, Mutability, Operand, Place, PlaceElem, + PlaceRef, }; use rustc_middle::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind}; use rustc_middle::mir::{Field, ProjectionElem, Promoted, Rvalue, Statement, StatementKind}; @@ -106,7 +106,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); @@ -168,13 +168,11 @@ fn do_mir_borrowck<'a, 'tcx>( // requires first making our own copy of the MIR. This copy will // be modified (in place) to contain non-lexical lifetimes. It // will have a lifetime tied to the inference context. - let body_clone: Body<'tcx> = input_body.clone(); + let mut body = input_body.clone(); let mut promoted = input_promoted.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 - let promoted: IndexVec<_, _> = promoted.iter_mut().map(|body| read_only!(body)).collect(); + let body = &body; // no further changes let location_table = &LocationTable::new(&body); @@ -415,7 +413,7 @@ fn do_mir_borrowck<'a, 'tcx>( crate struct MirBorrowckCtxt<'cx, 'tcx> { crate infcx: &'cx InferCtxt<'cx, 'tcx>, - body: ReadOnlyBodyAndCache<'cx, 'tcx>, + body: &'cx Body<'tcx>, mir_def_id: DefId, move_data: &'cx MoveData<'tcx>, @@ -952,7 +950,6 @@ fn check_access_for_conflict( let mut error_reported = false; let tcx = self.infcx.tcx; let body = self.body; - let body: &Body<'_> = &body; let borrow_set = self.borrow_set.clone(); // Use polonius output if it has been enabled. diff --git a/src/librustc_mir/borrow_check/nll.rs b/src/librustc_mir/borrow_check/nll.rs index 678ab3ed323..141ed00e789 100644 --- a/src/librustc_mir/borrow_check/nll.rs +++ b/src/librustc_mir/borrow_check/nll.rs @@ -6,8 +6,8 @@ use rustc_index::vec::IndexVec; use rustc_infer::infer::InferCtxt; use rustc_middle::mir::{ - BasicBlock, Body, BodyAndCache, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, - Location, Promoted, ReadOnlyBodyAndCache, + BasicBlock, Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location, + Promoted, }; use rustc_middle::ty::{self, RegionKind, RegionVid}; use rustc_span::symbol::sym; @@ -60,8 +60,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 BodyAndCache<'tcx>, - promoted: &mut IndexVec>, + body: &mut Body<'tcx>, + promoted: &mut IndexVec>, ) -> UniversalRegions<'tcx> { debug!("replace_regions_in_mir(def_id={:?})", def_id); @@ -159,8 +159,8 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>( infcx: &InferCtxt<'cx, 'tcx>, def_id: DefId, universal_regions: UniversalRegions<'tcx>, - body: ReadOnlyBodyAndCache<'_, 'tcx>, - promoted: &IndexVec>, + body: &Body<'tcx>, + promoted: &IndexVec>, location_table: &LocationTable, param_env: ty::ParamEnv<'tcx>, flow_inits: &mut ResultsCursor<'cx, 'tcx, MaybeInitializedPlaces<'cx, 'tcx>>, diff --git a/src/librustc_mir/borrow_check/prefixes.rs b/src/librustc_mir/borrow_check/prefixes.rs index 7350167684f..a2475e0ff29 100644 --- a/src/librustc_mir/borrow_check/prefixes.rs +++ b/src/librustc_mir/borrow_check/prefixes.rs @@ -10,7 +10,7 @@ use super::MirBorrowckCtxt; use rustc_hir as hir; -use rustc_middle::mir::{Place, PlaceRef, ProjectionElem, ReadOnlyBodyAndCache}; +use rustc_middle::mir::{Body, Place, PlaceRef, ProjectionElem}; use rustc_middle::ty::{self, TyCtxt}; pub trait IsPrefixOf<'tcx> { @@ -26,7 +26,7 @@ fn is_prefix_of(&self, other: PlaceRef<'tcx>) -> bool { } pub(super) struct Prefixes<'cx, 'tcx> { - body: ReadOnlyBodyAndCache<'cx, 'tcx>, + body: &'cx Body<'tcx>, tcx: TyCtxt<'tcx>, kind: PrefixSet, next: Option>, diff --git a/src/librustc_mir/borrow_check/region_infer/values.rs b/src/librustc_mir/borrow_check/region_infer/values.rs index 5310fd4abaf..57a3fa6f79b 100644 --- a/src/librustc_mir/borrow_check/region_infer/values.rs +++ b/src/librustc_mir/borrow_check/region_infer/values.rs @@ -2,7 +2,7 @@ use rustc_index::bit_set::{HybridBitSet, SparseBitMatrix}; use rustc_index::vec::Idx; use rustc_index::vec::IndexVec; -use rustc_middle::mir::{BasicBlock, Body, Location, ReadOnlyBodyAndCache}; +use rustc_middle::mir::{BasicBlock, Body, Location}; use rustc_middle::ty::{self, RegionVid}; use std::fmt::Debug; use std::rc::Rc; @@ -80,7 +80,7 @@ impl RegionValueElements { /// Pushes all predecessors of `index` onto `stack`. crate fn push_predecessors( &self, - body: ReadOnlyBodyAndCache<'_, '_>, + body: &Body<'_>, index: PointIndex, stack: &mut Vec, ) { diff --git a/src/librustc_mir/borrow_check/renumber.rs b/src/librustc_mir/borrow_check/renumber.rs index a6b4aa74977..59568968819 100644 --- a/src/librustc_mir/borrow_check/renumber.rs +++ b/src/librustc_mir/borrow_check/renumber.rs @@ -1,7 +1,7 @@ use rustc_index::vec::IndexVec; use rustc_infer::infer::{InferCtxt, NLLRegionVariableOrigin}; use rustc_middle::mir::visit::{MutVisitor, TyContext}; -use rustc_middle::mir::{BodyAndCache, Location, PlaceElem, Promoted}; +use rustc_middle::mir::{Body, Location, PlaceElem, Promoted}; use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable}; @@ -9,8 +9,8 @@ /// inference variables, returning the number of variables created. pub fn renumber_mir<'tcx>( infcx: &InferCtxt<'_, 'tcx>, - body: &mut BodyAndCache<'tcx>, - promoted: &mut IndexVec>, + body: &mut Body<'tcx>, + promoted: &mut IndexVec>, ) { debug!("renumber_mir()"); debug!("renumber_mir: body.arg_count={:?}", body.arg_count); diff --git a/src/librustc_mir/borrow_check/type_check/liveness/local_use_map.rs b/src/librustc_mir/borrow_check/type_check/liveness/local_use_map.rs index 88e2109b1b2..0fdf96710c6 100644 --- a/src/librustc_mir/borrow_check/type_check/liveness/local_use_map.rs +++ b/src/librustc_mir/borrow_check/type_check/liveness/local_use_map.rs @@ -1,7 +1,7 @@ use rustc_data_structures::vec_linked_list as vll; use rustc_index::vec::IndexVec; use rustc_middle::mir::visit::{PlaceContext, Visitor}; -use rustc_middle::mir::{Local, Location, ReadOnlyBodyAndCache}; +use rustc_middle::mir::{Body, Local, Location}; use crate::util::liveness::{categorize, DefUse}; @@ -62,7 +62,7 @@ impl LocalUseMap { crate fn build( live_locals: &Vec, elements: &RegionValueElements, - body: ReadOnlyBodyAndCache<'_, '_>, + body: &Body<'_>, ) -> 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/type_check/liveness/mod.rs b/src/librustc_mir/borrow_check/type_check/liveness/mod.rs index 13bdaa357ce..717bfb8fe7d 100644 --- a/src/librustc_mir/borrow_check/type_check/liveness/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/liveness/mod.rs @@ -1,5 +1,5 @@ use rustc_data_structures::fx::FxHashSet; -use rustc_middle::mir::{Body, Local, ReadOnlyBodyAndCache}; +use rustc_middle::mir::{Body, Local}; use rustc_middle::ty::{RegionVid, TyCtxt}; use std::rc::Rc; @@ -32,7 +32,7 @@ /// performed before pub(super) fn generate<'mir, 'tcx>( typeck: &mut TypeChecker<'_, 'tcx>, - body: ReadOnlyBodyAndCache<'_, 'tcx>, + body: &Body<'tcx>, elements: &Rc, flow_inits: &mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'mir, 'tcx>>, move_data: &MoveData<'tcx>, diff --git a/src/librustc_mir/borrow_check/type_check/liveness/polonius.rs b/src/librustc_mir/borrow_check/type_check/liveness/polonius.rs index 26d75f08ae4..2e033896ce1 100644 --- a/src/librustc_mir/borrow_check/type_check/liveness/polonius.rs +++ b/src/librustc_mir/borrow_check/type_check/liveness/polonius.rs @@ -3,7 +3,7 @@ use crate::dataflow::move_paths::{LookupResult, MoveData}; use crate::util::liveness::{categorize, DefUse}; use rustc_middle::mir::visit::{MutatingUseContext, PlaceContext, Visitor}; -use rustc_middle::mir::{Local, Location, Place, ReadOnlyBodyAndCache}; +use rustc_middle::mir::{Body, Local, Location, Place}; use rustc_middle::ty::subst::GenericArg; use super::TypeChecker; @@ -85,7 +85,7 @@ fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, location: pub(super) fn populate_access_facts( typeck: &mut TypeChecker<'_, 'tcx>, - body: ReadOnlyBodyAndCache<'_, 'tcx>, + body: &Body<'tcx>, location_table: &LocationTable, move_data: &MoveData<'_>, dropped_at: &mut Vec<(Local, Location)>, diff --git a/src/librustc_mir/borrow_check/type_check/liveness/trace.rs b/src/librustc_mir/borrow_check/type_check/liveness/trace.rs index fe5c020c8bb..af09dc5b803 100644 --- a/src/librustc_mir/borrow_check/type_check/liveness/trace.rs +++ b/src/librustc_mir/borrow_check/type_check/liveness/trace.rs @@ -1,7 +1,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_index::bit_set::HybridBitSet; use rustc_infer::infer::canonical::QueryRegionConstraints; -use rustc_middle::mir::{BasicBlock, ConstraintCategory, Local, Location, ReadOnlyBodyAndCache}; +use rustc_middle::mir::{BasicBlock, Body, ConstraintCategory, Local, Location}; use rustc_middle::ty::{Ty, TypeFoldable}; use rustc_trait_selection::traits::query::dropck_outlives::DropckOutlivesResult; use rustc_trait_selection::traits::query::type_op::outlives::DropckOutlives; @@ -37,7 +37,7 @@ /// this respects `#[may_dangle]` annotations). pub(super) fn trace( typeck: &mut TypeChecker<'_, 'tcx>, - body: ReadOnlyBodyAndCache<'_, 'tcx>, + body: &Body<'tcx>, elements: &Rc, flow_inits: &mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'mir, 'tcx>>, move_data: &MoveData<'tcx>, @@ -76,7 +76,7 @@ struct LivenessContext<'me, 'typeck, 'flow, 'tcx> { elements: &'me RegionValueElements, /// MIR we are analyzing. - body: ReadOnlyBodyAndCache<'me, 'tcx>, + body: &'me Body<'tcx>, /// Mapping to/from the various indices used for initialization tracking. move_data: &'me MoveData<'tcx>, diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index f706ac26d07..796efd2bab9 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -122,8 +122,8 @@ macro_rules! span_mirbug_and_err { pub(crate) fn type_check<'mir, 'tcx>( infcx: &InferCtxt<'_, 'tcx>, param_env: ty::ParamEnv<'tcx>, - body: ReadOnlyBodyAndCache<'_, 'tcx>, - promoted: &IndexVec>, + body: &Body<'tcx>, + promoted: &IndexVec>, mir_def_id: DefId, universal_regions: &Rc>, location_table: &LocationTable, @@ -190,8 +190,8 @@ fn type_check_internal<'a, 'tcx, R>( infcx: &'a InferCtxt<'a, 'tcx>, mir_def_id: DefId, param_env: ty::ParamEnv<'tcx>, - body: ReadOnlyBodyAndCache<'a, 'tcx>, - promoted: &'a IndexVec>, + body: &'a Body<'tcx>, + promoted: &'a IndexVec>, region_bound_pairs: &'a RegionBoundPairs<'tcx>, implicit_region_bound: ty::Region<'tcx>, borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>, @@ -266,7 +266,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, @@ -320,7 +320,7 @@ fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) { if let ty::ConstKind::Unevaluated(def_id, substs, promoted) = constant.literal.val { if let Some(promoted) = promoted { let check_err = |verifier: &mut TypeVerifier<'a, 'b, 'tcx>, - promoted: &ReadOnlyBodyAndCache<'_, 'tcx>, + promoted: &Body<'tcx>, ty, san_ty| { if let Err(terr) = verifier.cx.eq_types( @@ -451,7 +451,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, @@ -525,11 +525,7 @@ fn sanitize_place( place_ty } - fn sanitize_promoted( - &mut self, - promoted_body: ReadOnlyBodyAndCache<'b, 'tcx>, - location: Location, - ) { + fn sanitize_promoted(&mut self, promoted_body: &'b Body<'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. @@ -1396,12 +1392,7 @@ fn tcx(&self) -> TyCtxt<'tcx> { self.infcx.tcx } - fn check_stmt( - &mut self, - body: ReadOnlyBodyAndCache<'_, 'tcx>, - stmt: &Statement<'tcx>, - location: Location, - ) { + fn check_stmt(&mut self, body: &Body<'tcx>, stmt: &Statement<'tcx>, location: Location) { debug!("check_stmt: {:?}", stmt); let tcx = self.tcx(); match stmt.kind { @@ -1973,12 +1964,7 @@ fn aggregate_field_ty( } } - fn check_rvalue( - &mut self, - body: ReadOnlyBodyAndCache<'_, 'tcx>, - rvalue: &Rvalue<'tcx>, - location: Location, - ) { + fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: Location) { let tcx = self.tcx(); match rvalue { @@ -2712,7 +2698,7 @@ fn prove_predicate( }) } - fn typeck_mir(&mut self, body: ReadOnlyBodyAndCache<'_, 'tcx>) { + fn typeck_mir(&mut self, body: &Body<'tcx>) { self.last_span = body.span; debug!("run_on_mir: {:?}", body.span); diff --git a/src/librustc_mir/dataflow/impls/storage_liveness.rs b/src/librustc_mir/dataflow/impls/storage_liveness.rs index cc63f5f39d5..5d130213e1f 100644 --- a/src/librustc_mir/dataflow/impls/storage_liveness.rs +++ b/src/librustc_mir/dataflow/impls/storage_liveness.rs @@ -84,13 +84,13 @@ impl BottomValue for MaybeStorageLive { /// 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 MaybeRequiresStorage<'mir, 'tcx> { - body: ReadOnlyBodyAndCache<'mir, 'tcx>, + body: &'mir Body<'tcx>, borrowed_locals: RefCell>, } impl<'mir, 'tcx> MaybeRequiresStorage<'mir, 'tcx> { pub fn new( - body: ReadOnlyBodyAndCache<'mir, 'tcx>, + body: &'mir Body<'tcx>, borrowed_locals: &'mir Results<'tcx, MaybeBorrowedLocals>, ) -> Self { MaybeRequiresStorage { diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 0a33dfde9db..ae4ad49fe66 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -405,7 +405,7 @@ pub fn load_mir( &self, instance: ty::InstanceDef<'tcx>, promoted: Option, - ) -> InterpResult<'tcx, mir::ReadOnlyBodyAndCache<'tcx, 'tcx>> { + ) -> InterpResult<'tcx, &'tcx mir::Body<'tcx>> { // do not continue if typeck errors occurred (can only occur in local crate) let did = instance.def_id(); if did.is_local() && self.tcx.has_typeck_tables(did) { @@ -415,12 +415,12 @@ pub fn load_mir( } trace!("load mir(instance={:?}, promoted={:?})", instance, promoted); if let Some(promoted) = promoted { - return Ok(self.tcx.promoted_mir(did)[promoted].unwrap_read_only()); + return Ok(&self.tcx.promoted_mir(did)[promoted]); } match instance { ty::InstanceDef::Item(def_id) => { if self.tcx.is_mir_available(did) { - Ok(self.tcx.optimized_mir(did).unwrap_read_only()) + Ok(self.tcx.optimized_mir(did)) } else { throw_unsup!(NoMirFor(def_id)) } diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 77d4424befd..6dc6935179b 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 BodyAndCache<'tcx> { +fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx Body<'tcx> { debug!("make_shim({:?})", instance); let mut result = match instance { @@ -128,7 +128,6 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx debug!("make_shim({:?}) = {:?}", instance, result); - result.ensure_predecessors(); tcx.arena.alloc(result) } @@ -168,11 +167,7 @@ fn local_decls_for_sig<'tcx>( .collect() } -fn build_drop_shim<'tcx>( - tcx: TyCtxt<'tcx>, - def_id: DefId, - ty: Option>, -) -> BodyAndCache<'tcx> { +fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) -> Body<'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 @@ -204,9 +199,7 @@ fn build_drop_shim<'tcx>( block(&mut blocks, TerminatorKind::Goto { target: return_block }); block(&mut blocks, TerminatorKind::Return); - let body = new_body(blocks, local_decls_for_sig(&sig, span), sig.inputs().len(), span); - - let mut body = BodyAndCache::new(body); + let mut body = new_body(blocks, local_decls_for_sig(&sig, span), sig.inputs().len(), span); if let Some(..) = ty { // The first argument (index 0), but add 1 for the return value. @@ -320,11 +313,7 @@ fn array_subpath(&self, _path: Self::Path, _index: u32, _size: u32) -> Option( - 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>) -> Body<'tcx> { debug!("build_clone_shim(def_id={:?})", def_id); let param_env = tcx.param_env(def_id); @@ -348,7 +337,7 @@ fn build_clone_shim<'tcx>( _ => bug!("clone shim for `{:?}` which is not `Copy` and is not an aggregate", self_ty), }; - BodyAndCache::new(builder.into_mir()) + builder.into_mir() } struct CloneShimBuilder<'tcx> { @@ -671,7 +660,7 @@ fn build_call_shim<'tcx>( rcvr_adjustment: Option, call_kind: CallKind, untuple_args: Option<&[Ty<'tcx>]>, -) -> BodyAndCache<'tcx> { +) -> Body<'tcx> { debug!( "build_call_shim(instance={:?}, rcvr_adjustment={:?}, \ call_kind={:?}, untuple_args={:?})", @@ -835,10 +824,11 @@ fn build_call_shim<'tcx>( if let Abi::RustCall = sig.abi { body.spread_arg = Some(Local::new(sig.inputs().len())); } - BodyAndCache::new(body) + + body } -pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> &BodyAndCache<'_> { +pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> &Body<'_> { debug_assert!(tcx.is_constructor(ctor_id)); let span = @@ -905,7 +895,5 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> &BodyAndCache<'_> { |_, _| Ok(()), ); - 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 6deb5d6485a..33859115359 100644 --- a/src/librustc_mir/transform/add_call_guards.rs +++ b/src/librustc_mir/transform/add_call_guards.rs @@ -31,13 +31,13 @@ pub enum AddCallGuards { */ impl<'tcx> MirPass<'tcx> for AddCallGuards { - fn run_pass(&self, _tcx: TyCtxt<'tcx>, _src: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { + fn run_pass(&self, _tcx: TyCtxt<'tcx>, _src: MirSource<'tcx>, body: &mut Body<'tcx>) { self.add_call_guards(body); } } impl AddCallGuards { - pub fn add_call_guards(&self, body: &mut BodyAndCache<'_>) { + pub fn add_call_guards(&self, body: &mut Body<'_>) { 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 7c46855dfd6..39ce2340aed 100644 --- a/src/librustc_mir/transform/add_moves_for_packed_drops.rs +++ b/src/librustc_mir/transform/add_moves_for_packed_drops.rs @@ -40,17 +40,13 @@ pub struct AddMovesForPackedDrops; impl<'tcx> MirPass<'tcx> for AddMovesForPackedDrops { - fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut Body<'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 BodyAndCache<'tcx>, - def_id: DefId, -) { +pub fn add_moves_for_packed_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'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 d0de0a09873..6d5853def1e 100644 --- a/src/librustc_mir/transform/add_retag.rs +++ b/src/librustc_mir/transform/add_retag.rs @@ -58,7 +58,7 @@ fn may_be_reference(ty: Ty<'tcx>) -> bool { } impl<'tcx> MirPass<'tcx> for AddRetag { - fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut Body<'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 1f916d5fc1d..8aac5c791ec 100644 --- a/src/librustc_mir/transform/check_consts/mod.rs +++ b/src/librustc_mir/transform/check_consts/mod.rs @@ -21,7 +21,7 @@ /// 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::ReadOnlyBodyAndCache<'mir, 'tcx>, + pub body: &'mir mir::Body<'tcx>, pub tcx: TyCtxt<'tcx>, pub def_id: DefId, pub param_env: ty::ParamEnv<'tcx>, @@ -29,11 +29,7 @@ pub struct Item<'mir, 'tcx> { } impl Item<'mir, 'tcx> { - pub fn new( - tcx: TyCtxt<'tcx>, - def_id: DefId, - body: mir::ReadOnlyBodyAndCache<'mir, 'tcx>, - ) -> Self { + pub fn new(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'mir mir::Body<'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_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 8b5e502dc72..5215c985107 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -502,9 +502,6 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: DefId) -> UnsafetyCheckResult hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => (true, false), }; let mut checker = UnsafetyChecker::new(const_context, min_const_fn, body, tcx, param_env); - // mir_built ensures that body has a computed cache, so we don't (and can't) attempt to - // recompute it here. - let body = body.unwrap_read_only(); checker.visit_body(&body); check_unused_unsafe(tcx, def_id, &checker.used_unsafe, &mut checker.inherited_blocks); diff --git a/src/librustc_mir/transform/cleanup_post_borrowck.rs b/src/librustc_mir/transform/cleanup_post_borrowck.rs index 446aadd56dc..a3880d691b2 100644 --- a/src/librustc_mir/transform/cleanup_post_borrowck.rs +++ b/src/librustc_mir/transform/cleanup_post_borrowck.rs @@ -18,7 +18,7 @@ use crate::transform::{MirPass, MirSource}; use rustc_middle::mir::visit::MutVisitor; -use rustc_middle::mir::{BodyAndCache, BorrowKind, Location, Rvalue}; +use rustc_middle::mir::{Body, BorrowKind, Location, Rvalue}; use rustc_middle::mir::{Statement, StatementKind}; use rustc_middle::ty::TyCtxt; @@ -29,7 +29,7 @@ pub struct DeleteNonCodegenStatements<'tcx> { } impl<'tcx> MirPass<'tcx> for CleanupNonCodegenStatements { - fn run_pass(&self, tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, body: &mut Body<'tcx>) { let mut delete = DeleteNonCodegenStatements { tcx }; delete.visit_body(body); body.user_type_annotations.raw.clear(); diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 79dba2c5db8..58a8d5eeb1e 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -14,10 +14,9 @@ MutVisitor, MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor, }; use rustc_middle::mir::{ - read_only, AggregateKind, AssertKind, BasicBlock, BinOp, Body, BodyAndCache, ClearCrossCrate, - Constant, Local, LocalDecl, LocalKind, Location, Operand, Place, ReadOnlyBodyAndCache, Rvalue, - SourceInfo, SourceScope, SourceScopeData, Statement, StatementKind, Terminator, TerminatorKind, - UnOp, RETURN_PLACE, + AggregateKind, AssertKind, BasicBlock, BinOp, Body, ClearCrossCrate, Constant, Local, + LocalDecl, LocalKind, Location, Operand, Place, Rvalue, SourceInfo, SourceScope, + SourceScopeData, Statement, StatementKind, Terminator, TerminatorKind, UnOp, RETURN_PLACE, }; use rustc_middle::ty::layout::{HasTyCtxt, LayoutError, TyAndLayout}; use rustc_middle::ty::subst::{InternalSubsts, Subst}; @@ -59,7 +58,7 @@ impl rustc_middle::mir::interpret::MachineStopType for Zst {} pub struct ConstProp; impl<'tcx> MirPass<'tcx> for ConstProp { - fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>) { // will be evaluated by miri and produce its errors there if source.promoted.is_some() { return; @@ -150,8 +149,7 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut BodyAn // constants, instead of just checking for const-folding succeeding. // That would require an uniform one-def no-mutation analysis // and RPO (or recursing when needing the value of a local). - let mut optimization_finder = - ConstPropagator::new(read_only!(body), dummy_body, tcx, source); + let mut optimization_finder = ConstPropagator::new(body, dummy_body, tcx, source); optimization_finder.visit_body(body); trace!("ConstProp done for {:?}", source.def_id()); @@ -362,7 +360,7 @@ fn tcx(&self) -> TyCtxt<'tcx> { impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { fn new( - body: ReadOnlyBodyAndCache<'_, 'tcx>, + body: &Body<'tcx>, dummy_body: &'mir Body<'tcx>, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, @@ -782,7 +780,7 @@ struct CanConstProp { impl CanConstProp { /// returns true if `local` can be propagated - fn check(body: ReadOnlyBodyAndCache<'_, '_>) -> IndexVec { + fn check(body: &Body<'_>) -> IndexVec { let mut cpv = CanConstProp { can_const_prop: IndexVec::from_elem(ConstPropMode::FullConstProp, &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 494fb93b663..bc1cb52ae85 100644 --- a/src/librustc_mir/transform/copy_prop.rs +++ b/src/librustc_mir/transform/copy_prop.rs @@ -23,15 +23,14 @@ use crate::util::def_use::DefUseAnalysis; use rustc_middle::mir::visit::MutVisitor; use rustc_middle::mir::{ - read_only, Body, BodyAndCache, Constant, Local, LocalKind, Location, Operand, Place, Rvalue, - StatementKind, + Body, Constant, Local, LocalKind, Location, Operand, Place, Rvalue, StatementKind, }; use rustc_middle::ty::TyCtxt; pub struct CopyPropagation; impl<'tcx> MirPass<'tcx> for CopyPropagation { - fn run_pass(&self, tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, body: &mut Body<'tcx>) { // We only run when the MIR optimization level is > 1. // This avoids a slow pass, and messing up debug info. if tcx.sess.opts.debugging_opts.mir_opt_level <= 1 { @@ -40,10 +39,10 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, body: &mut BodyA let mut def_use_analysis = DefUseAnalysis::new(body); loop { - def_use_analysis.analyze(read_only!(body)); + def_use_analysis.analyze(body); if eliminate_self_assignments(body, &def_use_analysis) { - def_use_analysis.analyze(read_only!(body)); + def_use_analysis.analyze(body); } let mut changed = false; @@ -252,7 +251,7 @@ fn constant(src_constant: &Constant<'tcx>) -> Option> { fn perform( self, - body: &mut BodyAndCache<'tcx>, + body: &mut Body<'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 3e2be7fd7d5..2de701284e3 100644 --- a/src/librustc_mir/transform/deaggregator.rs +++ b/src/librustc_mir/transform/deaggregator.rs @@ -6,7 +6,7 @@ pub struct Deaggregator; impl<'tcx> MirPass<'tcx> for Deaggregator { - fn run_pass(&self, tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, body: &mut Body<'tcx>) { let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut(); let local_decls = &*local_decls; for bb in basic_blocks { diff --git a/src/librustc_mir/transform/dump_mir.rs b/src/librustc_mir/transform/dump_mir.rs index 9933b5cd9f7..5ce6f4fa741 100644 --- a/src/librustc_mir/transform/dump_mir.rs +++ b/src/librustc_mir/transform/dump_mir.rs @@ -7,7 +7,7 @@ use crate::transform::{MirPass, MirSource}; use crate::util as mir_util; -use rustc_middle::mir::{Body, BodyAndCache}; +use rustc_middle::mir::Body; use rustc_middle::ty::TyCtxt; use rustc_session::config::{OutputFilenames, OutputType}; @@ -18,13 +18,7 @@ fn name(&self) -> Cow<'_, str> { Cow::Borrowed(self.0) } - fn run_pass( - &self, - _tcx: TyCtxt<'tcx>, - _source: MirSource<'tcx>, - _body: &mut BodyAndCache<'tcx>, - ) { - } + fn run_pass(&self, _tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, _body: &mut Body<'tcx>) {} } pub struct Disambiguator { diff --git a/src/librustc_mir/transform/elaborate_drops.rs b/src/librustc_mir/transform/elaborate_drops.rs index a7c6b5a98bb..6074619dd15 100644 --- a/src/librustc_mir/transform/elaborate_drops.rs +++ b/src/librustc_mir/transform/elaborate_drops.rs @@ -21,7 +21,7 @@ pub struct ElaborateDrops; impl<'tcx> MirPass<'tcx> for ElaborateDrops { - fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut Body<'tcx>) { debug!("elaborate_drops({:?} @ {:?})", src, body.span); let def_id = src.def_id(); diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 44928951045..6906d443735 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -354,7 +354,7 @@ fn visit_basic_block_data(&mut self, block: BasicBlock, data: &mut BasicBlockDat } } -fn make_generator_state_argument_indirect<'tcx>(tcx: TyCtxt<'tcx>, body: &mut BodyAndCache<'tcx>) { +fn make_generator_state_argument_indirect<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { let gen_ty = body.local_decls.raw[1].ty; let ref_gen_ty = @@ -367,7 +367,7 @@ fn make_generator_state_argument_indirect<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Bo DerefArgVisitor { tcx }.visit_body(body); } -fn make_generator_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut BodyAndCache<'tcx>) { +fn make_generator_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { let ref_gen_ty = body.local_decls.raw[1].ty; let pin_did = tcx.lang_items().pin_type().unwrap(); @@ -391,7 +391,7 @@ fn make_generator_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body fn replace_local<'tcx>( local: Local, ty: Ty<'tcx>, - body: &mut BodyAndCache<'tcx>, + body: &mut Body<'tcx>, tcx: TyCtxt<'tcx>, ) -> Local { let source_info = source_info(body); @@ -436,7 +436,7 @@ struct LivenessInfo { fn locals_live_across_suspend_points( tcx: TyCtxt<'tcx>, - body: ReadOnlyBodyAndCache<'_, 'tcx>, + body: &Body<'tcx>, source: MirSource<'tcx>, always_live_locals: &storage::AlwaysLiveLocals, movable: bool, @@ -686,7 +686,7 @@ fn compute_layout<'tcx>( interior: Ty<'tcx>, always_live_locals: &storage::AlwaysLiveLocals, movable: bool, - body: &mut BodyAndCache<'tcx>, + body: &mut Body<'tcx>, ) -> ( FxHashMap, VariantIdx, usize)>, GeneratorLayout<'tcx>, @@ -698,13 +698,7 @@ fn compute_layout<'tcx>( live_locals_at_suspension_points, storage_conflicts, storage_liveness, - } = locals_live_across_suspend_points( - tcx, - read_only!(body), - source, - always_live_locals, - movable, - ); + } = locals_live_across_suspend_points(tcx, body, source, always_live_locals, movable); // Erase regions from the types passed in from typeck so we can compare them with // MIR types @@ -779,7 +773,7 @@ fn compute_layout<'tcx>( /// /// After this function, the former entry point of the function will be bb1. fn insert_switch<'tcx>( - body: &mut BodyAndCache<'tcx>, + body: &mut Body<'tcx>, cases: Vec<(usize, BasicBlock)>, transform: &TransformVisitor<'tcx>, default: TerminatorKind<'tcx>, @@ -810,11 +804,7 @@ fn insert_switch<'tcx>( } } -fn elaborate_generator_drops<'tcx>( - tcx: TyCtxt<'tcx>, - def_id: DefId, - body: &mut BodyAndCache<'tcx>, -) { +fn elaborate_generator_drops<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, body: &mut Body<'tcx>) { use crate::shim::DropShimElaborator; use crate::util::elaborate_drops::{elaborate_drop, Unwind}; use crate::util::patch::MirPatch; @@ -865,9 +855,9 @@ fn create_generator_drop_shim<'tcx>( transform: &TransformVisitor<'tcx>, source: MirSource<'tcx>, gen_ty: Ty<'tcx>, - body: &mut BodyAndCache<'tcx>, + body: &mut Body<'tcx>, drop_clean: BasicBlock, -) -> BodyAndCache<'tcx> { +) -> Body<'tcx> { let mut body = body.clone(); body.arg_count = 1; // make sure the resume argument is not included here @@ -934,10 +924,7 @@ fn create_generator_drop_shim<'tcx>( body } -fn insert_term_block<'tcx>( - body: &mut BodyAndCache<'tcx>, - kind: TerminatorKind<'tcx>, -) -> BasicBlock { +fn insert_term_block<'tcx>(body: &mut Body<'tcx>, kind: TerminatorKind<'tcx>) -> BasicBlock { let term_block = BasicBlock::new(body.basic_blocks().len()); let source_info = source_info(body); body.basic_blocks_mut().push(BasicBlockData { @@ -950,7 +937,7 @@ fn insert_term_block<'tcx>( fn insert_panic_block<'tcx>( tcx: TyCtxt<'tcx>, - body: &mut BodyAndCache<'tcx>, + body: &mut Body<'tcx>, message: AssertMessage<'tcx>, ) -> BasicBlock { let assert_block = BasicBlock::new(body.basic_blocks().len()); @@ -1036,7 +1023,7 @@ fn create_generator_resume_function<'tcx>( tcx: TyCtxt<'tcx>, transform: TransformVisitor<'tcx>, source: MirSource<'tcx>, - body: &mut BodyAndCache<'tcx>, + body: &mut Body<'tcx>, can_return: bool, ) { let can_unwind = can_unwind(tcx, body); @@ -1115,7 +1102,7 @@ fn source_info(body: &Body<'_>) -> SourceInfo { SourceInfo { span: body.span, scope: OUTERMOST_SOURCE_SCOPE } } -fn insert_clean_drop(body: &mut BodyAndCache<'_>) -> BasicBlock { +fn insert_clean_drop(body: &mut Body<'_>) -> BasicBlock { let return_block = insert_term_block(body, TerminatorKind::Return); // Create a block to destroy an unresumed generators. This can only destroy upvars. @@ -1152,7 +1139,7 @@ fn target_block(self, point: &SuspensionPoint<'_>) -> Option { } fn create_cases<'tcx>( - body: &mut BodyAndCache<'tcx>, + body: &mut Body<'tcx>, transform: &TransformVisitor<'tcx>, operation: Operation, ) -> Vec<(usize, BasicBlock)> { @@ -1215,7 +1202,7 @@ fn create_cases<'tcx>( } impl<'tcx> MirPass<'tcx> for StateTransform { - fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>) { let yield_ty = if let Some(yield_ty) = body.yield_ty { yield_ty } else { diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index c1705b0ff7e..d8bb8a0b52c 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -38,7 +38,7 @@ struct CallSite<'tcx> { } impl<'tcx> MirPass<'tcx> for Inline { - fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>) { if tcx.sess.opts.debugging_opts.mir_opt_level >= 2 { Inliner { tcx, source }.run_pass(body); } @@ -51,7 +51,7 @@ struct Inliner<'tcx> { } impl Inliner<'tcx> { - fn run_pass(&self, caller_body: &mut BodyAndCache<'tcx>) { + fn run_pass(&self, caller_body: &mut Body<'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 @@ -405,8 +405,8 @@ fn should_inline(&self, callsite: CallSite<'tcx>, callee_body: &Body<'tcx>) -> b fn inline_call( &self, callsite: CallSite<'tcx>, - caller_body: &mut BodyAndCache<'tcx>, - mut callee_body: BodyAndCache<'tcx>, + caller_body: &mut Body<'tcx>, + mut callee_body: Body<'tcx>, ) -> bool { let terminator = caller_body[callsite.bb].terminator.take().unwrap(); match terminator.kind { @@ -534,7 +534,7 @@ fn make_call_args( &self, args: Vec>, callsite: &CallSite<'tcx>, - caller_body: &mut BodyAndCache<'tcx>, + caller_body: &mut Body<'tcx>, ) -> Vec { let tcx = self.tcx; @@ -601,7 +601,7 @@ fn create_temp_if_necessary( &self, arg: Operand<'tcx>, callsite: &CallSite<'tcx>, - caller_body: &mut BodyAndCache<'tcx>, + caller_body: &mut Body<'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 3a60048b0ef..d570e093353 100644 --- a/src/librustc_mir/transform/instcombine.rs +++ b/src/librustc_mir/transform/instcombine.rs @@ -5,8 +5,7 @@ use rustc_index::vec::Idx; use rustc_middle::mir::visit::{MutVisitor, Visitor}; use rustc_middle::mir::{ - read_only, Body, BodyAndCache, Constant, Local, Location, Operand, Place, PlaceRef, - ProjectionElem, Rvalue, + Body, Constant, Local, Location, Operand, Place, PlaceRef, ProjectionElem, Rvalue, }; use rustc_middle::ty::{self, TyCtxt}; use std::mem; @@ -14,7 +13,7 @@ pub struct InstCombine; impl<'tcx> MirPass<'tcx> for InstCombine { - fn run_pass(&self, tcx: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) { // We only run when optimizing MIR (at any level). if tcx.sess.opts.debugging_opts.mir_opt_level == 0 { return; @@ -24,9 +23,8 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut BodyAndCach // read-only so that we can do global analyses on the MIR in the process (e.g. // `Place::ty()`). let optimizations = { - let read_only_cache = read_only!(body); let mut optimization_finder = OptimizationFinder::new(body, tcx); - optimization_finder.visit_body(&read_only_cache); + optimization_finder.visit_body(body); optimization_finder.optimizations }; diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 8db0b39a497..b7b67f36ae4 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -4,7 +4,7 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIdSet, LocalDefId, LOCAL_CRATE}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_index::vec::IndexVec; -use rustc_middle::mir::{BodyAndCache, ConstQualifs, MirPhase, Promoted}; +use rustc_middle::mir::{Body, ConstQualifs, MirPhase, Promoted}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::steal::Steal; use rustc_middle::ty::{InstanceDef, TyCtxt, TypeFoldable}; @@ -131,12 +131,12 @@ fn name(&self) -> Cow<'_, str> { default_name::() } - fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>); + fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>); } pub fn run_passes( tcx: TyCtxt<'tcx>, - body: &mut BodyAndCache<'tcx>, + body: &mut Body<'tcx>, instance: InstanceDef<'tcx>, promoted: Option, mir_phase: MirPhase, @@ -194,13 +194,8 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs { return Default::default(); } - let item = check_consts::Item { - body: body.unwrap_read_only(), - tcx, - def_id, - const_kind, - param_env: tcx.param_env(def_id), - }; + let item = + check_consts::Item { body, tcx, def_id, const_kind, param_env: tcx.param_env(def_id) }; let mut validator = check_consts::validation::Validator::new(&item); validator.check_body(); @@ -210,7 +205,7 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs { validator.qualifs_in_return_place() } -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); @@ -230,14 +225,13 @@ fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> &Steal> { &rustc_peek::SanityCheck, ], ); - body.ensure_predecessors(); tcx.alloc_steal_mir(body) } 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); @@ -263,7 +257,7 @@ fn mir_validated( fn run_optimization_passes<'tcx>( tcx: TyCtxt<'tcx>, - body: &mut BodyAndCache<'tcx>, + body: &mut Body<'tcx>, def_id: DefId, promoted: Option, ) { @@ -319,7 +313,7 @@ fn run_optimization_passes<'tcx>( ); } -fn optimized_mir(tcx: TyCtxt<'_>, def_id: DefId) -> &BodyAndCache<'_> { +fn optimized_mir(tcx: TyCtxt<'_>, def_id: DefId) -> &Body<'_> { 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 @@ -335,14 +329,13 @@ fn optimized_mir(tcx: TyCtxt<'_>, def_id: DefId) -> &BodyAndCache<'_> { let (body, _) = tcx.mir_validated(def_id); let mut body = body.steal(); run_optimization_passes(tcx, &mut body, def_id, None); - body.ensure_predecessors(); debug_assert!(!body.has_free_regions(), "Free regions in optimized MIR"); 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()); } @@ -353,7 +346,6 @@ fn promoted_mir(tcx: TyCtxt<'_>, def_id: DefId) -> &IndexVec) -> Self { } impl<'tcx> MirPass<'tcx> for NoLandingPads<'tcx> { - fn run_pass(&self, tcx: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) { no_landing_pads(tcx, body) } } -pub fn no_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut BodyAndCache<'tcx>) { +pub fn no_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'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 9c18a298b24..20576d82b1c 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -42,11 +42,11 @@ /// newly created `Constant`. #[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 BodyAndCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut Body<'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. @@ -64,8 +64,7 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyAndCa let mut rpo = traversal::reverse_postorder(body); let (temps, all_candidates) = collect_temps_and_candidates(tcx, body, &mut rpo); - let promotable_candidates = - validate_candidates(tcx, read_only!(body), def_id, &temps, &all_candidates); + let promotable_candidates = validate_candidates(tcx, body, def_id, &temps, &all_candidates); let promoted = promote_candidates(def_id, body, tcx, temps, promotable_candidates); self.promoted_fragments.set(promoted); @@ -719,7 +718,7 @@ fn validate_call( // FIXME(eddyb) remove the differences for promotability in `static`, `const`, `const fn`. pub fn validate_candidates( tcx: TyCtxt<'tcx>, - body: ReadOnlyBodyAndCache<'_, 'tcx>, + body: &Body<'tcx>, def_id: DefId, temps: &IndexVec, candidates: &[Candidate], @@ -752,8 +751,8 @@ pub fn validate_candidates( struct Promoter<'a, 'tcx> { tcx: TyCtxt<'tcx>, - source: &'a mut BodyAndCache<'tcx>, - promoted: BodyAndCache<'tcx>, + source: &'a mut Body<'tcx>, + promoted: Body<'tcx>, temps: &'a mut IndexVec, extra_statements: &'a mut Vec<(Location, Statement<'tcx>)>, @@ -901,7 +900,7 @@ fn promote_candidate( def_id: DefId, candidate: Candidate, next_promoted_id: usize, - ) -> Option> { + ) -> Option> { let mut rvalue = { let promoted = &mut self.promoted; let promoted_id = Promoted::new(next_promoted_id); @@ -1044,11 +1043,11 @@ fn visit_local(&mut self, local: &mut Local, _: PlaceContext, _: Location) { pub fn promote_candidates<'tcx>( def_id: DefId, - body: &mut BodyAndCache<'tcx>, + body: &mut Body<'tcx>, tcx: TyCtxt<'tcx>, mut temps: IndexVec, candidates: Vec, -) -> IndexVec> { +) -> IndexVec> { // Visit candidates in reverse, in case they're nested. debug!("promote_candidates({:?})", candidates); @@ -1093,7 +1092,7 @@ pub fn promote_candidates<'tcx>( promoted.ignore_interior_mut_in_const_validation = true; let promoter = Promoter { - promoted: BodyAndCache::new(promoted), + promoted, tcx, source: body, temps: &mut temps, @@ -1150,7 +1149,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: ReadOnlyBodyAndCache<'_, 'tcx>, + body: &Body<'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 5e4fd061c76..44a68a8040f 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 @@ /// code for these. pub struct RemoveNoopLandingPads; -pub fn remove_noop_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut BodyAndCache<'tcx>) { +pub fn remove_noop_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { if tcx.sess.no_landing_pads() { return; } @@ -19,7 +19,7 @@ pub fn remove_noop_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut BodyAndCache } impl<'tcx> MirPass<'tcx> for RemoveNoopLandingPads { - fn run_pass(&self, tcx: TyCtxt<'tcx>, _src: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _src: MirSource<'tcx>, body: &mut Body<'tcx>) { remove_noop_landing_pads(tcx, body); } } @@ -80,7 +80,7 @@ fn is_nop_landing_pad( } } - fn remove_nop_landing_pads(&self, body: &mut BodyAndCache<'_>) { + fn remove_nop_landing_pads(&self, body: &mut Body<'_>) { // 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 28bac490ac9..88af60dbeb6 100644 --- a/src/librustc_mir/transform/rustc_peek.rs +++ b/src/librustc_mir/transform/rustc_peek.rs @@ -6,7 +6,7 @@ use crate::transform::{MirPass, MirSource}; use rustc_hir::def_id::DefId; use rustc_index::bit_set::BitSet; -use rustc_middle::mir::{self, Body, BodyAndCache, Local, Location}; +use rustc_middle::mir::{self, Body, Local, Location}; use rustc_middle::ty::{self, Ty, TyCtxt}; use crate::dataflow::move_paths::{HasMoveData, MoveData}; @@ -21,7 +21,7 @@ pub struct SanityCheck; impl<'tcx> MirPass<'tcx> for SanityCheck { - fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut Body<'tcx>) { use crate::dataflow::has_rustc_mir_with; let def_id = src.def_id(); if !tcx.has_attr(def_id, sym::rustc_mir) { diff --git a/src/librustc_mir/transform/simplify.rs b/src/librustc_mir/transform/simplify.rs index c4971b25655..e579950d8c0 100644 --- a/src/librustc_mir/transform/simplify.rs +++ b/src/librustc_mir/transform/simplify.rs @@ -45,7 +45,7 @@ pub fn new(label: &str) -> Self { } } -pub fn simplify_cfg(body: &mut BodyAndCache<'_>) { +pub fn simplify_cfg(body: &mut Body<'_>) { CfgSimplifier::new(body).simplify(); remove_dead_blocks(body); @@ -58,7 +58,7 @@ fn name(&self) -> Cow<'_, str> { Cow::Borrowed(&self.label) } - fn run_pass(&self, _tcx: TyCtxt<'tcx>, _src: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { + fn run_pass(&self, _tcx: TyCtxt<'tcx>, _src: MirSource<'tcx>, body: &mut Body<'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 BodyAndCache<'tcx>) -> Self { + pub fn new(body: &'a mut Body<'tcx>) -> Self { let mut pred_count = IndexVec::from_elem(0u32, body.basic_blocks()); // we can't use mir.predecessors() here because that counts @@ -272,7 +272,7 @@ fn strip_nops(&mut self) { } } -pub fn remove_dead_blocks(body: &mut BodyAndCache<'_>) { +pub fn remove_dead_blocks(body: &mut Body<'_>) { let mut seen = BitSet::new_empty(body.basic_blocks().len()); for (bb, _) in traversal::preorder(body) { seen.insert(bb.index()); @@ -304,15 +304,14 @@ pub fn remove_dead_blocks(body: &mut BodyAndCache<'_>) { pub struct SimplifyLocals; impl<'tcx> MirPass<'tcx> for SimplifyLocals { - fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>) { trace!("running SimplifyLocals on {:?}", source); // First, we're going to get a count of *actual* uses for every `Local`. // Take a look at `DeclMarker::visit_local()` to see exactly what is ignored. let mut used_locals = { - let read_only_cache = read_only!(body); let mut marker = DeclMarker::new(body); - marker.visit_body(&read_only_cache); + marker.visit_body(&body); marker.local_counts }; diff --git a/src/librustc_mir/transform/simplify_branches.rs b/src/librustc_mir/transform/simplify_branches.rs index dd666289e39..38e7f9d8ae4 100644 --- a/src/librustc_mir/transform/simplify_branches.rs +++ b/src/librustc_mir/transform/simplify_branches.rs @@ -21,7 +21,7 @@ fn name(&self) -> Cow<'_, str> { Cow::Borrowed(&self.label) } - fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut Body<'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 72658e51f00..d22c2d90600 100644 --- a/src/librustc_mir/transform/simplify_try.rs +++ b/src/librustc_mir/transform/simplify_try.rs @@ -33,7 +33,7 @@ pub struct SimplifyArmIdentity; impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity { - fn run_pass(&self, _: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { + fn run_pass(&self, _: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) { let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut(); for bb in basic_blocks { // Need 3 statements: @@ -153,7 +153,7 @@ fn match_variant_field_place<'tcx>(place: Place<'tcx>) -> Option<(Local, VarFiel pub struct SimplifyBranchSame; impl<'tcx> MirPass<'tcx> for SimplifyBranchSame { - fn run_pass(&self, _: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { + fn run_pass(&self, _: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut Body<'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/uninhabited_enum_branching.rs b/src/librustc_mir/transform/uninhabited_enum_branching.rs index 0a08c13b479..e3b182b8849 100644 --- a/src/librustc_mir/transform/uninhabited_enum_branching.rs +++ b/src/librustc_mir/transform/uninhabited_enum_branching.rs @@ -2,8 +2,7 @@ use crate::transform::{MirPass, MirSource}; use rustc_middle::mir::{ - BasicBlock, BasicBlockData, Body, BodyAndCache, Local, Operand, Rvalue, StatementKind, - TerminatorKind, + BasicBlock, BasicBlockData, Body, Local, Operand, Rvalue, StatementKind, TerminatorKind, }; use rustc_middle::ty::layout::TyAndLayout; use rustc_middle::ty::{Ty, TyCtxt}; @@ -67,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 BodyAndCache<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>) { if source.promoted.is_some() { return; } diff --git a/src/librustc_mir/transform/unreachable_prop.rs b/src/librustc_mir/transform/unreachable_prop.rs index 8f636582673..d9f2259030f 100644 --- a/src/librustc_mir/transform/unreachable_prop.rs +++ b/src/librustc_mir/transform/unreachable_prop.rs @@ -12,7 +12,7 @@ pub struct UnreachablePropagation; impl MirPass<'_> for UnreachablePropagation { - fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { + fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) { if tcx.sess.opts.debugging_opts.mir_opt_level < 3 { // Enable only under -Zmir-opt-level=3 as in some cases (check the deeply-nested-opt // perf benchmark) LLVM may spend quite a lot of time optimizing the generated code. diff --git a/src/librustc_mir/util/def_use.rs b/src/librustc_mir/util/def_use.rs index 0ac743359be..b4448ead8eb 100644 --- a/src/librustc_mir/util/def_use.rs +++ b/src/librustc_mir/util/def_use.rs @@ -2,7 +2,7 @@ use rustc_index::vec::IndexVec; use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor}; -use rustc_middle::mir::{Body, BodyAndCache, Local, Location, ReadOnlyBodyAndCache, VarDebugInfo}; +use rustc_middle::mir::{Body, Local, Location, VarDebugInfo}; use rustc_middle::ty::TyCtxt; use std::mem; @@ -28,7 +28,7 @@ pub fn new(body: &Body<'_>) -> DefUseAnalysis { DefUseAnalysis { info: IndexVec::from_elem_n(Info::new(), body.local_decls.len()) } } - pub fn analyze(&mut self, body: ReadOnlyBodyAndCache<'_, '_>) { + pub fn analyze(&mut self, body: &Body<'_>) { self.clear(); let mut finder = DefUseFinder { @@ -53,7 +53,7 @@ pub fn local_info(&self, local: Local) -> &Info { fn mutate_defs_and_uses( &self, local: Local, - body: &mut BodyAndCache<'tcx>, + body: &mut Body<'tcx>, new_local: Local, tcx: TyCtxt<'tcx>, ) { @@ -72,7 +72,7 @@ fn mutate_defs_and_uses( pub fn replace_all_defs_and_uses_with( &self, local: Local, - body: &mut BodyAndCache<'tcx>, + body: &mut Body<'tcx>, new_local: Local, tcx: TyCtxt<'tcx>, ) { diff --git a/src/librustc_mir/util/liveness.rs b/src/librustc_mir/util/liveness.rs index 2c020f4adfc..80b31be84ca 100644 --- a/src/librustc_mir/util/liveness.rs +++ b/src/librustc_mir/util/liveness.rs @@ -56,7 +56,7 @@ pub struct LivenessResult { /// Computes which local variables are live within the given function /// `mir`, including drops. -pub fn liveness_of_locals(body: ReadOnlyBodyAndCache<'_, '_>) -> LivenessResult { +pub fn liveness_of_locals(body: &Body<'_>) -> LivenessResult { let num_live_vars = body.local_decls.len(); let def_use: IndexVec<_, DefsUses> = diff --git a/src/librustc_mir/util/patch.rs b/src/librustc_mir/util/patch.rs index 46f42f4db05..9153f82588b 100644 --- a/src/librustc_mir/util/patch.rs +++ b/src/librustc_mir/util/patch.rs @@ -121,7 +121,7 @@ pub fn make_nop(&mut self, loc: Location) { self.make_nop.push(loc); } - pub fn apply(self, body: &mut BodyAndCache<'tcx>) { + pub fn apply(self, body: &mut Body<'tcx>) { debug!("MirPatch: make nops at: {:?}", self.make_nop); for loc in self.make_nop { body.make_statement_nop(loc); diff --git a/src/librustc_mir_build/build/mod.rs b/src/librustc_mir_build/build/mod.rs index ee45ff5a495..2a3e9188437 100644 --- a/src/librustc_mir_build/build/mod.rs +++ b/src/librustc_mir_build/build/mod.rs @@ -21,12 +21,12 @@ use super::lints; -crate fn mir_built(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::steal::Steal> { +crate fn mir_built(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::steal::Steal> { tcx.alloc_steal_mir(mir_build(tcx, def_id)) } /// Construct the MIR for a given `DefId`. -fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> BodyAndCache<'_> { +fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> Body<'_> { let id = tcx.hir().as_local_hir_id(def_id).unwrap(); // Figure out what primary body this item has. @@ -183,9 +183,6 @@ fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> BodyAndCache<'_> { lints::check(tcx, &body, def_id); - let mut body = BodyAndCache::new(body); - body.ensure_predecessors(); - // The borrow checker will replace all the regions here with its own // inference variables. There's no point having non-erased regions here. // The exception is `body.user_type_annotations`, which is used unmodified