Skip to content

Commit 4519788

Browse files
committed
move MaybeInitializedPlaces computation to where it's used
This dataflow analysis is only used by `liveness::trace`. We move it there to make it lazy.
1 parent c583fa6 commit 4519788

File tree

5 files changed

+11
-27
lines changed

5 files changed

+11
-27
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ use rustc_middle::ty::{
4040
self, ParamEnv, RegionVid, Ty, TyCtxt, TypeFoldable, TypeVisitable, TypingMode, fold_regions,
4141
};
4242
use rustc_middle::{bug, span_bug};
43-
use rustc_mir_dataflow::impls::{
44-
EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces,
45-
};
43+
use rustc_mir_dataflow::impls::{EverInitializedPlaces, MaybeUninitializedPlaces};
4644
use rustc_mir_dataflow::move_paths::{
4745
InitIndex, InitLocation, LookupResult, MoveData, MovePathIndex,
4846
};
@@ -324,10 +322,6 @@ fn do_mir_borrowck<'tcx>(
324322

325323
let move_data = MoveData::gather_moves(body, tcx, |_| true);
326324

327-
let flow_inits = MaybeInitializedPlaces::new(tcx, body, &move_data)
328-
.iterate_to_fixpoint(tcx, body, Some("borrowck"))
329-
.into_results_cursor(body);
330-
331325
let locals_are_invalidated_at_exit = tcx.hir_body_owner_kind(def).is_fn_or_closure();
332326
let borrow_set = BorrowSet::build(tcx, body, locals_are_invalidated_at_exit, &move_data);
333327

@@ -346,7 +340,6 @@ fn do_mir_borrowck<'tcx>(
346340
body,
347341
&promoted,
348342
&location_table,
349-
flow_inits,
350343
&move_data,
351344
&borrow_set,
352345
consumer_options,

