Skip to content

Commit 8e783da

Browse files
committed
encapsulate ReserveOrActivateIndex into the borrows dataflow
1 parent 5f7b74f commit 8e783da

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/librustc_mir/borrow_check/mod.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use dataflow::MoveDataParamEnv;
3737
use dataflow::{DataflowResultsConsumer};
3838
use dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces};
3939
use dataflow::{EverInitializedPlaces, MovingOutStatements};
40-
use dataflow::{Borrows, ReserveOrActivateIndex};
40+
use dataflow::Borrows;
4141
use dataflow::indexes::BorrowIndex;
4242
use dataflow::move_paths::{IllegalMoveOriginKind, MoveError};
4343
use dataflow::move_paths::{HasMoveData, LookupResult, MoveData, MovePathIndex};
@@ -66,6 +66,8 @@ pub fn provide(providers: &mut Providers) {
6666
};
6767
}
6868

69+
struct IsActive(bool);
70+
6971
fn mir_borrowck<'a, 'tcx>(
7072
tcx: TyCtxt<'a, 'tcx, 'tcx>,
7173
def_id: DefId,
@@ -846,22 +848,21 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
846848
context,
847849
(sd, place_span.0),
848850
flow_state,
849-
|this, index, borrow| match (rw, borrow.kind) {
851+
|this, borrow_index, is_active, borrow| match (rw, borrow.kind) {
850852
// Obviously an activation is compatible with its own
851853
// reservation (or even prior activating uses of same
852854
// borrow); so don't check if they interfere.
853855
//
854856
// NOTE: *reservations* do conflict with themselves;
855857
// thus aren't injecting unsoundenss w/ this check.)
856-
(Activation(_, activating), _) if activating == index.borrow_index() => {
858+
(Activation(_, activating), _) if activating == borrow_index => {
857859
debug!(
858860
"check_access_for_conflict place_span: {:?} sd: {:?} rw: {:?} \
859-
skipping {:?} b/c activation of same borrow_index: {:?}",
861+
skipping {:?} b/c activation of same borrow_index",
860862
place_span,
861863
sd,
862864
rw,
863-
(index, borrow),
864-
index.borrow_index()
865+
(borrow_index, borrow),
865866
);
866867
Control::Continue
867868
}
@@ -872,7 +873,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
872873

873874
(Read(kind), BorrowKind::Unique) | (Read(kind), BorrowKind::Mut { .. }) => {
874875
// Reading from mere reservations of mutable-borrows is OK.
875-
if this.allow_two_phase_borrow(borrow.kind) && index.is_reservation() {
876+
if this.allow_two_phase_borrow(borrow.kind) && !is_active.0 {
876877
return Control::Continue;
877878
}
878879

@@ -2216,18 +2217,16 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
22162217
/// "Current borrow" here means a borrow that reaches the point in
22172218
/// the control-flow where the access occurs.
22182219
///
2219-
/// The borrow's phase is represented by the ReserveOrActivateIndex
2220-
/// passed to the callback: one can call `is_reservation()` and
2221-
/// `is_activation()` to determine what phase the borrow is
2222-
/// currently in, when such distinction matters.
2220+
/// The borrow's phase is represented by the IsActive parameter
2221+
/// passed to the callback.
22232222
fn each_borrow_involving_path<F>(
22242223
&mut self,
22252224
_context: Context,
22262225
access_place: (ShallowOrDeep, &Place<'tcx>),
22272226
flow_state: &Flows<'cx, 'gcx, 'tcx>,
22282227
mut op: F,
22292228
) where
2230-
F: FnMut(&mut Self, ReserveOrActivateIndex, &BorrowData<'tcx>) -> Control,
2229+
F: FnMut(&mut Self, BorrowIndex, IsActive, &BorrowData<'tcx>) -> Control,
22312230
{
22322231
let (access, place) = access_place;
22332232

@@ -2247,7 +2246,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
22472246
"each_borrow_involving_path: {:?} @ {:?} vs. {:?}/{:?}",
22482247
i, borrowed, place, access
22492248
);
2250-
let ctrl = op(self, i, borrowed);
2249+
let is_active = IsActive(i.is_activation());
2250+
let ctrl = op(self, i.borrow_index(), is_active, borrowed);
22512251
if ctrl == Control::Break {
22522252
return;
22532253
}

src/librustc_mir/dataflow/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ pub use self::impls::{DefinitelyInitializedPlaces, MovingOutStatements};
3131
pub use self::impls::EverInitializedPlaces;
3232
pub use self::impls::borrows::Borrows;
3333
pub use self::impls::HaveBeenBorrowedLocals;
34-
pub(crate) use self::impls::borrows::{ReserveOrActivateIndex};
3534
pub use self::at_location::{FlowAtLocation, FlowsAtLocation};
3635
pub(crate) use self::drop_flag_effects::*;
3736

0 commit comments

Comments
 (0)