Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use Body everywhere
  • Loading branch information
ecstatic-morse committed Apr 22, 2020
commit 8287842eb4bdc59d407ffcae29b0b5e8a4abb1be
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
// a loop.
fn maybe_sideeffect<Bx: BuilderMethods<'a, 'tcx>>(
&self,
mir: mir::ReadOnlyBodyAndCache<'tcx, 'tcx>,
mir: &'tcx mir::Body<'tcx>,
bx: &mut Bx,
targets: &[mir::BasicBlock],
) {
Expand Down
13 changes: 6 additions & 7 deletions src/librustc_codegen_ssa/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use self::operand::{OperandRef, OperandValue};
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<FunctionDebugContext<Bx::DIScope>>,

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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());

Expand All @@ -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()
};

Expand All @@ -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 {
Expand All @@ -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);
Expand Down
26 changes: 7 additions & 19 deletions src/librustc_metadata/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rustc_middle::middle::cstore::{CrateSource, ExternCrate};
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;
Expand Down Expand Up @@ -1099,40 +1099,28 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
!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)
.filter(|_| !self.is_proc_macro(id))
.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<Promoted, BodyAndCache<'tcx>> {
let mut cache = self
.root
fn get_promoted_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> IndexVec<Promoted, Body<'tcx>> {
self.root
.tables
.promoted_mir
.get(self, id)
.filter(|_| !self.is_proc_macro(id))
.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 {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_metadata/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ define_tables! {
// Also, as an optimization, a missing entry indicates an empty `&[]`.
inferred_outlives: Table<DefIndex, Lazy!(&'tcx [(ty::Predicate<'tcx>, Span)])>,
super_predicates: Table<DefIndex, Lazy!(ty::GenericPredicates<'tcx>)>,
mir: Table<DefIndex, Lazy!(mir::BodyAndCache<'tcx>)>,
promoted_mir: Table<DefIndex, Lazy!(IndexVec<mir::Promoted, mir::BodyAndCache<'tcx>>)>,
mir: Table<DefIndex, Lazy!(mir::Body<'tcx>)>,
promoted_mir: Table<DefIndex, Lazy!(IndexVec<mir::Promoted, mir::Body<'tcx>>)>,
}

#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_middle/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<rustc_middle::mir::BodyAndCache<$tcx>>,
[] mir: rustc_middle::mir::BodyAndCache<$tcx>,
[] steal_mir: rustc_middle::ty::steal::Steal<rustc_middle::mir::Body<$tcx>>,
[] 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>,
Expand Down
22 changes: 8 additions & 14 deletions src/librustc_middle/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,6 @@ use rustc_span::Span;
// 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> {
Expand All @@ -82,7 +73,7 @@ macro_rules! make_mir_visitor {

fn visit_body(
&mut self,
body: body_type!($($mutability)? 'tcx)
body: &$($mutability)? Body<'tcx>,
) {
self.super_body(body);
}
Expand Down Expand Up @@ -254,7 +245,7 @@ macro_rules! make_mir_visitor {

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 {
Expand All @@ -275,7 +266,6 @@ macro_rules! make_mir_visitor {
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);
}
Expand Down Expand Up @@ -819,10 +809,14 @@ macro_rules! make_mir_visitor {

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)
Expand Down
32 changes: 11 additions & 21 deletions src/librustc_middle/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,56 +170,46 @@ rustc_queries! {

/// Fetch the MIR for a given `DefId` right after it's built - this includes
/// unreachable code.
query mir_built(_: DefId) -> &'tcx Steal<mir::BodyAndCache<'tcx>> {
query mir_built(_: DefId) -> &'tcx Steal<mir::Body<'tcx>> {
desc { "building MIR for" }
}

/// 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<mir::BodyAndCache<'tcx>> {
query mir_const(_: DefId) -> &'tcx Steal<mir::Body<'tcx>> {
no_hash
}

query mir_validated(_: DefId) ->
(
&'tcx Steal<mir::BodyAndCache<'tcx>>,
&'tcx Steal<IndexVec<mir::Promoted, mir::BodyAndCache<'tcx>>>
&'tcx Steal<mir::Body<'tcx>>,
&'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
) {
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<crate::mir::BodyAndCache<'tcx>>
let mir: Option<crate::mir::Body<'tcx>>
= 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<mir::Promoted, mir::BodyAndCache<'tcx>> {
query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
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))
}
}
}
Expand Down Expand Up @@ -618,7 +608,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::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()) }
}

Expand Down
14 changes: 6 additions & 8 deletions src/librustc_middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ use crate::middle::cstore::EncodedMetadata;
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;
Expand Down Expand Up @@ -993,21 +991,21 @@ pub struct GlobalCtxt<'tcx> {
}

impl<'tcx> TyCtxt<'tcx> {
pub fn alloc_steal_mir(self, mir: BodyAndCache<'tcx>) -> &'tcx Steal<BodyAndCache<'tcx>> {
pub fn alloc_steal_mir(self, mir: Body<'tcx>) -> &'tcx Steal<Body<'tcx>> {
self.arena.alloc(Steal::new(mir))
}

pub fn alloc_steal_promoted(
self,
promoted: IndexVec<Promoted, BodyAndCache<'tcx>>,
) -> &'tcx Steal<IndexVec<Promoted, BodyAndCache<'tcx>>> {
promoted: IndexVec<Promoted, Body<'tcx>>,
) -> &'tcx Steal<IndexVec<Promoted, Body<'tcx>>> {
self.arena.alloc(Steal::new(promoted))
}

pub fn intern_promoted(
self,
promoted: IndexVec<Promoted, BodyAndCache<'tcx>>,
) -> &'tcx IndexVec<Promoted, BodyAndCache<'tcx>> {
promoted: IndexVec<Promoted, Body<'tcx>>,
) -> &'tcx IndexVec<Promoted, Body<'tcx>> {
self.arena.alloc(promoted)
}

Expand Down
8 changes: 4 additions & 4 deletions src/librustc_middle/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::infer::canonical::Canonical;
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};
Expand Down Expand Up @@ -2808,17 +2808,17 @@ impl<'tcx> TyCtxt<'tcx> {
}

/// 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(..)
| ty::InstanceDef::FnPtrShim(..)
| 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),
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/borrow_check/borrow_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_index::bit_set::BitSet;
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;
Expand Down Expand Up @@ -90,7 +90,7 @@ crate enum LocalsStateAtExit {
impl LocalsStateAtExit {
fn build(
locals_are_invalidated_at_exit: bool,
body: ReadOnlyBodyAndCache<'_, 'tcx>,
body: &Body<'tcx>,
move_data: &MoveData<'tcx>,
) -> Self {
struct HasStorageDead(BitSet<Local>);
Expand Down Expand Up @@ -122,7 +122,7 @@ impl LocalsStateAtExit {
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 {
Expand Down
Loading