diff --git a/src/librustc_mir/borrow_check/flows.rs b/src/librustc_mir/borrow_check/flows.rs index ceff380c594e..b5cfdee6a454 100644 --- a/src/librustc_mir/borrow_check/flows.rs +++ b/src/librustc_mir/borrow_check/flows.rs @@ -88,9 +88,8 @@ impl<'b, 'gcx, 'tcx> fmt::Display for Flows<'b, 'gcx, 'tcx> { s.push_str(", "); }; saw_one = true; - let borrow_data = &self.borrows.operator().borrows()[borrow.borrow_index()]; - s.push_str(&format!("{}{}", borrow_data, - if borrow.is_activation() { "@active" } else { "" })); + let borrow_data = &self.borrows.operator().borrows()[borrow]; + s.push_str(&format!("{}", borrow_data)); }); s.push_str("] "); @@ -101,7 +100,7 @@ impl<'b, 'gcx, 'tcx> fmt::Display for Flows<'b, 'gcx, 'tcx> { s.push_str(", "); }; saw_one = true; - let borrow_data = &self.borrows.operator().borrows()[borrow.borrow_index()]; + let borrow_data = &self.borrows.operator().borrows()[borrow]; s.push_str(&format!("{}", borrow_data)); }); s.push_str("] "); diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index dd76b883d63d..962356c64010 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -220,9 +220,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( &attributes, &dead_unwinds, Borrows::new(tcx, mir, opt_regioncx.clone(), def_id, body_id, borrow_set), - |rs, i| { - DebugFormatted::new(&(i.kind(), rs.location(i.borrow_index()))) - } + |rs, i| DebugFormatted::new(&rs.location(i)), )); let movable_generator = !match tcx.hir.get(id) { @@ -549,7 +547,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx let data = domain.borrows(); flow_state.borrows.with_iter_outgoing(|borrows| { for i in borrows { - let borrow = &data[i.borrow_index()]; + let borrow = &data[i]; self.check_for_local_borrow(borrow, span); } }); @@ -565,7 +563,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx let data = domain.borrows(); flow_state.borrows.with_iter_outgoing(|borrows| { for i in borrows { - let borrow = &data[i.borrow_index()]; + let borrow = &data[i]; let context = ContextKind::StorageDead.new(loc); self.check_for_invalidation_at_exit(context, borrow, span, flow_state); } @@ -2245,21 +2243,14 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { // borrows of P, P.a.b, etc. let mut iter_incoming = flow_state.borrows.iter_incoming(); while let Some(i) = iter_incoming.next() { - // TODO -- for now, just skip activations, since - // everywhere that activation is set, reservation should - // be set - if i.is_activation() { - continue; - } - - let borrowed = &data[i.borrow_index()]; + let borrowed = &data[i]; if self.places_conflict(&borrowed.borrowed_place, place, access) { debug!( "each_borrow_involving_path: {:?} @ {:?} vs. {:?}/{:?}", i, borrowed, place, access ); - let ctrl = op(self, i.borrow_index(), borrowed); + let ctrl = op(self, i, borrowed); if ctrl == Control::Break { return; } diff --git a/src/librustc_mir/dataflow/impls/borrows.rs b/src/librustc_mir/dataflow/impls/borrows.rs index 190d08e83de4..19f5ad5589e8 100644 --- a/src/librustc_mir/dataflow/impls/borrows.rs +++ b/src/librustc_mir/dataflow/impls/borrows.rs @@ -20,13 +20,13 @@ use rustc::ty::{Region, TyCtxt}; use rustc::ty::RegionKind; use rustc::ty::RegionKind::ReScope; -use rustc_data_structures::bitslice::{BitwiseOperator}; -use rustc_data_structures::indexed_set::{IdxSet}; -use rustc_data_structures::indexed_vec::{Idx, IndexVec}; +use rustc_data_structures::bitslice::BitwiseOperator; +use rustc_data_structures::indexed_set::IdxSet; +use rustc_data_structures::indexed_vec::IndexVec; use rustc_data_structures::sync::Lrc; use dataflow::{BitDenotation, BlockSets, InitialFlow}; -pub use dataflow::indexes::{BorrowIndex, ReserveOrActivateIndex}; +pub use dataflow::indexes::BorrowIndex; use borrow_check::nll::region_infer::RegionInferenceContext; use borrow_check::nll::ToRegionVid; @@ -53,21 +53,6 @@ pub struct Borrows<'a, 'gcx: 'tcx, 'tcx: 'a> { nonlexical_regioncx: Option>>, } -impl ReserveOrActivateIndex { - fn reserved(i: BorrowIndex) -> Self { ReserveOrActivateIndex::new(i.index() * 2) } - fn active(i: BorrowIndex) -> Self { ReserveOrActivateIndex::new((i.index() * 2) + 1) } - - pub(crate) fn is_reservation(self) -> bool { self.index() % 2 == 0 } - pub(crate) fn is_activation(self) -> bool { self.index() % 2 == 1} - - pub(crate) fn kind(self) -> &'static str { - if self.is_reservation() { "reserved" } else { "active" } - } - pub(crate) fn borrow_index(self) -> BorrowIndex { - BorrowIndex::new(self.index() / 2) - } -} - impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> { crate fn new( tcx: TyCtxt<'a, 'gcx, 'tcx>, @@ -120,7 +105,7 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> { /// That means either they went out of either a nonlexical scope, if we care about those /// at the moment, or the location represents a lexical EndRegion fn kill_loans_out_of_scope_at_location(&self, - sets: &mut BlockSets, + sets: &mut BlockSets, location: Location) { if let Some(ref regioncx) = self.nonlexical_regioncx { // NOTE: The state associated with a given `location` @@ -137,22 +122,18 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> { for (borrow_index, borrow_data) in self.borrow_set.borrows.iter_enumerated() { let borrow_region = borrow_data.region.to_region_vid(); if !regioncx.region_contains_point(borrow_region, location) { - sets.kill(&ReserveOrActivateIndex::reserved(borrow_index)); - sets.kill(&ReserveOrActivateIndex::active(borrow_index)); + sets.kill(&borrow_index); } } } } fn kill_borrows_on_local(&self, - sets: &mut BlockSets, + sets: &mut BlockSets, local: &rustc::mir::Local) { if let Some(borrow_indexes) = self.borrow_set.local_map.get(local) { - sets.kill_all(borrow_indexes.iter() - .map(|b| ReserveOrActivateIndex::reserved(*b))); - sets.kill_all(borrow_indexes.iter() - .map(|b| ReserveOrActivateIndex::active(*b))); + sets.kill_all(borrow_indexes); } } @@ -162,45 +143,29 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> { .map(|activations| &activations[..]) .unwrap_or(&[]) } - - /// Performs the activations for a given location - fn perform_activations_at_location(&self, - sets: &mut BlockSets, - location: Location) { - // Handle activations - match self.borrow_set.activation_map.get(&location) { - Some(activations) => { - for activated in activations { - debug!("activating borrow {:?}", activated); - sets.gen(&ReserveOrActivateIndex::active(*activated)) - } - } - None => {} - } - } } impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> { - type Idx = ReserveOrActivateIndex; + type Idx = BorrowIndex; fn name() -> &'static str { "borrows" } fn bits_per_block(&self) -> usize { self.borrow_set.borrows.len() * 2 } - fn start_block_effect(&self, _entry_set: &mut IdxSet) { + fn start_block_effect(&self, _entry_set: &mut IdxSet) { // no borrows of code region_scopes have been taken prior to // function execution, so this method has no effect on // `_sets`. } fn before_statement_effect(&self, - sets: &mut BlockSets, + sets: &mut BlockSets, location: Location) { debug!("Borrows::before_statement_effect sets: {:?} location: {:?}", sets, location); self.kill_loans_out_of_scope_at_location(sets, location); } - fn statement_effect(&self, sets: &mut BlockSets, location: Location) { + fn statement_effect(&self, sets: &mut BlockSets, location: Location) { debug!("Borrows::statement_effect sets: {:?} location: {:?}", sets, location); let block = &self.mir.basic_blocks().get(location.block).unwrap_or_else(|| { @@ -210,7 +175,6 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> { panic!("could not find statement at location {:?}"); }); - self.perform_activations_at_location(sets, location); self.kill_loans_out_of_scope_at_location(sets, location); match stmt.kind { @@ -221,8 +185,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> { { assert!(self.nonlexical_regioncx.is_none()); for idx in borrow_indexes { - sets.kill(&ReserveOrActivateIndex::reserved(*idx)); - sets.kill(&ReserveOrActivateIndex::active(*idx)); + sets.kill(idx); } } else { // (if there is no entry, then there are no borrows to be tracked) @@ -252,14 +215,14 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> { if let RegionKind::ReEmpty = region { // If the borrowed value dies before the borrow is used, the region for // the borrow can be empty. Don't track the borrow in that case. - sets.kill(&ReserveOrActivateIndex::active(*index)); + sets.kill(&index); return } assert!(self.borrow_set.region_map.get(region).unwrap_or_else(|| { panic!("could not find BorrowIndexs for region {:?}", region); }).contains(&index)); - sets.gen(&ReserveOrActivateIndex::reserved(*index)); + sets.gen(&index); // Issue #46746: Two-phase borrows handles // stmts of form `Tmp = &mut Borrow` ... @@ -270,7 +233,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> { // e.g. `box (&mut _)`. Current // conservative solution: force // immediate activation here. - sets.gen(&ReserveOrActivateIndex::active(*index)); + sets.gen(&index); } } } @@ -306,13 +269,13 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> { } fn before_terminator_effect(&self, - sets: &mut BlockSets, + sets: &mut BlockSets, location: Location) { debug!("Borrows::before_terminator_effect sets: {:?} location: {:?}", sets, location); self.kill_loans_out_of_scope_at_location(sets, location); } - fn terminator_effect(&self, sets: &mut BlockSets, location: Location) { + fn terminator_effect(&self, sets: &mut BlockSets, location: Location) { debug!("Borrows::terminator_effect sets: {:?} location: {:?}", sets, location); let block = &self.mir.basic_blocks().get(location.block).unwrap_or_else(|| { @@ -320,7 +283,6 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> { }); let term = block.terminator(); - self.perform_activations_at_location(sets, location); self.kill_loans_out_of_scope_at_location(sets, location); @@ -343,8 +305,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> { if *scope != root_scope && self.scope_tree.is_subscope_of(*scope, root_scope) { - sets.kill(&ReserveOrActivateIndex::reserved(borrow_index)); - sets.kill(&ReserveOrActivateIndex::active(borrow_index)); + sets.kill(&borrow_index); } } } @@ -365,7 +326,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> { } fn propagate_call_return(&self, - _in_out: &mut IdxSet, + _in_out: &mut IdxSet, _call_bb: mir::BasicBlock, _dest_bb: mir::BasicBlock, _dest_place: &mir::Place) { diff --git a/src/librustc_mir/dataflow/move_paths/mod.rs b/src/librustc_mir/dataflow/move_paths/mod.rs index 9f6cf8c036e1..3a49e28f0418 100644 --- a/src/librustc_mir/dataflow/move_paths/mod.rs +++ b/src/librustc_mir/dataflow/move_paths/mod.rs @@ -65,9 +65,6 @@ pub(crate) mod indexes { /// Index into Borrows.locations new_index!(BorrowIndex, "bw"); - - /// Index into Reservations/Activations bitvector - new_index!(ReserveOrActivateIndex, "ra"); } pub use self::indexes::MovePathIndex;