Replace (Body, WithOptConstParam)
with Body
where possible
This commit is contained in:
parent
52484c59e5
commit
2e35cf973b
3 changed files with 10 additions and 11 deletions
|
@ -111,7 +111,7 @@ fn mir_borrowck<'tcx>(
|
||||||
let opt_closure_req = tcx.infer_ctxt().enter(|infcx| {
|
let opt_closure_req = tcx.infer_ctxt().enter(|infcx| {
|
||||||
let input_body: &Body<'_> = &input_body.borrow();
|
let input_body: &Body<'_> = &input_body.borrow();
|
||||||
let promoted: &IndexVec<_, _> = &promoted.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");
|
debug!("mir_borrowck done");
|
||||||
|
|
||||||
|
@ -122,8 +122,9 @@ fn do_mir_borrowck<'a, 'tcx>(
|
||||||
infcx: &InferCtxt<'a, 'tcx>,
|
infcx: &InferCtxt<'a, 'tcx>,
|
||||||
input_body: &Body<'tcx>,
|
input_body: &Body<'tcx>,
|
||||||
input_promoted: &IndexVec<Promoted, Body<'tcx>>,
|
input_promoted: &IndexVec<Promoted, Body<'tcx>>,
|
||||||
def: ty::WithOptConstParam<LocalDefId>,
|
|
||||||
) -> BorrowCheckResult<'tcx> {
|
) -> BorrowCheckResult<'tcx> {
|
||||||
|
let def = input_body.source.with_opt_param().as_local().unwrap();
|
||||||
|
|
||||||
debug!("do_mir_borrowck(def = {:?})", def);
|
debug!("do_mir_borrowck(def = {:?})", def);
|
||||||
|
|
||||||
let tcx = infcx.tcx;
|
let tcx = infcx.tcx;
|
||||||
|
@ -185,7 +186,7 @@ fn do_mir_borrowck<'a, 'tcx>(
|
||||||
// will have a lifetime tied to the inference context.
|
// will have a lifetime tied to the inference context.
|
||||||
let mut body = input_body.clone();
|
let mut body = input_body.clone();
|
||||||
let mut promoted = input_promoted.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 body = &body; // no further changes
|
||||||
|
|
||||||
let location_table = &LocationTable::new(&body);
|
let location_table = &LocationTable::new(&body);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_errors::Diagnostic;
|
use rustc_errors::Diagnostic;
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_infer::infer::InferCtxt;
|
use rustc_infer::infer::InferCtxt;
|
||||||
use rustc_middle::mir::{
|
use rustc_middle::mir::{
|
||||||
|
@ -58,11 +58,12 @@ crate struct NllOutput<'tcx> {
|
||||||
/// `compute_regions`.
|
/// `compute_regions`.
|
||||||
pub(in crate::borrow_check) fn replace_regions_in_mir<'cx, 'tcx>(
|
pub(in crate::borrow_check) fn replace_regions_in_mir<'cx, 'tcx>(
|
||||||
infcx: &InferCtxt<'cx, 'tcx>,
|
infcx: &InferCtxt<'cx, 'tcx>,
|
||||||
def: ty::WithOptConstParam<LocalDefId>,
|
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
body: &mut Body<'tcx>,
|
body: &mut Body<'tcx>,
|
||||||
promoted: &mut IndexVec<Promoted, Body<'tcx>>,
|
promoted: &mut IndexVec<Promoted, Body<'tcx>>,
|
||||||
) -> UniversalRegions<'tcx> {
|
) -> UniversalRegions<'tcx> {
|
||||||
|
let def = body.source.with_opt_param().as_local().unwrap();
|
||||||
|
|
||||||
debug!("replace_regions_in_mir(def={:?})", def);
|
debug!("replace_regions_in_mir(def={:?})", def);
|
||||||
|
|
||||||
// Compute named region information. This also renumbers the inputs/outputs.
|
// Compute named region information. This also renumbers the inputs/outputs.
|
||||||
|
|
|
@ -60,15 +60,13 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let def = body.source.with_opt_param().expect_local();
|
|
||||||
|
|
||||||
let mut rpo = traversal::reverse_postorder(body);
|
let mut rpo = traversal::reverse_postorder(body);
|
||||||
let ccx = ConstCx::new(tcx, body);
|
let ccx = ConstCx::new(tcx, body);
|
||||||
let (temps, all_candidates) = collect_temps_and_candidates(&ccx, &mut rpo);
|
let (temps, all_candidates) = collect_temps_and_candidates(&ccx, &mut rpo);
|
||||||
|
|
||||||
let promotable_candidates = validate_candidates(&ccx, &temps, &all_candidates);
|
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);
|
self.promoted_fragments.set(promoted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -970,10 +968,10 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
|
||||||
|
|
||||||
fn promote_candidate(
|
fn promote_candidate(
|
||||||
mut self,
|
mut self,
|
||||||
def: ty::WithOptConstParam<DefId>,
|
|
||||||
candidate: Candidate,
|
candidate: Candidate,
|
||||||
next_promoted_id: usize,
|
next_promoted_id: usize,
|
||||||
) -> Option<Body<'tcx>> {
|
) -> Option<Body<'tcx>> {
|
||||||
|
let def = self.source.source.with_opt_param();
|
||||||
let mut rvalue = {
|
let mut rvalue = {
|
||||||
let promoted = &mut self.promoted;
|
let promoted = &mut self.promoted;
|
||||||
let promoted_id = Promoted::new(next_promoted_id);
|
let promoted_id = Promoted::new(next_promoted_id);
|
||||||
|
@ -1133,7 +1131,6 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn promote_candidates<'tcx>(
|
pub fn promote_candidates<'tcx>(
|
||||||
def: ty::WithOptConstParam<DefId>,
|
|
||||||
body: &mut Body<'tcx>,
|
body: &mut Body<'tcx>,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
mut temps: IndexVec<Local, TempState>,
|
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
|
//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());
|
promoted.source.promoted = Some(promotions.next_index());
|
||||||
promotions.push(promoted);
|
promotions.push(promoted);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue