Skip to content

Commit 7595130

Browse files
committed
Delay creating a ResultsCursor for MaybeInitializedPlaces.
This lets us pass an immutable `Results<...>` rather than a `&mut ResultsCursor<...>` through several functions. Passing it by value instead of by reference also removes the need for the explicit `drop`.
1 parent 2c0f766 commit 7595130

File tree

5 files changed

+16
-22
lines changed

5 files changed

+16
-22
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,10 @@ fn do_mir_borrowck<'tcx>(
192192
.iter_enumerated()
193193
.map(|(idx, body)| (idx, MoveData::gather_moves(body, tcx, |_| true)));
194194

195-
let mut flow_inits = MaybeInitializedPlaces::new(tcx, body, &move_data)
195+
let flow_inits = MaybeInitializedPlaces::new(tcx, body, &move_data)
196196
.into_engine(tcx, body)
197197
.pass_name("borrowck")
198-
.iterate_to_fixpoint()
199-
.into_results_cursor(body);
198+
.iterate_to_fixpoint();
200199

201200
let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind(def).is_fn_or_closure();
202201
let borrow_set = BorrowSet::build(tcx, body, locals_are_invalidated_at_exit, &move_data);
@@ -216,7 +215,7 @@ fn do_mir_borrowck<'tcx>(
216215
&promoted,
217216
&location_table,
218217
param_env,
219-
&mut flow_inits,
218+
flow_inits,
220219
&move_data,
221220
&borrow_set,
222221
tcx.closure_captures(def),
@@ -238,11 +237,6 @@ fn do_mir_borrowck<'tcx>(
238237
&mut diags,
239238
);
240239

241-
// The various `flow_*` structures can be large. We drop `flow_inits` here
242-
// so it doesn't overlap with the others below. This reduces peak memory
243-
// usage significantly on some benchmarks.
244-
drop(flow_inits);
245-
246240
let flow_borrows = Borrows::new(tcx, body, &regioncx, &borrow_set)
247241
.into_engine(tcx, body)
248242
.pass_name("borrowck")

compiler/rustc_borrowck/src/nll.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_middle::mir::{
1616
};
1717
use rustc_middle::ty::print::with_no_trimmed_paths;
1818
use rustc_middle::ty::{self, OpaqueHiddenType, TyCtxt};
19-
use rustc_mir_dataflow::ResultsCursor;
19+
use rustc_mir_dataflow::Results;
2020
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
2121
use rustc_mir_dataflow::move_paths::MoveData;
2222
use rustc_mir_dataflow::points::DenseLocationMap;
@@ -78,11 +78,11 @@ pub(crate) fn replace_regions_in_mir<'tcx>(
7878
pub(crate) fn compute_regions<'a, 'tcx>(
7979
infcx: &BorrowckInferCtxt<'tcx>,
8080
universal_regions: UniversalRegions<'tcx>,
81-
body: &Body<'tcx>,
81+
body: &'a Body<'tcx>,
8282
promoted: &IndexSlice<Promoted, Body<'tcx>>,
8383
location_table: &LocationTable,
8484
param_env: ty::ParamEnv<'tcx>,
85-
flow_inits: &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
85+
flow_inits: Results<'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
8686
move_data: &MoveData<'tcx>,
8787
borrow_set: &BorrowSet<'tcx>,
8888
upvars: &[&ty::CapturedPlace<'tcx>],

compiler/rustc_borrowck/src/type_check/liveness/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_middle::mir::{Body, Local, Location, SourceInfo};
55
use rustc_middle::span_bug;
66
use rustc_middle::ty::visit::TypeVisitable;
77
use rustc_middle::ty::{GenericArgsRef, Region, RegionVid, Ty, TyCtxt};
8-
use rustc_mir_dataflow::ResultsCursor;
8+
use rustc_mir_dataflow::Results;
99
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
1010
use rustc_mir_dataflow::move_paths::MoveData;
1111
use rustc_mir_dataflow::points::DenseLocationMap;
@@ -30,9 +30,9 @@ mod trace;
3030
/// performed before
3131
pub(super) fn generate<'a, 'tcx>(
3232
typeck: &mut TypeChecker<'_, 'tcx>,
33-
body: &Body<'tcx>,
33+
body: &'a Body<'tcx>,
3434
elements: &DenseLocationMap,
35-
flow_inits: &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
35+
flow_inits: Results<'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
3636
move_data: &MoveData<'tcx>,
3737
) {
3838
debug!("liveness::generate");

compiler/rustc_borrowck/src/type_check/liveness/trace.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use rustc_infer::infer::outlives::for_liveness;
66
use rustc_middle::mir::{BasicBlock, Body, ConstraintCategory, Local, Location};
77
use rustc_middle::traits::query::DropckOutlivesResult;
88
use rustc_middle::ty::{Ty, TyCtxt, TypeVisitable, TypeVisitableExt};
9-
use rustc_mir_dataflow::ResultsCursor;
109
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
1110
use rustc_mir_dataflow::move_paths::{HasMoveData, MoveData, MovePathIndex};
1211
use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex};
12+
use rustc_mir_dataflow::{Results, ResultsCursor};
1313
use rustc_span::DUMMY_SP;
1414
use rustc_trait_selection::traits::query::type_op::{DropckOutlives, TypeOp, TypeOpOutput};
1515
use tracing::debug;
@@ -36,9 +36,9 @@ use crate::type_check::{NormalizeLocation, TypeChecker};
3636
/// this respects `#[may_dangle]` annotations).
3737
pub(super) fn trace<'a, 'tcx>(
3838
typeck: &mut TypeChecker<'_, 'tcx>,
39-
body: &Body<'tcx>,
39+
body: &'a Body<'tcx>,
4040
elements: &DenseLocationMap,
41-
flow_inits: &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
41+
flow_inits: Results<'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
4242
move_data: &MoveData<'tcx>,
4343
relevant_live_locals: Vec<Local>,
4444
boring_locals: Vec<Local>,
@@ -79,7 +79,7 @@ pub(super) fn trace<'a, 'tcx>(
7979
let cx = LivenessContext {
8080
typeck,
8181
body,
82-
flow_inits,
82+
flow_inits: &mut flow_inits.into_results_cursor(body),
8383
elements,
8484
local_use_map,
8585
move_data,

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use rustc_middle::ty::{
3232
UserType, UserTypeAnnotationIndex,
3333
};
3434
use rustc_middle::{bug, span_bug};
35-
use rustc_mir_dataflow::ResultsCursor;
35+
use rustc_mir_dataflow::Results;
3636
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
3737
use rustc_mir_dataflow::move_paths::MoveData;
3838
use rustc_mir_dataflow::points::DenseLocationMap;
@@ -119,13 +119,13 @@ mod relate_tys;
119119
pub(crate) fn type_check<'a, 'tcx>(
120120
infcx: &BorrowckInferCtxt<'tcx>,
121121
param_env: ty::ParamEnv<'tcx>,
122-
body: &Body<'tcx>,
122+
body: &'a Body<'tcx>,
123123
promoted: &IndexSlice<Promoted, Body<'tcx>>,
124124
universal_regions: Rc<UniversalRegions<'tcx>>,
125125
location_table: &LocationTable,
126126
borrow_set: &BorrowSet<'tcx>,
127127
all_facts: &mut Option<AllFacts>,
128-
flow_inits: &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
128+
flow_inits: Results<'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
129129
move_data: &MoveData<'tcx>,
130130
elements: Rc<DenseLocationMap>,
131131
upvars: &[&ty::CapturedPlace<'tcx>],

0 commit comments

Comments
 (0)