]> git.lizzy.rs Git - rust.git/commitdiff
Convert regions to IndexVec
authorSantiago Pastorino <spastorino@gmail.com>
Wed, 27 Sep 2017 17:29:11 +0000 (14:29 -0300)
committerSantiago Pastorino <spastorino@gmail.com>
Thu, 5 Oct 2017 02:50:53 +0000 (23:50 -0300)
src/librustc_mir/transform/nll/mod.rs

index 0ed0321a948b63709d757c9d55c6e5e44a0ac830..f06441f77e2653c318c4ce45605aef7efbd314c7 100644 (file)
 use rustc::mir::transform::{MirPass, MirSource};
 use rustc::infer::{self, InferCtxt};
 use rustc::util::nodemap::FxHashSet;
+use rustc_data_structures::indexed_vec::{IndexVec, Idx};
 use syntax_pos::DUMMY_SP;
 use std::collections::HashMap;
 
 #[allow(dead_code)]
 struct NLLVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
     lookup_map: HashMap<RegionVid, Lookup>,
-    regions: Vec<Region>,
+    regions: IndexVec<RegionIndex, Region>,
     infcx: InferCtxt<'a, 'gcx, 'tcx>,
 }
 
@@ -31,7 +32,7 @@ pub fn new(infcx: InferCtxt<'a, 'gcx, 'tcx>) -> Self {
         NLLVisitor {
             infcx,
             lookup_map: HashMap::new(),
-            regions: vec![],
+            regions: IndexVec::new(),
         }
     }
 
@@ -153,3 +154,19 @@ fn run_pass<'a, 'tcx>(&self,
 struct Region {
     points: FxHashSet<Location>,
 }
+
+#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd, Debug)]
+pub struct RegionIndex(pub u32);
+
+impl Idx for RegionIndex {
+    #[inline]
+    fn new(idx: usize) -> Self {
+        assert!(idx <= ::std::u32::MAX as usize);
+        RegionIndex(idx as u32)
+    }
+
+    #[inline]
+    fn index(self) -> usize {
+        self.0 as usize
+    }
+}