compiler/rustc_borrowck/src/nll.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ use rustc_middle::mir::pretty::{PrettyPrintMirOptions, dump_mir_with_options};
1111
use rustc_middle::mir::{Body, PassWhere, Promoted, create_dump_file, dump_enabled, dump_mir};
1212
use rustc_middle::ty::print::with_no_trimmed_paths;
1313
use rustc_middle::ty::{self, TyCtxt};
14-
use rustc_mir_dataflow::ResultsCursor;
15-
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
1614
use rustc_mir_dataflow::move_paths::MoveData;
1715
use rustc_mir_dataflow::points::DenseLocationMap;
1816
use rustc_session::config::MirIncludeSpans;
@@ -75,14 +73,13 @@ pub(crate) fn replace_regions_in_mir<'tcx>(
7573
/// Computes the (non-lexical) regions from the input MIR.
7674
///
7775
/// This may result in errors being reported.
78-
pub(crate) fn compute_regions<'a, 'tcx>(
76+
pub(crate) fn compute_regions<'tcx>(
7977
root_cx: &mut BorrowCheckRootCtxt<'tcx>,
8078
infcx: &BorrowckInferCtxt<'tcx>,
8179
universal_regions: UniversalRegions<'tcx>,
8280
body: &Body<'tcx>,
8381
promoted: &IndexSlice<Promoted, Body<'tcx>>,
8482
location_table: &PoloniusLocationTable,
85-
flow_inits: ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
8683
move_data: &MoveData<'tcx>,
8784
borrow_set: &BorrowSet<'tcx>,
8885
consumer_options: Option<ConsumerOptions>,
@@ -112,7 +109,6 @@ pub(crate) fn compute_regions<'a, 'tcx>(
112109
location_table,
113110
borrow_set,
114111
&mut polonius_facts,
115-
flow_inits,
116112
move_data,
117113
Rc::clone(&location_map),
118114
);

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use rustc_middle::mir::{Body, Local, Location, SourceInfo};
55
use rustc_middle::span_bug;
66
use rustc_middle::ty::relate::Relate;
77
use rustc_middle::ty::{GenericArgsRef, Region, RegionVid, Ty, TyCtxt, TypeVisitable};
8-
use rustc_mir_dataflow::ResultsCursor;
9-
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
108
use rustc_mir_dataflow::move_paths::MoveData;
119
use rustc_mir_dataflow::points::DenseLocationMap;
1210
use tracing::debug;
@@ -28,10 +26,9 @@ mod trace;
2826
///
2927
/// N.B., this computation requires normalization; therefore, it must be
3028
/// performed before
31-
pub(super) fn generate<'a, 'tcx>(
29+
pub(super) fn generate<'tcx>(
3230
typeck: &mut TypeChecker<'_, 'tcx>,
3331
location_map: &DenseLocationMap,
34-
flow_inits: ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
3532
move_data: &MoveData<'tcx>,
3633
) {
3734
debug!("liveness::generate");
@@ -58,7 +55,7 @@ pub(super) fn generate<'a, 'tcx>(
5855
let (relevant_live_locals, boring_locals) =
5956
compute_relevant_live_locals(typeck.tcx(), &free_regions, typeck.body);
6057

61-
trace::trace(typeck, location_map, flow_inits, move_data, relevant_live_locals, boring_locals);
58+
trace::trace(typeck, location_map, move_data, relevant_live_locals, boring_locals);
6259

6360
// Mark regions that should be live where they appear within rvalues or within a call: like
6461
// args, regions, and types.

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use rustc_middle::mir::{BasicBlock, Body, ConstraintCategory, HasLocalDecls, Loc
77
use rustc_middle::traits::query::DropckOutlivesResult;
88
use rustc_middle::ty::relate::Relate;
99
use rustc_middle::ty::{Ty, TyCtxt, TypeVisitable, TypeVisitableExt};
10-
use rustc_mir_dataflow::ResultsCursor;
1110
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
1211
use rustc_mir_dataflow::move_paths::{HasMoveData, MoveData, MovePathIndex};
1312
use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex};
13+
use rustc_mir_dataflow::{Analysis, ResultsCursor};
1414
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
1515
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
1616
use rustc_trait_selection::traits::ObligationCtxt;
@@ -37,15 +37,17 @@ use crate::type_check::{NormalizeLocation, TypeChecker};
3737
/// DROP-LIVE set are to the liveness sets for regions found in the
3838
/// `dropck_outlives` result of the variable's type (in particular,
3939
/// this respects `#[may_dangle]` annotations).
40-
pub(super) fn trace<'a, 'tcx>(
40+
pub(super) fn trace<'tcx>(
4141
typeck: &mut TypeChecker<'_, 'tcx>,
4242
location_map: &DenseLocationMap,
43-
flow_inits: ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
4443
move_data: &MoveData<'tcx>,
4544
relevant_live_locals: Vec<Local>,
4645
boring_locals: Vec<Local>,
4746
) {
4847
let local_use_map = &LocalUseMap::build(&relevant_live_locals, location_map, typeck.body);
48+
let flow_inits = MaybeInitializedPlaces::new(typeck.tcx(), typeck.body, move_data)
49+
.iterate_to_fixpoint(typeck.tcx(), typeck.body, Some("borrowck"))
50+
.into_results_cursor(typeck.body);
4951
let cx = LivenessContext {
5052
typeck,
5153
flow_inits,

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ use rustc_middle::ty::{
3030
TypeVisitableExt, UserArgs, UserTypeAnnotationIndex, fold_regions,
3131
};
3232
use rustc_middle::{bug, span_bug};
33-
use rustc_mir_dataflow::ResultsCursor;
34-
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
3533
use rustc_mir_dataflow::move_paths::MoveData;
3634
use rustc_mir_dataflow::points::DenseLocationMap;
3735
use rustc_span::def_id::CRATE_DEF_ID;
@@ -97,10 +95,9 @@ mod relate_tys;
9795
/// - `location_table` -- for datalog polonius, the map between `Location`s and `RichLocation`s
9896
/// - `borrow_set` -- information about borrows occurring in `body`
9997
/// - `polonius_facts` -- when using Polonius, this is the generated set of Polonius facts
100-
/// - `flow_inits` -- results of a maybe-init dataflow analysis
10198
/// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysis
10299
/// - `location_map` -- map between MIR `Location` and `PointIndex`
103-
pub(crate) fn type_check<'a, 'tcx>(
100+
pub(crate) fn type_check<'tcx>(
104101
root_cx: &mut BorrowCheckRootCtxt<'tcx>,
105102
infcx: &BorrowckInferCtxt<'tcx>,
106103
body: &Body<'tcx>,
@@ -109,7 +106,6 @@ pub(crate) fn type_check<'a, 'tcx>(
109106
location_table: &PoloniusLocationTable,
110107
borrow_set: &BorrowSet<'tcx>,
111108
polonius_facts: &mut Option<PoloniusFacts>,
112-
flow_inits: ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
113109
move_data: &MoveData<'tcx>,
114110
location_map: Rc<DenseLocationMap>,
115111
) -> MirTypeckResults<'tcx> {
@@ -167,7 +163,7 @@ pub(crate) fn type_check<'a, 'tcx>(
167163
typeck.equate_inputs_and_outputs(&normalized_inputs_and_output);
168164
typeck.check_signature_annotation();
169165

170-
liveness::generate(&mut typeck, &location_map, flow_inits, move_data);
166+
liveness::generate(&mut typeck, &location_map, move_data);
171167

172168
let opaque_type_values =
173169
opaque_types::take_opaques_and_register_member_constraints(&mut typeck);

0 commit comments

Comments
 (0)