Skip to content

Commit

Permalink
Replace (Body, WithOptConstParam) with Body where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
ecstatic-morse committed Oct 4, 2020
1 parent 52484c5 commit 2e35cf9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
7 changes: 4 additions & 3 deletions compiler/rustc_mir/src/borrow_check/mod.rs
Expand Up @@ -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");

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_mir/src/borrow_check/nll.rs
Expand Up @@ -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::{
Expand Down Expand Up @@ -58,11 +58,12 @@ crate struct NllOutput<'tcx> {
/// `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.
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_mir/src/transform/promote_consts.rs
Expand Up @@ -60,15 +60,13 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'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);
}
}
Expand Down Expand Up @@ -970,10 +968,10 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {

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);
Expand Down Expand Up @@ -1133,7 +1131,6 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> {
}

pub fn promote_candidates<'tcx>(
def: ty::WithOptConstParam<DefId>,
body: &mut Body<'tcx>,
tcx: TyCtxt<'tcx>,
mut temps: IndexVec<Local, TempState>,
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 2e35cf9

Please sign in to comment.