]> git.lizzy.rs Git - rust.git/commitdiff
incr.comp.: Make MIR encoding fit for incr.comp. caching.
authorMichael Woerister <michaelwoerister@posteo>
Wed, 22 Nov 2017 12:47:50 +0000 (13:47 +0100)
committerMichael Woerister <michaelwoerister@posteo>
Tue, 28 Nov 2017 11:44:45 +0000 (12:44 +0100)
src/librustc/ich/impls_mir.rs
src/librustc/mir/mod.rs
src/librustc/ty/maps/on_disk_cache.rs
src/librustc_metadata/decoder.rs
src/librustc_metadata/encoder.rs
src/librustc_mir/build/mod.rs
src/librustc_mir/shim.rs
src/librustc_mir/transform/check_unsafety.rs

index e40d07d936bbcba40bd84b5a98b6e5927baae3c0..424259de4fd1dfa0be8dad6915fcd6a3fd9ca855 100644 (file)
@@ -98,7 +98,7 @@ fn hash_stable<W: StableHasherResult>(&self,
     }
 }
 
-impl<'gcx, T> HashStable<StableHashingContext<'gcx>> for mir::ClearOnDecode<T>
+impl<'gcx, T> HashStable<StableHashingContext<'gcx>> for mir::ClearCrossCrate<T>
     where T: HashStable<StableHashingContext<'gcx>>
 {
     #[inline]
@@ -107,8 +107,8 @@ fn hash_stable<W: StableHasherResult>(&self,
                                           hasher: &mut StableHasher<W>) {
         mem::discriminant(self).hash_stable(hcx, hasher);
         match *self {
-            mir::ClearOnDecode::Clear => {}
-            mir::ClearOnDecode::Set(ref value) => {
+            mir::ClearCrossCrate::Clear => {}
+            mir::ClearCrossCrate::Set(ref value) => {
                 value.hash_stable(hcx, hasher);
             }
         }
index d5df90a5ea02c5849c37ccaf098e679906b9092e..76dbe6e61b4f078553c7a9291f87ddc010b439e8 100644 (file)
@@ -75,7 +75,7 @@ pub struct Mir<'tcx> {
 
     /// Crate-local information for each visibility scope, that can't (and
     /// needn't) be tracked across crates.
-    pub visibility_scope_info: ClearOnDecode<IndexVec<VisibilityScope, VisibilityScopeInfo>>,
+    pub visibility_scope_info: ClearCrossCrate<IndexVec<VisibilityScope, VisibilityScopeInfo>>,
 
     /// Rvalues promoted from this function, such as borrows of constants.
     /// Each of them is the Mir of a constant with the fn's type parameters
@@ -129,8 +129,8 @@ pub struct Mir<'tcx> {
 impl<'tcx> Mir<'tcx> {
     pub fn new(basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
                visibility_scopes: IndexVec<VisibilityScope, VisibilityScopeData>,
-               visibility_scope_info: ClearOnDecode<IndexVec<VisibilityScope,
-                                                             VisibilityScopeInfo>>,
+               visibility_scope_info: ClearCrossCrate<IndexVec<VisibilityScope,
+                                                               VisibilityScopeInfo>>,
                promoted: IndexVec<Promoted, Mir<'tcx>>,
                yield_ty: Option<Ty<'tcx>>,
                local_decls: IndexVec<Local, LocalDecl<'tcx>>,
@@ -283,7 +283,7 @@ pub fn return_ty(&self) -> Ty<'tcx> {
     }
 }
 
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
 pub struct VisibilityScopeInfo {
     /// A NodeId with lint levels equivalent to this scope's lint levels.
     pub lint_root: ast::NodeId,
@@ -291,7 +291,7 @@ pub struct VisibilityScopeInfo {
     pub safety: Safety,
 }
 
-#[derive(Copy, Clone, Debug)]
+#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)]
 pub enum Safety {
     Safe,
     /// Unsafe because of a PushUnsafeBlock
@@ -335,22 +335,13 @@ fn index_mut(&mut self, index: BasicBlock) -> &mut BasicBlockData<'tcx> {
 }
 
 #[derive(Clone, Debug)]
-pub enum ClearOnDecode<T> {
+pub enum ClearCrossCrate<T> {
     Clear,
     Set(T)
 }
 
-impl<T> serialize::Encodable for ClearOnDecode<T> {
-    fn encode<S: serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
-        serialize::Encodable::encode(&(), s)
-    }
-}
-
-impl<T> serialize::Decodable for ClearOnDecode<T> {
-    fn decode<D: serialize::Decoder>(d: &mut D) -> Result<Self, D::Error> {
-        serialize::Decodable::decode(d).map(|()| ClearOnDecode::Clear)
-    }
-}
+impl<T: serialize::Encodable> serialize::UseSpecializedEncodable for ClearCrossCrate<T> {}
+impl<T: serialize::Decodable> serialize::UseSpecializedDecodable for ClearCrossCrate<T> {}
 
 /// Grouped information about the source code origin of a MIR entity.
 /// Intended to be inspected by diagnostics and debuginfo.
index 6f55df76df4a13227bcf6fc42cb252fe5c0b77b8..01f2374033da8927cd59daf24808c03b3ffb91d9 100644 (file)
@@ -15,6 +15,7 @@
                   RESERVED_FOR_INCR_COMP_CACHE, LOCAL_CRATE};
 use hir::map::definitions::DefPathHash;
 use middle::cstore::CrateStore;
+use mir;
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::indexed_vec::{IndexVec, Idx};
 use rustc_serialize::{Decodable, Decoder, Encodable, Encoder, opaque,
@@ -36,6 +37,9 @@
 const PREV_DIAGNOSTICS_TAG: u64 = 0x1234_5678_A1A1_A1A1;
 const QUERY_RESULT_INDEX_TAG: u64 = 0x1234_5678_C3C3_C3C3;
 
+const TAG_CLEAR_CROSS_CRATE_CLEAR: u8 = 0;
+const TAG_CLEAR_CROSS_CRATE_SET: u8 = 1;
+
 /// `OnDiskCache` provides an interface to incr. comp. data cached from the
 /// previous compilation session. This data will eventually include the results
 /// of a few selected queries (like `typeck_tables_of` and `mir_optimized`) and
@@ -518,12 +522,32 @@ fn specialized_decode(&mut self) -> Result<hir::HirId, Self::Error> {
 // NodeIds are not stable across compilation sessions, so we store them in their
 // HirId representation. This allows use to map them to the current NodeId.
 impl<'a, 'tcx, 'x> SpecializedDecoder<NodeId> for CacheDecoder<'a, 'tcx, 'x> {
+    #[inline]
     fn specialized_decode(&mut self) -> Result<NodeId, Self::Error> {
         let hir_id = hir::HirId::decode(self)?;
         Ok(self.tcx().hir.hir_to_node_id(hir_id))
     }
 }
 
+impl<'a, 'tcx, 'x, T: Decodable> SpecializedDecoder<mir::ClearCrossCrate<T>>
+for CacheDecoder<'a, 'tcx, 'x> {
+    #[inline]
+    fn specialized_decode(&mut self) -> Result<mir::ClearCrossCrate<T>, Self::Error> {
+        let discr = u8::decode(self)?;
+
+        match discr {
+            TAG_CLEAR_CROSS_CRATE_CLEAR => Ok(mir::ClearCrossCrate::Clear),
+            TAG_CLEAR_CROSS_CRATE_SET => {
+                let val = T::decode(self)?;
+                Ok(mir::ClearCrossCrate::Set(val))
+            }
+            _ => {
+                unreachable!()
+            }
+        }
+    }
+}
+
 //- ENCODING -------------------------------------------------------------------
 
 struct CacheEncoder<'enc, 'a, 'tcx, E>
@@ -658,6 +682,27 @@ fn specialized_encode(&mut self, node_id: &NodeId) -> Result<(), Self::Error> {
     }
 }
 
+impl<'enc, 'a, 'tcx, E, T> SpecializedEncoder<mir::ClearCrossCrate<T>>
+for CacheEncoder<'enc, 'a, 'tcx, E>
+    where E: 'enc + ty_codec::TyEncoder,
+          T: Encodable,
+{
+    #[inline]
+    fn specialized_encode(&mut self,
+                          val: &mir::ClearCrossCrate<T>)
+                          -> Result<(), Self::Error> {
+        match *val {
+            mir::ClearCrossCrate::Clear => {
+                TAG_CLEAR_CROSS_CRATE_CLEAR.encode(self)
+            }
+            mir::ClearCrossCrate::Set(ref val) => {
+                TAG_CLEAR_CROSS_CRATE_SET.encode(self)?;
+                val.encode(self)
+            }
+        }
+    }
+}
+
 macro_rules! encoder_methods {
     ($($name:ident($ty:ty);)*) => {
         $(fn $name(&mut self, value: $ty) -> Result<(), Self::Error> {
index 633806d5ef56800d5bde0178f5612457f7955c3c..eb2bcfc93c5fb15e9869e4fa8540f2d998d73fcd 100644 (file)
@@ -21,6 +21,7 @@
 use rustc::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
 use rustc::ich::Fingerprint;
 use rustc::middle::lang_items;
+use rustc::mir;
 use rustc::session::Session;
 use rustc::ty::{self, Ty, TyCtxt};
 use rustc::ty::codec::TyDecoder;
@@ -327,6 +328,14 @@ fn specialized_decode(&mut self) -> Result<Span, Self::Error> {
     }
 }
 
+impl<'a, 'tcx, T: Decodable> SpecializedDecoder<mir::ClearCrossCrate<T>>
+for DecodeContext<'a, 'tcx> {
+    #[inline]
+    fn specialized_decode(&mut self) -> Result<mir::ClearCrossCrate<T>, Self::Error> {
+        Ok(mir::ClearCrossCrate::Clear)
+    }
+}
+
 implement_ty_decoder!( DecodeContext<'a, 'tcx> );
 
 impl<'a, 'tcx> MetadataBlob {
index d82d50164cbb59c58e0d44cabea691ea583bc982..de6bb9ea738bed4ec92fa9092210b2931e187670 100644 (file)
@@ -157,6 +157,15 @@ fn specialized_encode(&mut self,
     }
 }
 
+impl<'a, 'tcx, T: Encodable> SpecializedEncoder<mir::ClearCrossCrate<T>>
+for EncodeContext<'a, 'tcx> {
+    fn specialized_encode(&mut self,
+                          _: &mir::ClearCrossCrate<T>)
+                          -> Result<(), Self::Error> {
+        Ok(())
+    }
+}
+
 impl<'a, 'tcx> TyEncoder for EncodeContext<'a, 'tcx> {
     fn position(&self) -> usize {
         self.opaque.position()
index 080cf4b47cf8701cf6fdfe98672b7b8fd0e757b2..2086e92a9846420507674d83c398526b61c0c317 100644 (file)
@@ -543,7 +543,7 @@ fn finish(self,
 
         Mir::new(self.cfg.basic_blocks,
                  self.visibility_scopes,
-                 ClearOnDecode::Set(self.visibility_scope_info),
+                 ClearCrossCrate::Set(self.visibility_scope_info),
                  IndexVec::new(),
                  yield_ty,
                  self.local_decls,
index 119cd35910fd590272c312a8d666b9c703b6e7e9..15b06bd38924ad478f734d810750df50ffa464f3 100644 (file)
@@ -198,7 +198,7 @@ fn build_drop_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
         IndexVec::from_elem_n(
             VisibilityScopeData { span: span, parent_scope: None }, 1
         ),
-        ClearOnDecode::Clear,
+        ClearCrossCrate::Clear,
         IndexVec::new(),
         None,
         local_decls_for_sig(&sig, span),
@@ -345,7 +345,7 @@ fn into_mir(self) -> Mir<'tcx> {
             IndexVec::from_elem_n(
                 VisibilityScopeData { span: self.span, parent_scope: None }, 1
             ),
-            ClearOnDecode::Clear,
+            ClearCrossCrate::Clear,
             IndexVec::new(),
             None,
             self.local_decls,
@@ -807,7 +807,7 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
         IndexVec::from_elem_n(
             VisibilityScopeData { span: span, parent_scope: None }, 1
         ),
-        ClearOnDecode::Clear,
+        ClearCrossCrate::Clear,
         IndexVec::new(),
         None,
         local_decls,
@@ -885,7 +885,7 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>,
         IndexVec::from_elem_n(
             VisibilityScopeData { span: span, parent_scope: None }, 1
         ),
-        ClearOnDecode::Clear,
+        ClearCrossCrate::Clear,
         IndexVec::new(),
         None,
         local_decls,
index c8a23280079c1c12ce654c690d52afcaed78caf9..720a3bf0bc0ed280f2530b715a2f82d8aebcbab1 100644 (file)
@@ -320,8 +320,8 @@ fn unsafety_check_result<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
     let mir = &tcx.mir_built(def_id).borrow();
 
     let visibility_scope_info = match mir.visibility_scope_info {
-        ClearOnDecode::Set(ref data) => data,
-        ClearOnDecode::Clear => {
+        ClearCrossCrate::Set(ref data) => data,
+        ClearCrossCrate::Clear => {
             debug!("unsafety_violations: {:?} - remote, skipping", def_id);
             return UnsafetyCheckResult {
                 violations: Rc::new([]),