Skip to content

Commit

Permalink
Auto merge of #67140 - Centril:rollup-h7rbw7y, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - #66325 (Change unused_labels from allow to warn)
 - #66991 (Cleanup BodyCache)
 - #67101 (use `#[allow(unused_attributes)]` to paper over incr.comp problem)
 - #67114 (Make `ForeignItem` an alias of `Item`.)
 - #67129 (Fixes typo)

Failed merges:

 - #66886 (Remove the borrow check::nll submodule)

r? @ghost
  • Loading branch information
bors committed Dec 8, 2019
2 parents de17464 + 32e27c2 commit e862c01
Show file tree
Hide file tree
Showing 75 changed files with 306 additions and 304 deletions.
1 change: 1 addition & 0 deletions src/libcore/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ impl<T> From<T> for T {
///
/// [#64715]: https://github.com/rust-lang/rust/issues/64715
#[stable(feature = "convert_infallible", since = "1.34.0")]
#[allow(unused_attributes)] // FIXME(#58633): do a principled fix instead.
#[rustc_reservation_impl = "permitting this impl would forbid us from adding \
`impl<T> From<!> for T` later; see rust-lang/rust#64715 for details"]
impl<T> From<!> for T {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<rustc::mir::BodyCache<$tcx>>,
[] mir: rustc::mir::BodyCache<$tcx>,
[] steal_mir: rustc::ty::steal::Steal<rustc::mir::BodyAndCache<$tcx>>,
[] 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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ declare_lint! {

declare_lint! {
pub UNUSED_LABELS,
Allow,
Warn,
"detects labels that are never used"
}

Expand Down
54 changes: 25 additions & 29 deletions src/librustc/mir/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
}
Expand All @@ -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);
}
Expand All @@ -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<BasicBlock, BasicBlockData<'tcx>> {
Expand All @@ -163,48 +163,48 @@ impl BodyCache<'tcx> {
}
}

impl<'tcx> Index<BasicBlock> for BodyCache<'tcx> {
impl<'tcx> Index<BasicBlock> for BodyAndCache<'tcx> {
type Output = BasicBlockData<'tcx>;

fn index(&self, index: BasicBlock) -> &BasicBlockData<'tcx> {
&self.body[index]
}
}

impl<'tcx> IndexMut<BasicBlock> for BodyCache<'tcx> {
impl<'tcx> IndexMut<BasicBlock> 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 {
&self.body
}
}

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,
}
}

Expand All @@ -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<BasicBlock, BasicBlockData<'tcx>> {
&self.body.basic_blocks
}
Expand All @@ -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<BasicBlock>;
}

impl graph::WithPredecessors for ReadOnlyBodyCache<'a, 'tcx> {
impl graph::WithPredecessors for ReadOnlyBodyAndCache<'a, 'tcx> {
fn predecessors(
&self,
node: Self::Node,
Expand All @@ -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,
Expand All @@ -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<Successors<'b>>;
}


impl Deref for ReadOnlyBodyCache<'a, 'tcx> {
impl Deref for ReadOnlyBodyAndCache<'a, 'tcx> {
type Target = &'a Body<'tcx>;

fn deref(&self) -> &Self::Target {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -108,7 +108,7 @@ pub struct Body<'tcx> {
pub yield_ty: Option<Ty<'tcx>>,

/// Generator drop glue.
pub generator_drop: Option<Box<BodyCache<'tcx>>>,
pub generator_drop: Option<Box<BodyAndCache<'tcx>>>,

/// The layout of a generator. Produced by the state transformation.
pub generator_layout: Option<GeneratorLayout<'tcx>>,
Expand Down Expand Up @@ -2597,7 +2597,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`.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
};
}

Expand Down
18 changes: 9 additions & 9 deletions src/librustc/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<mir::BodyCache<'tcx>> {}
query mir_built(_: DefId) -> &'tcx Steal<mir::BodyAndCache<'tcx>> {}

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

query mir_validated(_: DefId) ->
(
&'tcx Steal<mir::BodyCache<'tcx>>,
&'tcx Steal<IndexVec<mir::Promoted, mir::BodyCache<'tcx>>>
&'tcx Steal<mir::BodyAndCache<'tcx>>,
&'tcx Steal<IndexVec<mir::Promoted, mir::BodyAndCache<'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::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<crate::mir::BodyCache<'tcx>>
let mir: Option<crate::mir::BodyAndCache<'tcx>>
= tcx.queries.on_disk_cache.try_load_query_result(tcx, id);
mir.map(|x| {
let cache = tcx.arena.alloc(x);
Expand All @@ -139,13 +139,13 @@ rustc_queries! {
}
}

query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::BodyCache<'tcx>> {
query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::BodyAndCache<'tcx>> {
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);
Expand Down Expand Up @@ -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()) }
}
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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;
Expand Down Expand Up @@ -1084,17 +1084,17 @@ impl<'tcx> TyCtxt<'tcx> {
&self.hir_map
}

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2486,7 +2486,7 @@ where
'descend_newtypes: while !fat_pointer_layout.ty.is_unsafe_ptr()
&& !fat_pointer_layout.ty.is_region_ptr()
{
'iter_fields: for i in 0..fat_pointer_layout.fields.count() {
for i in 0..fat_pointer_layout.fields.count() {
let field_layout = fat_pointer_layout.field(cx, i);

if !field_layout.is_zst() {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2981,7 +2981,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()
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
// a loop.
fn maybe_sideeffect<Bx: BuilderMethods<'a, 'tcx>>(
&self,
mir: mir::ReadOnlyBodyCache<'tcx, 'tcx>,
mir: mir::ReadOnlyBodyAndCache<'tcx, 'tcx>,
bx: &mut Bx,
targets: &[mir::BasicBlock],
) {
Expand Down Expand Up @@ -718,7 +718,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
'descend_newtypes: while !op.layout.ty.is_unsafe_ptr()
&& !op.layout.ty.is_region_ptr()
{
'iter_fields: for i in 0..op.layout.fields.count() {
for i in 0..op.layout.fields.count() {
let field = op.extract_field(&mut bx, i);
if !field.layout.is_zst() {
// we found the one non-zero-sized field that is allowed
Expand Down
Loading

0 comments on commit e862c01

Please sign in to comment.