]> git.lizzy.rs Git - rust.git/commitdiff
Use normal newtype_index macro for MIR dataflow
authorMatthew Jasper <mjjasper1@gmail.com>
Mon, 1 Apr 2019 18:38:00 +0000 (19:38 +0100)
committerMatthew Jasper <mjjasper1@gmail.com>
Mon, 1 Apr 2019 18:38:00 +0000 (19:38 +0100)
src/librustc_mir/borrow_check/error_reporting.rs
src/librustc_mir/borrow_check/flows.rs
src/librustc_mir/borrow_check/nll/facts.rs
src/librustc_mir/borrow_check/nll/invalidation.rs
src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs
src/librustc_mir/dataflow/impls/borrows.rs
src/librustc_mir/dataflow/mod.rs
src/librustc_mir/dataflow/move_paths/mod.rs

index 95701204cab6d6205020b73ca66acced86dbf4c9..d7ad2dbfeaf9e4d4253e32a59aa4df4070f47e24 100644 (file)
@@ -25,8 +25,7 @@
 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)]
index 8de39f0efc1a5309a39eca22b3242f239c58d341..c0b199f1798d48bd01a4e29e27e929e4f60f89a6 100644 (file)
@@ -11,7 +11,7 @@
 
 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;
index 9714398d9d63a374524ce7d538588b84b75ac3b7..926f52b7cfce8bfdb6866f4b923bac7da13e0717 100644 (file)
@@ -72,18 +72,6 @@ fn index(self) -> usize {
     }
 }
 
-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)
index aafbff35776475a91d47624ba015b9b078e59906..7896feefd9aea4dba1e7f546f6ece813f44676cd 100644 (file)
@@ -9,7 +9,7 @@
 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};
index f0df7070e6b5ab41799f5d965dd014ab0849b719..4c4b4c0431927a477ceb1c1f92ef19bff6e3798c 100644 (file)
@@ -3,7 +3,7 @@
 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;
index b47aff3a4f8557ea19bd6174bcf53ff83193fcf0..0e51a519da300c65e47d7b568ac29718f953338c 100644 (file)
 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.
 ///
index af0e3f5a2709130764cb7e211568a8f7f1bca623..83221aca6c5b389d1be75b8d04974be5ad941ad6 100644 (file)
 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
index 7eef68e5f807350dcd59491eaf314a03e7a822be..6b01ab2c4ffda0b9d8f4f68fa8d179630a11ce45 100644 (file)
@@ -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};
 
 
 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())
-                }
-                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())
-                }
-            }
-        }
+newtype_index! {
+    pub struct MovePathIndex {
+        DEBUG_FORMAT = "mp{}"
     }
+}
 
-    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"
-    );
+newtype_index! {
+    pub struct MoveOutIndex {
+        DEBUG_FORMAT = "mo{}"
+    }
 }
 
-pub use self::indexes::MovePathIndex;
-pub use self::indexes::MoveOutIndex;
-pub use self::indexes::InitIndex;
+newtype_index! {
+    pub struct InitIndex {
+        DEBUG_FORMAT = "in{}"
+    }
+}
 
 impl MoveOutIndex {
     pub fn move_path_index(&self, move_data: &MoveData<'_>) -> MovePathIndex {