]> git.lizzy.rs Git - rust.git/commitdiff
Move SVH structure to data structures
authorMark Rousskov <mark.simulacrum@gmail.com>
Fri, 3 Aug 2018 18:22:22 +0000 (12:22 -0600)
committerMark Rousskov <mark.simulacrum@gmail.com>
Thu, 9 Aug 2018 16:00:25 +0000 (10:00 -0600)
15 files changed:
src/librustc/hir/map/collector.rs
src/librustc/hir/map/mod.rs
src/librustc/hir/mod.rs
src/librustc/hir/svh.rs [deleted file]
src/librustc/middle/cstore.rs
src/librustc/ty/mod.rs
src/librustc/ty/query/mod.rs
src/librustc_codegen_utils/link.rs
src/librustc_data_structures/lib.rs
src/librustc_data_structures/svh.rs [new file with mode: 0644]
src/librustc_incremental/persist/fs.rs
src/librustc_metadata/creader.rs
src/librustc_metadata/cstore_impl.rs
src/librustc_metadata/locator.rs
src/librustc_metadata/schema.rs

index 0150ba659c900dcb8ea2a32e05d82926c5f04567..3934475bea90c88c8d65212f9a607a1fe6022b09 100644 (file)
@@ -12,7 +12,7 @@
 use dep_graph::{DepGraph, DepKind, DepNodeIndex};
 use hir::def_id::{LOCAL_CRATE, CrateNum};
 use hir::intravisit::{Visitor, NestedVisitorMap};
-use hir::svh::Svh;
+use rustc_data_structures::svh::Svh;
 use ich::Fingerprint;
 use middle::cstore::CrateStore;
 use session::CrateDisambiguator;
index b05bcadf82649daa57cb8573a60d2a613ce8263a..81897322b6f6be6bb01c8233eaa58b3fa564dc0b 100644 (file)
@@ -22,6 +22,7 @@
 use middle::cstore::CrateStore;
 
 use rustc_target::spec::abi::Abi;
+use rustc_data_structures::svh::Svh;
 use syntax::ast::{self, Name, NodeId, CRATE_NODE_ID};
 use syntax::codemap::Spanned;
 use syntax::ext::base::MacroKind;
@@ -29,7 +30,6 @@
 
 use hir::*;
 use hir::print::Nested;
-use hir::svh::Svh;
 use util::nodemap::FxHashMap;
 
 use std::io;
index 0003790e6d552cfc066ed946c8789206b4f1f8c5..521499e4766892f6207664365a0093a47f0e0d7b 100644 (file)
@@ -70,7 +70,6 @@ macro_rules! hir_vec {
 pub mod map;
 pub mod pat_util;
 pub mod print;
-pub mod svh;
 
 /// A HirId uniquely identifies a node in the HIR of the current crate. It is
 /// composed of the `owner`, which is the DefIndex of the directly enclosing
diff --git a/src/librustc/hir/svh.rs b/src/librustc/hir/svh.rs
deleted file mode 100644 (file)
index a6cfcb7..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright 2012-2014 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.
-
-//! Calculation and management of a Strict Version Hash for crates
-//!
-//! The SVH is used for incremental compilation to track when HIR
-//! nodes have changed between compilations, and also to detect
-//! mismatches where we have two versions of the same crate that were
-//! compiled from distinct sources.
-
-use std::fmt;
-use std::hash::{Hash, Hasher};
-use serialize::{Encodable, Decodable, Encoder, Decoder};
-
-#[derive(Copy, Clone, PartialEq, Eq, Debug)]
-pub struct Svh {
-    hash: u64,
-}
-
-impl Svh {
-    /// Create a new `Svh` given the hash. If you actually want to
-    /// compute the SVH from some HIR, you want the `calculate_svh`
-    /// function found in `librustc_incremental`.
-    pub fn new(hash: u64) -> Svh {
-        Svh { hash: hash }
-    }
-
-    pub fn as_u64(&self) -> u64 {
-        self.hash
-    }
-
-    pub fn to_string(&self) -> String {
-        format!("{:016x}", self.hash)
-    }
-}
-
-impl Hash for Svh {
-    fn hash<H>(&self, state: &mut H) where H: Hasher {
-        self.hash.to_le().hash(state);
-    }
-}
-
-impl fmt::Display for Svh {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        f.pad(&self.to_string())
-    }
-}
-
-impl Encodable for Svh {
-    fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
-        s.emit_u64(self.as_u64().to_le())
-    }
-}
-
-impl Decodable for Svh {
-    fn decode<D: Decoder>(d: &mut D) -> Result<Svh, D::Error> {
-        d.read_u64()
-         .map(u64::from_le)
-         .map(Svh::new)
-    }
-}
-
-impl_stable_hash_for!(struct Svh {
-    hash
-});
index 0e84104245dcb14a78ae3f1d2be8cfa1eb54bae5..b91a9644b211a3a73d3bc75c917c3c9978b78443 100644 (file)
@@ -25,7 +25,7 @@
 use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
 use hir::map as hir_map;
 use hir::map::definitions::{DefKey, DefPathTable};
