Skip to content

Commit 55ea8a0

Browse files
committed
Auto merge of #113382 - lqd:test-mcp510, r=<try>
[perf] test MCP510 r? `@ghost`
2 parents d76fe15 + 85bffc6 commit 55ea8a0

File tree

5 files changed

+41
-39
lines changed

5 files changed

+41
-39
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: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +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);
4948
let cx = LivenessContext {
5049
typeck,
51-
flow_inits,
50+
flow_inits: None,
5251
location_map,
5352
local_use_map,
5453
move_data,
@@ -65,7 +64,7 @@ pub(super) fn trace<'a, 'tcx>(
6564
}
6665

6766
/// Contextual state for the type-liveness coroutine.
68-
struct LivenessContext<'a, 'typeck, 'b, 'tcx> {
67+
struct LivenessContext<'a, 'typeck, 'tcx> {
6968
/// Current type-checker, giving us our inference context etc.
7069
///
7170
/// This also stores the body we're currently analyzing.
@@ -82,7 +81,7 @@ struct LivenessContext<'a, 'typeck, 'b, 'tcx> {
8281

8382
/// Results of dataflow tracking which variables (and paths) have been
8483
/// initialized.
85-
flow_inits: ResultsCursor<'b, 'tcx, MaybeInitializedPlaces<'b, 'tcx>>,
84+
flow_inits: Option<ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>>,
8685

8786
/// Index indicating where each variable is assigned, used, or
8887
/// dropped.
@@ -94,8 +93,8 @@ struct DropData<'tcx> {
9493
region_constraint_data: Option<&'tcx QueryRegionConstraints<'tcx>>,
9594
}
9695

97-
struct LivenessResults<'a, 'typeck, 'b, 'tcx> {
98-
cx: LivenessContext<'a, 'typeck, 'b, 'tcx>,
96+
struct LivenessResults<'a, 'typeck, 'tcx> {
97+
cx: LivenessContext<'a, 'typeck, 'tcx>,
9998

10099
/// Set of points that define the current local.
101100
defs: DenseBitSet<PointIndex>,
@@ -116,8 +115,8 @@ struct LivenessResults<'a, 'typeck, 'b, 'tcx> {
116115
stack: Vec<PointIndex>,
117116
}
118117

119-
impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
120-
fn new(cx: LivenessContext<'a, 'typeck, 'b, 'tcx>) -> Self {
118+
impl<'a, 'typeck, 'tcx> LivenessResults<'a, 'typeck, 'tcx> {
119+
fn new(cx: LivenessContext<'a, 'typeck, 'tcx>) -> Self {
121120
let num_points = cx.location_map.num_points();
122121
LivenessResults {
123122
cx,
@@ -459,20 +458,39 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
459458
}
460459
}
461460

462-
impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
461+
impl<'a, 'typeck, 'tcx> LivenessContext<'a, 'typeck, 'tcx> {
462+
fn ensure(&mut self) -> &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>> {
463+
// Lazily compute maybe-init dataflow analysis if it's needed: if there are relevant
464+
// live locals with drop points.
465+
if self.flow_inits.is_none() {
466+
use rustc_mir_dataflow::Analysis;
467+
let tcx = self.typeck.tcx();
468+
let body = self.typeck.body;
469+
let flow_inits = MaybeInitializedPlaces::new(tcx, body, self.move_data)
470+
.iterate_to_fixpoint(tcx, body, Some("borrowck"))
471+
.into_results_cursor(body);
472+
self.flow_inits = Some(flow_inits);
473+
}
474+
self.flow_inits.as_mut().expect("MaybeInitializedPlaces unavailable for drop-liveness")
475+
}
476+
}
477+
478+
impl<'tcx> LivenessContext<'_, '_, 'tcx> {
463479
fn body(&self) -> &Body<'tcx> {
464480
self.typeck.body
465481
}
482+
466483
/// Returns `true` if the local variable (or some part of it) is initialized at the current
467484
/// cursor position. Callers should call one of the `seek` methods immediately before to point
468485
/// the cursor to the desired location.
469-
fn initialized_at_curr_loc(&self, mpi: MovePathIndex) -> bool {
470-
let state = self.flow_inits.get();
486+
fn initialized_at_curr_loc(&mut self, mpi: MovePathIndex) -> bool {
487+
let flow_inits = self.ensure();
488+
let state = flow_inits.get();
471489
if state.contains(mpi) {
472490
return true;
473491
}
474492

475-
let move_paths = &self.flow_inits.analysis().move_data().move_paths;
493+
let move_paths = &flow_inits.analysis().move_data().move_paths;
476494
move_paths[mpi].find_descendant(move_paths, |mpi| state.contains(mpi)).is_some()
477495
}
478496

@@ -481,7 +499,8 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
481499
/// DROP of some local variable will have an effect -- note that
482500
/// drops, as they may unwind, are always terminators.
483501
fn initialized_at_terminator(&mut self, block: BasicBlock, mpi: MovePathIndex) -> bool {
484-
self.flow_inits.seek_before_primary_effect(self.body().terminator_loc(block));
502+
let terminator = self.body().terminator_loc(block);
503+
self.ensure().seek_before_primary_effect(terminator);
485504
self.initialized_at_curr_loc(mpi)
486505
}
487506

@@ -491,7 +510,8 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
491510
/// **Warning:** Does not account for the result of `Call`
492511
/// instructions.
493512
fn initialized_at_exit(&mut self, block: BasicBlock, mpi: MovePathIndex) -> bool {
494-
self.flow_inits.seek_after_primary_effect(self.body().terminator_loc(block));
513+
let terminator = self.body().terminator_loc(block);
514+
self.ensure().seek_after_primary_effect(terminator);
495515
self.initialized_at_curr_loc(mpi)
496516
}
497517

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)