Skip to content

Commit d490ea1

Browse files
committed
Remove lifetimes from BorrowckDomain.
They are only present because it's currently defined in terms of the domains of `Borrows` and `MaybeUninitializedPlaces` and `EverInitializedPlaces` via associated types. This commit introduces typedefs for those domains, avoiding the lifetimes.
1 parent 83f67c5 commit d490ea1

File tree

4 files changed

+42
-41
lines changed

4 files changed

+42
-41
lines changed

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ use rustc_middle::mir::{
88
};
99
use rustc_middle::ty::{RegionVid, TyCtxt};
1010
use rustc_mir_dataflow::fmt::DebugWithContext;
11-
use rustc_mir_dataflow::impls::{EverInitializedPlaces, MaybeUninitializedPlaces};
11+
use rustc_mir_dataflow::impls::{
12+
EverInitializedPlaces, EverInitializedPlacesDomain, MaybeUninitializedPlaces,
13+
MaybeUninitializedPlacesDomain,
14+
};
1215
use rustc_mir_dataflow::{Analysis, GenKill, JoinSemiLattice, SwitchIntEdgeEffects};
1316
use tracing::debug;
1417

@@ -24,7 +27,7 @@ pub(crate) struct Borrowck<'a, 'tcx> {
2427
}
2528

2629
impl<'a, 'tcx> Analysis<'tcx> for Borrowck<'a, 'tcx> {
27-
type Domain = BorrowckDomain<'a, 'tcx>;
30+
type Domain = BorrowckDomain;
2831

2932
const NAME: &'static str = "borrowck";
3033

@@ -110,14 +113,14 @@ impl<'a, 'tcx> Analysis<'tcx> for Borrowck<'a, 'tcx> {
110113
}
111114
}
112115

