]> git.lizzy.rs Git - rust.git/commitdiff
Move Fingerprint to data structures
authorMark Rousskov <mark.simulacrum@gmail.com>
Sat, 4 Aug 2018 00:34:23 +0000 (18:34 -0600)
committerMark Rousskov <mark.simulacrum@gmail.com>
Thu, 9 Aug 2018 16:00:25 +0000 (10:00 -0600)
src/librustc/ich/fingerprint.rs [deleted file]
src/librustc/ich/mod.rs
src/librustc/lib.rs
src/librustc/session/mod.rs
src/librustc_codegen_llvm/back/symbol_export.rs
src/librustc_codegen_llvm/debuginfo/metadata.rs
src/librustc_data_structures/fingerprint.rs [new file with mode: 0644]
src/librustc_data_structures/lib.rs
src/librustc_driver/driver.rs
src/librustc_metadata/decoder.rs
src/librustc_metadata/encoder.rs

diff --git a/src/librustc/ich/fingerprint.rs b/src/librustc/ich/fingerprint.rs
deleted file mode 100644 (file)
index f00c5a6..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use std::mem;
-use rustc_data_structures::stable_hasher;
-use serialize;
-use serialize::opaque::{EncodeResult, Encoder, Decoder};
-
-#[derive(Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Clone, Copy)]
-pub struct Fingerprint(u64, u64);
-
-impl Fingerprint {
-
-    pub const ZERO: Fingerprint = Fingerprint(0, 0);
-
-    #[inline]
-    pub fn from_smaller_hash(hash: u64) -> Fingerprint {
-        Fingerprint(hash, hash)
-    }
-
-    #[inline]
-    pub fn to_smaller_hash(&self) -> u64 {
-        self.0
-    }
-
-    #[inline]
-    pub fn as_value(&self) -> (u64, u64) {
-        (self.0, self.1)
-    }
-
-    #[inline]
-    pub fn combine(self, other: Fingerprint) -> Fingerprint {
-        // See https://stackoverflow.com/a/27952689 on why this function is
-        // implemented this way.
-        Fingerprint(
-            self.0.wrapping_mul(3).wrapping_add(other.0),
-            self.1.wrapping_mul(3).wrapping_add(other.1)
-        )
-    }
-
-    // Combines two hashes in an order independent way. Make sure this is what
-    // you want.
-    #[inline]
-    pub fn combine_commutative(self, other: Fingerprint) -> Fingerprint {
-        let a = (self.1 as u128) << 64 | self.0 as u128;
-        let b = (other.1 as u128) << 64 | other.0 as u128;
-
-        let c = a.wrapping_add(b);
-
-        Fingerprint((c >> 64) as u64, c as u64)
-    }
-
-    pub fn to_hex(&self) -> String {
-        format!("{:x}{:x}", self.0, self.1)
-    }
-
-    pub fn encode_opaque(&self, encoder: &mut Encoder) -> EncodeResult {
-        let bytes: [u8; 16] = unsafe { mem::transmute([self.0.to_le(), self.1.to_le()]) };
-
-        encoder.emit_raw_bytes(&bytes);
-        Ok(())
-    }
-
-    pub fn decode_opaque<'a>(decoder: &mut Decoder<'a>) -> Result<Fingerprint, String> {
-        let mut bytes = [0; 16];
-
-        decoder.read_raw_bytes(&mut bytes)?;
-
-        let [l, r]: [u64; 2] = unsafe { mem::transmute(bytes) };
-
-        Ok(Fingerprint(u64::from_le(l), u64::from_le(r)))
-    }
-}
-
-impl ::std::fmt::Display for Fingerprint {
-    fn fmt(&self, formatter: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
-        write!(formatter, "{:x}-{:x}", self.0, self.1)
-    }
-}
-
-impl stable_hasher::StableHasherResult for Fingerprint {
-    fn finish(hasher: stable_hasher::StableHasher<Self>) -> Self {
-        let (_0, _1) = hasher.finalize();
-        Fingerprint(_0, _1)
-    }
-}
-
-impl_stable_hash_via_hash!(Fingerprint);
-
-impl serialize::UseSpecializedEncodable for Fingerprint { }
-
-impl serialize::UseSpecializedDecodable for Fingerprint { }
-
-impl serialize::SpecializedEncoder<Fingerprint> for serialize::opaque::Encoder {
-    fn specialized_encode(&mut self, f: &Fingerprint) -> Result<(), Self::Error> {
-        f.encode_opaque(self)
-    }
-}
-
-impl<'a> serialize::SpecializedDecoder<Fingerprint> for serialize::opaque::Decoder<'a> {
-    fn specialized_decode(&mut self) -> Result<Fingerprint, Self::Error> {
-        Fingerprint::decode_opaque(self)
-    }
-}
index d58eb64c366e7aa056faab5958017ddb7b5be838..dbb9ecaddfd337960a21008cea7ee6ba3b55efe7 100644 (file)
 
 //! ICH - Incremental Compilation Hash
 
