Skip to content

Commit

Permalink
Compute predecessors in mir_build query and use existing cache for ge…
Browse files Browse the repository at this point in the history
…nerating ReadOnlyBodyCache, remove unneeded fns
  • Loading branch information
Nashenas88 committed Dec 2, 2019
1 parent ed90818 commit 05dc5e9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
10 changes: 0 additions & 10 deletions src/librustc/mir/cache.rs
Expand Up @@ -181,8 +181,6 @@ impl BodyCache<'tcx> {
ReadOnlyBodyCache::new(&self.cache, &self.body)
}

pub fn cache(&self) -> &Cache { &self.cache }

pub fn basic_blocks_mut(&mut self) -> &mut IndexVec<BasicBlock, BasicBlockData<'tcx>> {
self.cache.basic_blocks_mut(&mut self.body)
}
Expand Down Expand Up @@ -240,14 +238,6 @@ impl ReadOnlyBodyCache<'a, 'tcx> {
}
}

pub fn from_external_cache(cache: &'a mut Cache, body: &'a Body<'tcx>) -> Self {
cache.ensure_predecessors(body);
Self {
cache,
body,
}
}

#[inline]
pub fn predecessors(&self) -> &IndexVec<BasicBlock, Vec<BasicBlock>> {
self.cache.predecessors.as_ref().unwrap()
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_mir/build/mod.rs
Expand Up @@ -196,7 +196,9 @@ pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> BodyCache<'_> {

lints::check(tcx, &body, def_id);

BodyCache::new(body)
let mut body = BodyCache::new(body);
body.ensure_predecessors();
body
})
}

Expand Down
7 changes: 4 additions & 3 deletions src/librustc_mir/transform/check_unsafety.rs
Expand Up @@ -528,9 +528,10 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: DefId) -> UnsafetyCheckResult
hir::BodyOwnerKind::Static(_) => (true, false),
};
let mut checker = UnsafetyChecker::new(const_context, min_const_fn, body, tcx, param_env);
let mut cache = body.cache().clone();
let read_only_cache = ReadOnlyBodyCache::from_external_cache(&mut cache, body);
checker.visit_body(read_only_cache);
// 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);
UnsafetyCheckResult {
Expand Down

0 comments on commit 05dc5e9

Please sign in to comment.