Auto merge of #59612 - matthewjasper:dataflow-usual-newtype-index, r=estebank
Use normal newtype_index macro for MIR dataflows * Makes the definition of these structs contain `struct IndexName` * Avoids having an offset by removing high values, rather than 0 * Implements some traits for us.
This commit is contained in:
commit
e4c66afba5
8 changed files with 31 additions and 77 deletions
|
@ -26,8 +26,7 @@ use super::borrow_set::BorrowData;
|
|||
use super::{Context, MirBorrowckCtxt};
|
||||
use super::{InitializationRequiringAction, PrefixSet};
|
||||
use crate::dataflow::drop_flag_effects;
|
||||
use crate::dataflow::move_paths::indexes::MoveOutIndex;
|
||||
use crate::dataflow::move_paths::MovePathIndex;
|
||||
use crate::dataflow::indexes::{MovePathIndex, MoveOutIndex};
|
||||
use crate::util::borrowck_errors::{BorrowckErrors, Origin};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -11,7 +11,7 @@ use crate::borrow_check::location::LocationIndex;
|
|||
|
||||
use polonius_engine::Output;
|
||||
|
||||
use crate::dataflow::move_paths::indexes::BorrowIndex;
|
||||
use crate::dataflow::indexes::BorrowIndex;
|
||||
use crate::dataflow::move_paths::HasMoveData;
|
||||
use crate::dataflow::Borrows;
|
||||
use crate::dataflow::EverInitializedPlaces;
|
||||
|
|
|
@ -72,18 +72,6 @@ impl Atom for BorrowIndex {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<usize> for BorrowIndex {
|
||||
fn from(i: usize) -> BorrowIndex {
|
||||
BorrowIndex::new(i)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BorrowIndex> for usize {
|
||||
fn from(vid: BorrowIndex) -> usize {
|
||||
Idx::index(vid)
|
||||
}
|
||||
}
|
||||
|
||||
impl Atom for LocationIndex {
|
||||
fn index(self) -> usize {
|
||||
Idx::index(self)
|
||||
|
|
|
@ -9,7 +9,7 @@ use crate::borrow_check::ArtificialField;
|
|||
use crate::borrow_check::{ReadKind, WriteKind};
|
||||
use crate::borrow_check::nll::facts::AllFacts;
|
||||
use crate::borrow_check::path_utils::*;
|
||||
use crate::dataflow::move_paths::indexes::BorrowIndex;
|
||||
use crate::dataflow::indexes::BorrowIndex;
|
||||
use rustc::ty::TyCtxt;
|
||||
use rustc::mir::visit::Visitor;
|
||||
use rustc::mir::{BasicBlock, Location, Mir, Place, PlaceBase, Rvalue};
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::borrow_check::nll::region_infer::values::{self, PointIndex, RegionVal
|
|||
use crate::borrow_check::nll::type_check::liveness::local_use_map::LocalUseMap;
|
||||
use crate::borrow_check::nll::type_check::NormalizeLocation;
|
||||
use crate::borrow_check::nll::type_check::TypeChecker;
|
||||
use crate::dataflow::move_paths::indexes::MovePathIndex;
|
||||
use crate::dataflow::indexes::MovePathIndex;
|
||||
use crate::dataflow::move_paths::MoveData;
|
||||
use crate::dataflow::{FlowAtLocation, FlowsAtLocation, MaybeInitializedPlaces};
|
||||
use rustc::infer::canonical::QueryRegionConstraint;
|
||||
|
|
|
@ -10,13 +10,18 @@ use rustc_data_structures::fx::FxHashMap;
|
|||
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
|
||||
|
||||
use crate::dataflow::{BitDenotation, BlockSets, InitialFlow};
|
||||
pub use crate::dataflow::indexes::BorrowIndex;
|
||||
use crate::borrow_check::nll::region_infer::RegionInferenceContext;
|
||||
use crate::borrow_check::nll::ToRegionVid;
|
||||
use crate::borrow_check::places_conflict;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
newtype_index! {
|
||||
pub struct BorrowIndex {
|
||||
DEBUG_FORMAT = "bw{}"
|
||||
}
|
||||
}
|
||||
|
||||
/// `Borrows` stores the data used in the analyses that track the flow
|
||||
/// of borrows.
|
||||
///
|
||||
|
|
|
@ -33,7 +33,12 @@ mod graphviz;
|
|||
mod impls;
|
||||
pub mod move_paths;
|
||||
|
||||
pub(crate) use self::move_paths::indexes;
|
||||
pub(crate) mod indexes {
|
||||
pub(crate) use super::{
|
||||
move_paths::{MovePathIndex, MoveOutIndex, InitIndex},
|
||||
impls::borrows::BorrowIndex,
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) struct DataflowBuilder<'a, 'tcx: 'a, BD>
|
||||
where
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use rustc::ty::{self, TyCtxt};
|
||||
use rustc::mir::*;
|
||||
use rustc::util::nodemap::FxHashMap;
|
||||
use rustc_data_structures::indexed_vec::{IndexVec};
|
||||
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
|
||||
use smallvec::SmallVec;
|
||||
use syntax_pos::{Span};
|
||||
|
||||
|
@ -12,66 +12,23 @@ use self::abs_domain::{AbstractElem, Lift};
|
|||
|
||||
mod abs_domain;
|
||||
|
||||
// This submodule holds some newtype'd Index wrappers that are using
|
||||
// NonZero to ensure that Option<Index> occupies only a single word.
|
||||
// They are in a submodule to impose privacy restrictions; namely, to
|
||||
// ensure that other code does not accidentally access `index.0`
|
||||
// (which is likely to yield a subtle off-by-one error).
|
||||
pub(crate) mod indexes {
|
||||
use std::fmt;
|
||||
use std::num::NonZeroUsize;
|
||||
use rustc_data_structures::indexed_vec::Idx;
|
||||
|
||||
macro_rules! new_index {
|
||||
($(#[$attrs:meta])* $Index:ident, $debug_name:expr) => {
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct $Index(NonZeroUsize);
|
||||
|
||||
impl Idx for $Index {
|
||||
fn new(idx: usize) -> Self {
|
||||
$Index(NonZeroUsize::new(idx + 1).unwrap())
|
||||
newtype_index! {
|
||||
pub struct MovePathIndex {
|
||||
DEBUG_FORMAT = "mp{}"
|
||||
}
|
||||
fn index(self) -> usize {
|
||||
self.0.get() - 1
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for $Index {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(fmt, "{}{}", $debug_name, self.index())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new_index!(
|
||||
/// Index into MovePathData.move_paths
|
||||
MovePathIndex,
|
||||
"mp"
|
||||
);
|
||||
|
||||
new_index!(
|
||||
/// Index into MoveData.moves.
|
||||
MoveOutIndex,
|
||||
"mo"
|
||||
);
|
||||
|
||||
new_index!(
|
||||
/// Index into MoveData.inits.
|
||||
InitIndex,
|
||||
"in"
|
||||
);
|
||||
|
||||
new_index!(
|
||||
/// Index into Borrows.locations
|
||||
BorrowIndex,
|
||||
"bw"
|
||||
);
|
||||
}
|
||||
|
||||
pub use self::indexes::MovePathIndex;
|
||||
pub use self::indexes::MoveOutIndex;
|
||||
pub use self::indexes::InitIndex;
|
||||
newtype_index! {
|
||||
pub struct MoveOutIndex {
|
||||
DEBUG_FORMAT = "mo{}"
|
||||
}
|
||||
}
|
||||
|
||||
newtype_index! {
|
||||
pub struct InitIndex {
|
||||
DEBUG_FORMAT = "in{}"
|
||||
}
|
||||
}
|
||||
|
||||
impl MoveOutIndex {
|
||||
pub fn move_path_index(&self, move_data: &MoveData<'_>) -> MovePathIndex {
|
||||
|
|
Loading…
Reference in a new issue