-pub use self::fingerprint::Fingerprint;
+crate use rustc_data_structures::fingerprint::Fingerprint;
 pub use self::caching_codemap_view::CachingCodemapView;
 pub use self::hcx::{StableHashingContextProvider, StableHashingContext, NodeIdHashingMode,
                     hash_stable_trait_impls, compute_ignored_attr_names};
-mod fingerprint;
 mod caching_codemap_view;
 mod hcx;
 
index 62f244acc9a944c4a21d365f458f9c1809845b2e..6b00a10eaa33393a9c906c725c27c5464041ffcd 100644 (file)
@@ -72,6 +72,7 @@
 #![feature(in_band_lifetimes)]
 #![feature(macro_at_most_once_rep)]
 #![feature(crate_in_paths)]
+#![feature(crate_visibility_modifier)]
 
 #![recursion_limit="512"]
 
index 6bbb4d9c6688d5d212569c1b4ccd2867ada15b7f..ece58978c5d532bf5c0bb7c032bc153c34ffc27e 100644 (file)
@@ -12,7 +12,7 @@
 use self::code_stats::CodeStats;
 
 use hir::def_id::CrateNum;
-use ich::Fingerprint;
+use rustc_data_structures::fingerprint::Fingerprint;
 
 use ich;
 use lint;
index 02434b7be0bda22aa1d024d96f6e0d14c694dc83..c78d061a39badc0c8ca9e69585a5db3c8b849607 100644 (file)
@@ -15,7 +15,7 @@
 use rustc::hir;
 use rustc::hir::CodegenFnAttrFlags;
 use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE, CRATE_DEF_INDEX};
-use rustc::ich::Fingerprint;
+use rustc_data_structures::fingerprint::Fingerprint;
 use rustc::middle::exported_symbols::{SymbolExportLevel, ExportedSymbol, metadata_symbol_name};
 use rustc::session::config;
 use rustc::ty::{TyCtxt, SymbolName};
index 3ae30e8579601469c1fa4b06535c5eb4b3c69b1f..8ee2404e10cdfe0ee65829ffc9ca71055df7d291 100644 (file)
@@ -28,7 +28,8 @@
 use rustc::hir::CodegenFnAttrFlags;
 use rustc::hir::def::CtorKind;
 use rustc::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
-use rustc::ich::{Fingerprint, NodeIdHashingMode};
+use rustc::ich::NodeIdHashingMode;
+use rustc_data_structures::fingerprint::Fingerprint;
 use rustc::ty::Instance;
 use common::CodegenCx;
 use rustc::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt};