113-
impl JoinSemiLattice for BorrowckDomain<'_, '_> {
116+
impl JoinSemiLattice for BorrowckDomain {
114117
fn join(&mut self, _other: &Self) -> bool {
115118
// This is only reachable from `iterate_to_fixpoint`, which this analysis doesn't use.
116119
unreachable!();
117120
}
118121
}
119122

120-
impl<'tcx, C> DebugWithContext<C> for BorrowckDomain<'_, 'tcx>
123+
impl<'tcx, C> DebugWithContext<C> for BorrowckDomain
121124
where
122125
C: rustc_mir_dataflow::move_paths::HasMoveData<'tcx>,
123126
{
@@ -160,10 +163,10 @@ where
160163

161164
/// The transient state of the dataflow analyses used by the borrow checker.
162165
#[derive(Clone, Debug, PartialEq, Eq)]
163-
pub(crate) struct BorrowckDomain<'a, 'tcx> {
164-
pub(crate) borrows: <Borrows<'a, 'tcx> as Analysis<'tcx>>::Domain,
165-
pub(crate) uninits: <MaybeUninitializedPlaces<'a, 'tcx> as Analysis<'tcx>>::Domain,
166-
pub(crate) ever_inits: <EverInitializedPlaces<'a, 'tcx> as Analysis<'tcx>>::Domain,
166+
pub(crate) struct BorrowckDomain {
167+
pub(crate) borrows: BorrowsDomain,
168+
pub(crate) uninits: MaybeUninitializedPlacesDomain,
169+
pub(crate) ever_inits: EverInitializedPlacesDomain,
167170
}
168171

169172
rustc_index::newtype_index! {
@@ -566,6 +569,8 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
566569
}
567570
}
568571

572+
type BorrowsDomain = BitSet<BorrowIndex>;
573+
569574
/// Forward dataflow computation of the set of borrows that are in scope at a particular location.
570575
/// - we gen the introduced loans
571576
/// - we kill loans on locals going out of (regular) scope
@@ -574,7 +579,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
574579
/// - we also kill loans of conflicting places when overwriting a shared path: e.g. borrows of
575580
/// `a.b.c` when `a` is overwritten.
576581
impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
577-
type Domain = BitSet<BorrowIndex>;
582+
type Domain = BorrowsDomain;
578583

579584
const NAME: &'static str = "borrows";
580585

compiler/rustc_borrowck/src/lib.rs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<
603603
fn visit_statement_before_primary_effect(
604604
&mut self,
605605
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
606-
state: &BorrowckDomain<'a, 'tcx>,
606+
state: &BorrowckDomain,
607607
stmt: &'a Statement<'tcx>,
608608
location: Location,
609609
) {
@@ -677,7 +677,7 @@ impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<
677677
fn visit_terminator_before_primary_effect(
678678
&mut self,
679679
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
680-
state: &BorrowckDomain<'a, 'tcx>,
680+
state: &BorrowckDomain,
681681
term: &'a Terminator<'tcx>,
682682
loc: Location,
683683
) {
@@ -790,7 +790,7 @@ impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<
790790
fn visit_terminator_after_primary_effect(
791791
&mut self,
792792
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
793-
state: &BorrowckDomain<'a, 'tcx>,
793+
state: &BorrowckDomain,
794794
term: &'a Terminator<'tcx>,
795795
loc: Location,
796796
) {
@@ -983,7 +983,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
983983
place_span: (Place<'tcx>, Span),
984984
kind: (AccessDepth, ReadOrWrite),
985985
is_local_mutation_allowed: LocalMutationIsAllowed,
986-
state: &BorrowckDomain<'a, 'tcx>,
986+
state: &BorrowckDomain,
987987
) {
988988
let (sd, rw) = kind;
989989

@@ -1032,7 +1032,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
10321032
place_span: (Place<'tcx>, Span),
10331033
sd: AccessDepth,
10341034
rw: ReadOrWrite,
1035-
state: &BorrowckDomain<'a, 'tcx>,
1035+
state: &BorrowckDomain,
10361036
) -> bool {
10371037
let mut error_reported = false;
10381038

@@ -1172,7 +1172,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
11721172
location: Location,
11731173
place_span: (Place<'tcx>, Span),
11741174
kind: AccessDepth,
1175-
state: &BorrowckDomain<'a, 'tcx>,
1175+
state: &BorrowckDomain,
11761176
) {
11771177
// Write of P[i] or *P requires P init'd.
11781178
self.check_if_assigned_path_is_moved(location, place_span, state);
@@ -1190,7 +1190,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
11901190
&mut self,
11911191
location: Location,
11921192
(rvalue, span): (&'a Rvalue<'tcx>, Span),
1193-
state: &BorrowckDomain<'a, 'tcx>,
1193+
state: &BorrowckDomain,
11941194
) {
11951195
match rvalue {
11961196
&Rvalue::Ref(_ /*rgn*/, bk, place) => {
@@ -1448,7 +1448,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
14481448
&mut self,
14491449
location: Location,
14501450
(operand, span): (&'a Operand<'tcx>, Span),
1451-
state: &BorrowckDomain<'a, 'tcx>,
1451+
state: &BorrowckDomain,
14521452
) {
14531453
match *operand {
14541454
Operand::Copy(place) => {
@@ -1568,12 +1568,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
15681568
}
15691569
}
15701570

1571-
fn check_activations(
1572-
&mut self,
1573-
location: Location,
1574-
span: Span,
1575-
state: &BorrowckDomain<'a, 'tcx>,
1576-
) {
1571+
fn check_activations(&mut self, location: Location, span: Span, state: &BorrowckDomain) {
15771572
// Two-phase borrow support: For each activation that is newly
15781573
// generated at this statement, check if it interferes with
15791574
// another borrow.
@@ -1731,7 +1726,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
17311726
location: Location,
17321727
desired_action: InitializationRequiringAction,
17331728
place_span: (PlaceRef<'tcx>, Span),
1734-
state: &BorrowckDomain<'a, 'tcx>,
1729+
state: &BorrowckDomain,
17351730
) {
17361731
let maybe_uninits = &state.uninits;
17371732

@@ -1836,7 +1831,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
18361831
location: Location,
18371832
desired_action: InitializationRequiringAction,
18381833
place_span: (PlaceRef<'tcx>, Span),
1839-
state: &BorrowckDomain<'a, 'tcx>,
1834+
state: &BorrowckDomain,
18401835
) {
18411836
let maybe_uninits = &state.uninits;
18421837

@@ -1935,7 +1930,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
19351930
&mut self,
19361931
location: Location,
19371932
(place, span): (Place<'tcx>, Span),
1938-
state: &BorrowckDomain<'a, 'tcx>,
1933+
state: &BorrowckDomain,
19391934
) {
19401935
debug!("check_if_assigned_path_is_moved place: {:?}", place);
19411936

@@ -2001,7 +1996,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
20011996
location: Location,
20021997
base: PlaceRef<'tcx>,
20031998
span: Span,
2004-
state: &BorrowckDomain<'a, 'tcx>,
1999+
state: &BorrowckDomain,
20052000
) {
20062001
// rust-lang/rust#21232: Until Rust allows reads from the
20072002
// initialized parts of partially initialized structs, we
@@ -2092,7 +2087,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
20922087
(place, span): (Place<'tcx>, Span),
20932088
kind: ReadOrWrite,
20942089
is_local_mutation_allowed: LocalMutationIsAllowed,
2095-
state: &BorrowckDomain<'a, 'tcx>,
2090+
state: &BorrowckDomain,
20962091
location: Location,
20972092
) -> bool {
20982093
debug!(
@@ -2206,18 +2201,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
22062201
}
22072202
}
22082203

2209-
fn is_local_ever_initialized(
2210-
&self,
2211-
local: Local,
2212-
state: &BorrowckDomain<'a, 'tcx>,
2213-
) -> Option<InitIndex> {
2204+
fn is_local_ever_initialized(&self, local: Local, state: &BorrowckDomain) -> Option<InitIndex> {
22142205
let mpi = self.move_data.rev_lookup.find_local(local)?;
22152206
let ii = &self.move_data.init_path_map[mpi];
22162207
ii.into_iter().find(|&&index| state.ever_inits.contains(index)).copied()
22172208
}
22182209

22192210
/// Adds the place into the used mutable variables set
2220-
fn add_used_mut(&mut self, root_place: RootPlace<'tcx>, state: &BorrowckDomain<'a, 'tcx>) {
2211+
fn add_used_mut(&mut self, root_place: RootPlace<'tcx>, state: &BorrowckDomain) {
22212212
match root_place {
22222213
RootPlace { place_local: local, place_projection: [], is_local_mutation_allowed } => {
22232214
// If the local may have been initialized, and it is now currently being

compiler/rustc_mir_dataflow/src/impls/initialized.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,12 @@ impl<'tcx> Analysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
369369
}
370370
}
371371

372+
/// There can be many more `MovePathIndex` than there are locals in a MIR body.
373+
/// We use a mixed bitset to avoid paying too high a memory footprint.
374+
pub type MaybeUninitializedPlacesDomain = MixedBitSet<MovePathIndex>;
375+
372376
impl<'tcx> Analysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
373-
/// There can be many more `MovePathIndex` than there are locals in a MIR body.
374-
/// We use a mixed bitset to avoid paying too high a memory footprint.
375-
type Domain = MixedBitSet<MovePathIndex>;
377+
type Domain = MaybeUninitializedPlacesDomain;
376378

377379
const NAME: &'static str = "maybe_uninit";
378380

@@ -490,10 +492,12 @@ impl<'tcx> Analysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
490492
}
491493
}
492494

495+
/// There can be many more `InitIndex` than there are locals in a MIR body.
496+
/// We use a mixed bitset to avoid paying too high a memory footprint.
497+
pub type EverInitializedPlacesDomain = MixedBitSet<InitIndex>;
498+
493499
impl<'tcx> Analysis<'tcx> for EverInitializedPlaces<'_, 'tcx> {
494-
/// There can be many more `InitIndex` than there are locals in a MIR body.
495-
/// We use a mixed bitset to avoid paying too high a memory footprint.
496-
type Domain = MixedBitSet<InitIndex>;
500+
type Domain = EverInitializedPlacesDomain;
497501

498502
const NAME: &'static str = "ever_init";
499503

compiler/rustc_mir_dataflow/src/impls/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ mod storage_liveness;
99

1010
pub use self::borrowed_locals::{MaybeBorrowedLocals, borrowed_locals};
1111
pub use self::initialized::{
12-
EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces,
12+
EverInitializedPlaces, EverInitializedPlacesDomain, MaybeInitializedPlaces,
13+
MaybeUninitializedPlaces, MaybeUninitializedPlacesDomain,
1314
};
1415
pub use self::liveness::{
1516
MaybeLiveLocals, MaybeTransitiveLiveLocals, TransferFunction as LivenessTransferFunction,

0 commit comments

Comments
 (0)