Compute predecessors in mir_build query and use existing cache for generating ReadOnlyBodyCache, remove unneeded fns
This commit is contained in:
parent
ed90818ac8
commit
05dc5e9f47
3 changed files with 7 additions and 14 deletions
|
@ -181,8 +181,6 @@ impl BodyCache<'tcx> {
|
||||||
ReadOnlyBodyCache::new(&self.cache, &self.body)
|
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>> {
|
pub fn basic_blocks_mut(&mut self) -> &mut IndexVec<BasicBlock, BasicBlockData<'tcx>> {
|
||||||
self.cache.basic_blocks_mut(&mut self.body)
|
self.cache.basic_blocks_mut(&mut self.body)
|
||||||
}
|
}
|
||||||
|
@ -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]
|
#[inline]
|
||||||
pub fn predecessors(&self) -> &IndexVec<BasicBlock, Vec<BasicBlock>> {
|
pub fn predecessors(&self) -> &IndexVec<BasicBlock, Vec<BasicBlock>> {
|
||||||
self.cache.predecessors.as_ref().unwrap()
|
self.cache.predecessors.as_ref().unwrap()
|
||||||
|
|
|
@ -196,7 +196,9 @@ pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> BodyCache<'_> {
|
||||||
|
|
||||||
lints::check(tcx, &body, def_id);
|
lints::check(tcx, &body, def_id);
|
||||||
|
|
||||||
BodyCache::new(body)
|
let mut body = BodyCache::new(body);
|
||||||
|
body.ensure_predecessors();
|
||||||
|
body
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -528,9 +528,10 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: DefId) -> UnsafetyCheckResult
|
||||||
hir::BodyOwnerKind::Static(_) => (true, false),
|
hir::BodyOwnerKind::Static(_) => (true, false),
|
||||||
};
|
};
|
||||||
let mut checker = UnsafetyChecker::new(const_context, min_const_fn, body, tcx, param_env);
|
let mut checker = UnsafetyChecker::new(const_context, min_const_fn, body, tcx, param_env);
|
||||||
let mut cache = body.cache().clone();
|
// mir_built ensures that body has a computed cache, so we don't (and can't) attempt to
|
||||||
let read_only_cache = ReadOnlyBodyCache::from_external_cache(&mut cache, body);
|
// recompute it here.
|
||||||
checker.visit_body(read_only_cache);
|
let body = body.unwrap_read_only();
|
||||||
|
checker.visit_body(body);
|
||||||
|
|
||||||
check_unused_unsafe(tcx, def_id, &checker.used_unsafe, &mut checker.inherited_blocks);
|
check_unused_unsafe(tcx, def_id, &checker.used_unsafe, &mut checker.inherited_blocks);
|
||||||
UnsafetyCheckResult {
|
UnsafetyCheckResult {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue