1
Fork 0

Make MIR basic blocks field public

This makes it possible to mutably borrow different fields of the MIR
body without resorting to methods like `basic_blocks_local_decls_mut_and_var_debug_info`.

To preserve validity of control flow graph caches in the presence of
modifications, a new struct `BasicBlocks` wraps together basic blocks
and control flow graph caches.

The `BasicBlocks` dereferences to `IndexVec<BasicBlock, BasicBlockData>`.
On the other hand a mutable access requires explicit `as_mut()` call.
This commit is contained in:
Tomasz Miąsko 2022-07-04 00:00:00 +00:00
parent fac8fa5672
commit c9dd1d9983
21 changed files with 213 additions and 195 deletions

View file

@ -27,12 +27,10 @@ pub fn lower_slice_len_calls<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
};
// The one successor remains unchanged, so no need to invalidate
let (basic_blocks, local_decls, _) =
body.basic_blocks_local_decls_mut_and_var_debug_info_no_invalidate();
let basic_blocks = body.basic_blocks.as_mut_preserves_cfg();
for block in basic_blocks {
// lower `<[_]>::len` calls
lower_slice_len_call(tcx, block, &*local_decls, slice_len_fn_item_def_id);
lower_slice_len_call(tcx, block, &body.local_decls, slice_len_fn_item_def_id);
}
}