Skip to content

Commit

Permalink
Remove unchecked inline attribute, remove unused functions, make chac…
Browse files Browse the repository at this point in the history
…he mod private again
  • Loading branch information
Nashenas88 committed Dec 2, 2019
1 parent c6354e9 commit 598797c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 48 deletions.
72 changes: 25 additions & 47 deletions src/librustc/mir/cache.rs
Expand Up @@ -32,45 +32,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for Cache {
}
}

macro_rules! get_predecessors {
(mut $self:ident, $block:expr, $body:expr) => {
$self.predecessors_for($block, $body)
};
($self:ident, $block:expr, $body:expr) => {
$self.unwrap_predecessors_for($block)
};
}

macro_rules! impl_predecessor_locations {
( ( $($pub:ident)? ) $name:ident $($mutability:ident)?) => {
$($pub)? fn $name<'a>(
&'a $($mutability)? self,
loc: Location,
body: &'a Body<'a>
) -> impl Iterator<Item = Location> + 'a {
let if_zero_locations = if loc.statement_index == 0 {
let predecessor_blocks = get_predecessors!($($mutability)? self, loc.block, body);
let num_predecessor_blocks = predecessor_blocks.len();
Some(
(0..num_predecessor_blocks)
.map(move |i| predecessor_blocks[i])
.map(move |bb| body.terminator_loc(bb)),
)
} else {
None
};

let if_not_zero_locations = if loc.statement_index == 0 {
None
} else {
Some(Location { block: loc.block, statement_index: loc.statement_index - 1 })
};

if_zero_locations.into_iter().flatten().chain(if_not_zero_locations)
}
};
}

impl Cache {
pub fn new() -> Self {
Self {
Expand Down Expand Up @@ -104,17 +65,35 @@ impl Cache {
self.predecessors.as_ref().unwrap()
}

fn predecessors_for(&mut self, bb: BasicBlock, body: &Body<'_>) -> &[BasicBlock] {
&self.predecessors(body)[bb]
}

fn unwrap_predecessors_for(&self, bb: BasicBlock) -> &[BasicBlock] {
&self.predecessors.as_ref().unwrap()[bb]
}

impl_predecessor_locations!((pub) predecessor_locations mut);

impl_predecessor_locations!(() unwrap_predecessor_locations);
fn unwrap_predecessor_locations<'a>(
&'a self,
loc: Location,
body: &'a Body<'a>
) -> impl Iterator<Item = Location> + 'a {
let if_zero_locations = if loc.statement_index == 0 {
let predecessor_blocks = self.unwrap_predecessors_for(loc.block);
let num_predecessor_blocks = predecessor_blocks.len();
Some(
(0..num_predecessor_blocks)
.map(move |i| predecessor_blocks[i])
.map(move |bb| body.terminator_loc(bb)),
)
} else {
None
};

let if_not_zero_locations = if loc.statement_index == 0 {
None
} else {
Some(Location { block: loc.block, statement_index: loc.statement_index - 1 })
};

if_zero_locations.into_iter().flatten().chain(if_not_zero_locations)
}

pub fn basic_blocks_mut<'a, 'tcx>(
&mut self,
Expand All @@ -125,7 +104,6 @@ impl Cache {
&mut body.basic_blocks
}

#[inline]
pub fn basic_blocks_and_local_decls_mut<'a, 'tcx>(
&mut self,
body: &'a mut Body<'tcx>
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/mod.rs
Expand Up @@ -41,7 +41,7 @@ pub use crate::mir::interpret::AssertMessage;
pub use crate::mir::cache::{BodyCache, ReadOnlyBodyCache};
pub use crate::read_only;

pub mod cache;
mod cache;
pub mod interpret;
pub mod mono;
pub mod tcx;
Expand Down

0 comments on commit 598797c

Please sign in to comment.