Skip to content

Commit 05dc5e9

Browse files
committed
Compute predecessors in mir_build query and use existing cache for generating ReadOnlyBodyCache, remove unneeded fns
1 parent ed90818 commit 05dc5e9

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

src/librustc/mir/cache.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ impl BodyCache<'tcx> {
181181
ReadOnlyBodyCache::new(&self.cache, &self.body)
182182
}
183183

184-
pub fn cache(&self) -> &Cache { &self.cache }
185-
186184
pub fn basic_blocks_mut(&mut self) -> &mut IndexVec<BasicBlock, BasicBlockData<'tcx>> {
187185
self.cache.basic_blocks_mut(&mut self.body)
188186
}
@@ -240,14 +238,6 @@ impl ReadOnlyBodyCache<'a, 'tcx> {
240238
}
241239
}
242240

243-
pub fn from_external_cache(cache: &'a mut Cache, body: &'a Body<'tcx>) -> Self {
244-
cache.ensure_predecessors(body);
245-
Self {
246-
cache,
247-
body,
248-
}
249-
}
250-
251241
#[inline]
252242
pub fn predecessors(&self) -> &IndexVec<BasicBlock, Vec<BasicBlock>> {
253243
self.cache.predecessors.as_ref().unwrap()

src/librustc_mir/build/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> BodyCache<'_> {
196196

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

199-
BodyCache::new(body)
199+
let mut body = BodyCache::new(body);
200+
body.ensure_predecessors();
201+
body
200202
})
201203
}
202204

src/librustc_mir/transform/check_unsafety.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,10 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: DefId) -> UnsafetyCheckResult
528528
hir::BodyOwnerKind::Static(_) => (true, false),
529529
};
530530
let mut checker = UnsafetyChecker::new(const_context, min_const_fn, body, tcx, param_env);
531-
let mut cache = body.cache().clone();
532-
let read_only_cache = ReadOnlyBodyCache::from_external_cache(&mut cache, body);
533-
checker.visit_body(read_only_cache);
531+
// mir_built ensures that body has a computed cache, so we don't (and can't) attempt to
532+
// recompute it here.
533+
let body = body.unwrap_read_only();
534+
checker.visit_body(body);
534535

535536
check_unused_unsafe(tcx, def_id, &checker.used_unsafe, &mut checker.inherited_blocks);
536537
UnsafetyCheckResult {

0 commit comments

Comments
 (0)