-use hir::svh::Svh;
+use rustc_data_structures::svh::Svh;
 use ty::{self, TyCtxt};
 use session::{Session, CrateDisambiguator};
 use session::search_paths::PathKind;
index 4fda3bdca3dfca022e701e591e9b6ff5be0fe779..6c5713d233a8fc295134e171b5df6bdbd00728b3 100644 (file)
@@ -18,7 +18,7 @@
 use hir::def::{Def, CtorKind, ExportMap};
 use hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
 use hir::map::DefPathData;
-use hir::svh::Svh;
+use rustc_data_structures::svh::Svh;
 use ich::Fingerprint;
 use ich::StableHashingContext;
 use infer::canonical::Canonical;
index 35080123d3e10ff20cee4331e24229b7e8e38666..ef22ebef9d7d4867fd5c79443f48d0f973854d8f 100644 (file)
@@ -13,7 +13,7 @@
 use hir::def_id::{CrateNum, DefId, DefIndex};
 use hir::def::{Def, Export};
 use hir::{self, TraitCandidate, ItemLocalId, CodegenFnAttrs};
-use hir::svh::Svh;
+use rustc_data_structures::svh::Svh;
 use infer::canonical::{self, Canonical};
 use lint;
 use middle::borrowck::BorrowCheckResult;
index 73cffdf7d491d297667881481aa2129657426738..a0d88ccae0f135d1ec0263b62b534bbbb2fa7031 100644 (file)
@@ -11,7 +11,7 @@
 use rustc::session::config::{self, OutputFilenames, Input, OutputType};
 use rustc::session::Session;
 use rustc::middle::cstore::LinkMeta;
-use rustc::hir::svh::Svh;
+use rustc_data_structures::svh::Svh;
 use std::path::{Path, PathBuf};
 use syntax::{ast, attr};
 use syntax_pos::Span;
index dd90cf7ae19e45bf246a9f2ca36a2001fd152ef6..b8c21afc386e9aaf0917b8fb1babb9ca93a0e0f6 100644 (file)
@@ -46,6 +46,7 @@
 extern crate rustc_rayon as rayon;
 extern crate rustc_rayon_core as rayon_core;
 extern crate rustc_hash;
+extern crate serialize;
 
 // See librustc_cratesio_shim/Cargo.toml for a comment explaining this.
 #[allow(unused_extern_crates)]
@@ -53,6 +54,7 @@
 
 pub use rustc_serialize::hex::ToHex;
 
+pub mod svh;
 pub mod accumulate_vec;
 pub mod array_vec;
 pub mod base_n;
diff --git a/src/librustc_data_structures/svh.rs b/src/librustc_data_structures/svh.rs
new file mode 100644 (file)
index 0000000..94f1325
--- /dev/null
@@ -0,0 +1,84 @@
+// Copyright 2012-2014 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.
+
+//! Calculation and management of a Strict Version Hash for crates
+//!
+//! The SVH is used for incremental compilation to track when HIR
+//! nodes have changed between compilations, and also to detect
+//! mismatches where we have two versions of the same crate that were
+//! compiled from distinct sources.
+
+use std::fmt;
+use std::hash::{Hash, Hasher};
+use serialize::{Encodable, Decodable, Encoder, Decoder};
+
+use stable_hasher;
+
+#[derive(Copy, Clone, PartialEq, Eq, Debug)]
+pub struct Svh {
+    hash: u64,
+}
+
+impl Svh {
+    /// Create a new `Svh` given the hash. If you actually want to
+    /// compute the SVH from some HIR, you want the `calculate_svh`
+    /// function found in `librustc_incremental`.
+    pub fn new(hash: u64) -> Svh {
+        Svh { hash: hash }
+    }
+
+    pub fn as_u64(&self) -> u64 {
+        self.hash
+    }
+
+    pub fn to_string(&self) -> String {
+        format!("{:016x}", self.hash)
+    }
+}
+
+impl Hash for Svh {
+    fn hash<H>(&self, state: &mut H) where H: Hasher {
+        self.hash.to_le().hash(state);
+    }
+}
+
+impl fmt::Display for Svh {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        f.pad(&self.to_string())
+    }
+}
+
+impl Encodable for Svh {
+    fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
+        s.emit_u64(self.as_u64().to_le())
+    }
+}
+
+impl Decodable for Svh {
+    fn decode<D: Decoder>(d: &mut D) -> Result<Svh, D::Error> {
+        d.read_u64()
+         .map(u64::from_le)
+         .map(Svh::new)
+    }
+}
+
+impl<T> stable_hasher::HashStable<T> for Svh {
+    #[inline]
+    fn hash_stable<W: stable_hasher::StableHasherResult>(
+        &self,
+        ctx: &mut T,
+        hasher: &mut stable_hasher::StableHasher<W>
+    ) {
+        let Svh {
+            hash
+        } = *self;
+        hash.hash_stable(ctx, hasher);
+    }
+}
index 795825f180c9dfdcb0658b1c2a1e6898043fff7a..65bc7f3f8565f41df01c6dc7a6e9a9db56e9ce8a 100644 (file)
 //! unsupported file system and emit a warning in that case. This is not yet
 //! implemented.
 