diff --git a/src/librustc_data_structures/fingerprint.rs b/src/librustc_data_structures/fingerprint.rs
new file mode 100644 (file)
index 0000000..aa9ddda
--- /dev/null
@@ -0,0 +1,111 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use std::mem;
+use stable_hasher;
+use serialize;
+use serialize::opaque::{EncodeResult, Encoder, Decoder};
+
+#[derive(Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Clone, Copy)]
+pub struct Fingerprint(u64, u64);
+
+impl Fingerprint {
+
+    pub const ZERO: Fingerprint = Fingerprint(0, 0);
+
+    #[inline]
+    pub fn from_smaller_hash(hash: u64) -> Fingerprint {
+        Fingerprint(hash, hash)
+    }
+
+    #[inline]
+    pub fn to_smaller_hash(&self) -> u64 {
+        self.0
+    }
+
+    #[inline]
+    pub fn as_value(&self) -> (u64, u64) {
+        (self.0, self.1)
+    }
+
+    #[inline]
+    pub fn combine(self, other: Fingerprint) -> Fingerprint {
+        // See https://stackoverflow.com/a/27952689 on why this function is
+        // implemented this way.
+        Fingerprint(
+            self.0.wrapping_mul(3).wrapping_add(other.0),
+            self.1.wrapping_mul(3).wrapping_add(other.1)
+        )
+    }
+
+    // Combines two hashes in an order independent way. Make sure this is what
+    // you want.
+    #[inline]
+    pub fn combine_commutative(self, other: Fingerprint) -> Fingerprint {
+        let a = (self.1 as u128) << 64 | self.0 as u128;
+        let b = (other.1 as u128) << 64 | other.0 as u128;
+
+        let c = a.wrapping_add(b);
+
+        Fingerprint((c >> 64) as u64, c as u64)
+    }
+
+    pub fn to_hex(&self) -> String {
+        format!("{:x}{:x}", self.0, self.1)
+    }
+
+    pub fn encode_opaque(&self, encoder: &mut Encoder) -> EncodeResult {
+        let bytes: [u8; 16] = unsafe { mem::transmute([self.0.to_le(), self.1.to_le()]) };
+
+        encoder.emit_raw_bytes(&bytes);
+        Ok(())
+    }
+
+    pub fn decode_opaque<'a>(decoder: &mut Decoder<'a>) -> Result<Fingerprint, String> {
+        let mut bytes = [0; 16];
+
+        decoder.read_raw_bytes(&mut bytes)?;
+
+        let [l, r]: [u64; 2] = unsafe { mem::transmute(bytes) };
+
+        Ok(Fingerprint(u64::from_le(l), u64::from_le(r)))
+    }
+}
+
+impl ::std::fmt::Display for Fingerprint {
+    fn fmt(&self, formatter: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+        write!(formatter, "{:x}-{:x}", self.0, self.1)
+    }
+}
+
+impl stable_hasher::StableHasherResult for Fingerprint {
+    fn finish(hasher: stable_hasher::StableHasher<Self>) -> Self {
+        let (_0, _1) = hasher.finalize();
+        Fingerprint(_0, _1)
+    }
+}
+
+impl_stable_hash_via_hash!(Fingerprint);
+
+impl serialize::UseSpecializedEncodable for Fingerprint { }
+
+impl serialize::UseSpecializedDecodable for Fingerprint { }
+
+impl serialize::SpecializedEncoder<Fingerprint> for serialize::opaque::Encoder {
+    fn specialized_encode(&mut self, f: &Fingerprint) -> Result<(), Self::Error> {
+        f.encode_opaque(self)
+    }
+}
+
+impl<'a> serialize::SpecializedDecoder<Fingerprint> for serialize::opaque::Decoder<'a> {
+    fn specialized_decode(&mut self) -> Result<Fingerprint, Self::Error> {
+        Fingerprint::decode_opaque(self)
+    }
+}
index b8c21afc386e9aaf0917b8fb1babb9ca93a0e0f6..3aa15f472a2740f5538ff8ae49514922f07d4f17 100644 (file)
 pub mod snapshot_map;
 pub use ena::snapshot_vec;
 pub mod sorted_map;
-pub mod stable_hasher;
+#[macro_use] pub mod stable_hasher;
 pub mod sync;
 pub mod tiny_list;
 pub mod transitive_relation;
 pub mod tuple_slice;
 pub use ena::unify;
 pub mod work_queue;
+pub mod fingerprint;
 
 pub struct OnDrop<F: Fn()>(pub F);
 
index 805a5ecd9913010a0ad68830b81c83f3a41cdc4d..b6e03b66510e50965fa724b37f14e35c961c116d 100644 (file)
@@ -11,7 +11,7 @@
 use rustc::dep_graph::DepGraph;
 use rustc::hir::{self, map as hir_map};
 use rustc::hir::lowering::lower_crate;
-use rustc::ich::Fingerprint;
+use rustc_data_structures::fingerprint::Fingerprint;
 use rustc_data_structures::stable_hasher::StableHasher;
 use rustc_mir as mir;
 use rustc::session::{CompileResult, CrateDisambiguator, Session};
index 5121b682d36a736a60702a6dfbe16bde1687d945..33d4cf26c039551a5e0c8e5b66bd97e8716b5ad6 100644 (file)
@@ -22,7 +22,7 @@
 use rustc::hir::def::{self, Def, CtorKind};
 use rustc::hir::def_id::{CrateNum, DefId, DefIndex,
                          CRATE_DEF_INDEX, LOCAL_CRATE, LocalDefId};
-use rustc::ich::Fingerprint;
+use rustc_data_structures::fingerprint::Fingerprint;
 use rustc::middle::lang_items;
 use rustc::mir::{self, interpret};
 use rustc::mir::interpret::AllocDecodingSession;
index 96d6c5b75f49e677b475ea161dc9b43f5275bde1..7c445cb715e7cd4d8ed8da3239a52766a67246c9 100644 (file)
@@ -18,7 +18,7 @@
 use rustc::hir::def::CtorKind;
 use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefIndex, DefId, LocalDefId, LOCAL_CRATE};
 use rustc::hir::map::definitions::DefPathTable;
-use rustc::ich::Fingerprint;
+use rustc_data_structures::fingerprint::Fingerprint;
 use rustc::middle::dependency_format::Linkage;
 use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel,
                                       metadata_symbol_name};