Replace (Body, WithOptConstParam) with Body where possible

This commit is contained in:
Dylan MacKenzie 2020-10-04 16:59:19 -07:00
parent 52484c59e5
commit 2e35cf973b
3 changed files with 10 additions and 11 deletions

View File

@ -111,7 +111,7 @@ fn mir_borrowck<'tcx>(
let opt_closure_req = tcx.infer_ctxt().enter(|infcx| {
let input_body: &Body<'_> = &input_body.borrow();
let promoted: &IndexVec<_, _> = &promoted.borrow();
do_mir_borrowck(&infcx, input_body, promoted, def)
do_mir_borrowck(&infcx, input_body, promoted)
});
debug!("mir_borrowck done");
@ -122,8 +122,9 @@ fn do_mir_borrowck<'a, 'tcx>(
infcx: &InferCtxt<'a, 'tcx>,
input_body: &Body<'tcx>,
input_promoted: &IndexVec<Promoted, Body<'tcx>>,
def: ty::WithOptConstParam<LocalDefId>,
) -> BorrowCheckResult<'tcx> {
let def = input_body.source.with_opt_param().as_local().unwrap();
debug!("do_mir_borrowck(def = {:?})", def);
let tcx = infcx.tcx;
@ -185,7 +186,7 @@ fn do_mir_borrowck<'a, 'tcx>(
// will have a lifetime tied to the inference context.
let mut body = input_body.clone();
let mut promoted = input_promoted.clone();
let free_regions = nll::replace_regions_in_mir(infcx, def, param_env, &mut body, &mut promoted);
let free_regions = nll::replace_regions_in_mir(infcx, param_env, &mut body, &mut promoted);
let body = &body; // no further changes
let location_table = &LocationTable::new(&body);

View File

@ -2,7 +2,7 @@
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::Diagnostic;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::def_id::DefId;
use rustc_index::vec::IndexVec;
use rustc_infer::infer::InferCtxt;
use rustc_middle::mir::{
@ -58,11 +58,12 @@
/// `compute_regions`.
pub(in crate::borrow_check) fn replace_regions_in_mir<'cx, 'tcx>(
infcx: &InferCtxt<'cx, 'tcx>,
def: ty::WithOptConstParam<LocalDefId>,
param_env: ty::ParamEnv<'tcx>,
body: &mut Body<'tcx>,
promoted: &mut IndexVec<Promoted, Body<'tcx>>,
) -> UniversalRegions<'tcx> {
let def = body.source.with_opt_param().as_local().unwrap();
debug!("replace_regions_in_mir(def={:?})", def);
// Compute named region information. This also renumbers the inputs/outputs.

View File

@ -60,15 +60,13 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
return;
}
let def = body.source.with_opt_param().expect_local();
let mut rpo = traversal::reverse_postorder(body);
let ccx = ConstCx::new(tcx, body);
let (temps, all_candidates) = collect_temps_and_candidates(&ccx, &mut rpo);
let promotable_candidates = validate_candidates(&ccx, &temps, &all_candidates);
let promoted = promote_candidates(def.to_global(), body, tcx, temps, promotable_candidates);
let promoted = promote_candidates(body, tcx, temps, promotable_candidates);
self.promoted_fragments.set(promoted);
}
}
@ -970,10 +968,10 @@ fn promote_temp(&mut self, temp: Local) -> Local {
fn promote_candidate(
mut self,
def: ty::WithOptConstParam<DefId>,
candidate: Candidate,
next_promoted_id: usize,
) -> Option<Body<'tcx>> {
let def = self.source.source.with_opt_param();
let mut rvalue = {
let promoted = &mut self.promoted;
let promoted_id = Promoted::new(next_promoted_id);
@ -1133,7 +1131,6 @@ fn visit_local(&mut self, local: &mut Local, _: PlaceContext, _: Location) {
}
pub fn promote_candidates<'tcx>(
def: ty::WithOptConstParam<DefId>,
body: &mut Body<'tcx>,
tcx: TyCtxt<'tcx>,
mut temps: IndexVec<Local, TempState>,
@ -1191,7 +1188,7 @@ pub fn promote_candidates<'tcx>(
};
//FIXME(oli-obk): having a `maybe_push()` method on `IndexVec` might be nice
if let Some(mut promoted) = promoter.promote_candidate(def, candidate, promotions.len()) {
if let Some(mut promoted) = promoter.promote_candidate(candidate, promotions.len()) {
promoted.source.promoted = Some(promotions.next_index());
promotions.push(promoted);
}