-use rustc::hir::svh::Svh;
 use rustc::session::{Session, CrateDisambiguator};
 use rustc::util::fs as fs_util;
 use rustc_data_structures::{flock, base_n};
 use rustc_data_structures::fx::{FxHashSet, FxHashMap};
+use rustc_data_structures::svh::Svh;
 
 use std::fs as std_fs;
 use std::io;
index 62c06aac1df0ecb5bb3006fdcc97a5ed4b8c9ecd..d3b70933e2cd416a25d816865d5816805c3e9ed9 100644 (file)
@@ -16,7 +16,7 @@
 use rustc_data_structures::sync::{Lrc, RwLock, Lock};
 
 use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX};
-use rustc::hir::svh::Svh;
+use rustc_data_structures::svh::Svh;
 use rustc::middle::allocator::AllocatorKind;
 use rustc::middle::cstore::DepKind;
 use rustc::mir::interpret::AllocDecodingState;
index 060dddd5343885d60119a5c7aec7d49720448633..4926da3b880e768276df764e7390d9c8a371bd45 100644 (file)
@@ -30,6 +30,7 @@
 use rustc::hir::map::blocks::FnLikeNode;
 use rustc::hir::map::definitions::DefPathTable;
 use rustc::util::nodemap::DefIdMap;
+use rustc_data_structures::svh::Svh;
 
 use std::any::Any;
 use rustc_data_structures::sync::Lrc;
@@ -515,7 +516,7 @@ fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> CrateDisambiguator
         self.get_crate_data(cnum).root.disambiguator
     }
 
-    fn crate_hash_untracked(&self, cnum: CrateNum) -> hir::svh::Svh
+    fn crate_hash_untracked(&self, cnum: CrateNum) -> Svh
     {
         self.get_crate_data(cnum).root.hash
     }
index f68bcdd62c695873388510a7c811a21c9ad16618..52777e5f6b90df7452eabe701565dcdcae660e83 100644 (file)
 use creader::Library;
 use schema::{METADATA_HEADER, rustc_version};
 
-use rustc::hir::svh::Svh;
+use rustc_data_structures::svh::Svh;
 use rustc::middle::cstore::MetadataLoader;
 use rustc::session::{config, Session};
 use rustc::session::filesearch::{FileSearch, FileMatches, FileDoesntMatch};
index 894c7cbf683dcae2d1ecddf009d09b9ec55ce23c..781652e1985d6fe6304815861c775932adb0a8d2 100644 (file)
@@ -20,6 +20,7 @@
 use rustc::session::CrateDisambiguator;
 use rustc::ty::{self, Ty, ReprOptions};
 use rustc_target::spec::{PanicStrategy, TargetTriple};
+use rustc_data_structures::svh::Svh;
 
 use rustc_serialize as serialize;
 use syntax::{ast, attr};
@@ -187,7 +188,7 @@ pub struct CrateRoot {
     pub name: Symbol,
     pub triple: TargetTriple,
     pub extra_filename: String,
-    pub hash: hir::svh::Svh,
+    pub hash: Svh,
     pub disambiguator: CrateDisambiguator,
     pub panic_strategy: PanicStrategy,
     pub edition: Edition,
@@ -223,7 +224,7 @@ pub struct CrateRoot {
 #[derive(RustcEncodable, RustcDecodable)]
 pub struct CrateDep {
     pub name: ast::Name,
-    pub hash: hir::svh::Svh,
+    pub hash: Svh,
     pub kind: DepKind,
     pub extra_filename: String,
 }