Skip to content

Commit 44fc785

Browse files
committed
Move ICH to rustc_crate.
1 parent 5f1330d commit 44fc785

File tree

7 files changed

+81
-74
lines changed

7 files changed

+81
-74
lines changed

compiler/rustc_middle/src/ich/hcx.rs renamed to compiler/rustc_crate/src/ich/hcx.rs

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1+
use crate::cstore::CrateStore;
12
use crate::ich;
2-
use crate::ty::{fast_reject, TyCtxt};
3-
use rustc_crate::cstore::CrateStore;
43

54
use rustc_ast as ast;
6-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5+
use rustc_data_structures::fx::FxHashSet;
76
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
87
use rustc_data_structures::sync::Lrc;
98
use rustc_hir as hir;
109
use rustc_hir::def_id::{DefId, LocalDefId};
1110
use rustc_hir::definitions::{DefPathHash, Definitions};
1211
use rustc_session::Session;
12+
use rustc_span::def_id::{CrateNum, CRATE_DEF_INDEX};
1313
use rustc_span::source_map::SourceMap;
1414
use rustc_span::symbol::Symbol;
1515
use rustc_span::{BytePos, CachingSourceMapView, SourceFile};
1616

17-
use rustc_span::def_id::{CrateNum, CRATE_DEF_INDEX};
18-
use smallvec::SmallVec;
19-
use std::cmp::Ord;
20-
2117
fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
2218
debug_assert!(!ich::IGNORED_ATTRIBUTES.is_empty());
2319
ich::IGNORED_ATTRIBUTES.iter().copied().collect()
@@ -207,12 +203,6 @@ impl<'a, 'b, T: StableHashingContextProvider<'a>> StableHashingContextProvider<'
207203
}
208204
}
209205

210-
impl StableHashingContextProvider<'tcx> for TyCtxt<'tcx> {
211-
fn get_stable_hashing_context(&self) -> StableHashingContext<'tcx> {
212-
(*self).create_stable_hashing_context()
213-
}
214-
}
215-
216206
impl<'a> StableHashingContextProvider<'a> for StableHashingContext<'a> {
217207
fn get_stable_hashing_context(&self) -> StableHashingContext<'a> {
218208
self.clone()
@@ -255,40 +245,14 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> {
255245
}
256246
}
257247

258-
impl<'a> rustc_crate::HashStableContext for StableHashingContext<'a> {}
248+
impl<'a> crate::HashStableContext for StableHashingContext<'a> {}
259249

260-
pub fn hash_stable_trait_impls<'a>(
261-
hcx: &mut StableHashingContext<'a>,
262-
hasher: &mut StableHasher,
263-
blanket_impls: &[DefId],
264-
non_blanket_impls: &FxHashMap<fast_reject::SimplifiedType, Vec<DefId>>,
265-
) {
266-
{
267-
let mut blanket_impls: SmallVec<[_; 8]> =
268-
blanket_impls.iter().map(|&def_id| hcx.def_path_hash(def_id)).collect();
250+
impl<'a> HashStable<StableHashingContext<'a>> for crate::privacy::AccessLevels {
251+
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
252+
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
253+
let crate::privacy::AccessLevels { ref map } = *self;
269254

270-
if blanket_impls.len() > 1 {
271-
blanket_impls.sort_unstable();
272-
}
273-
274-
blanket_impls.hash_stable(hcx, hasher);
275-
}
276-
277-
{
278-
let mut keys: SmallVec<[_; 8]> =
279-
non_blanket_impls.keys().map(|k| (k, k.map_def(|d| hcx.def_path_hash(d)))).collect();
280-
keys.sort_unstable_by(|&(_, ref k1), &(_, ref k2)| k1.cmp(k2));
281-
keys.len().hash_stable(hcx, hasher);
282-
for (key, ref stable_key) in keys {
283-
stable_key.hash_stable(hcx, hasher);
284-
let mut impls: SmallVec<[_; 8]> =
285-
non_blanket_impls[key].iter().map(|&impl_id| hcx.def_path_hash(impl_id)).collect();
286-
287-
if impls.len() > 1 {
288-
impls.sort_unstable();
289-
}
290-
291-
impls.hash_stable(hcx, hasher);
292-
}
255+
map.hash_stable(hcx, hasher);
256+
});
293257
}
294258
}

compiler/rustc_crate/src/ich/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! ICH - Incremental Compilation Hash
2+
3+
pub use self::hcx::{NodeIdHashingMode, StableHashingContext, StableHashingContextProvider};
4+
use rustc_span::symbol::{sym, Symbol};
5+
6+
mod hcx;
7+
mod impls_hir;
8+
mod impls_syntax;
9+
10+
pub const IGNORED_ATTRIBUTES: &[Symbol] = &[
11+
sym::cfg,
12+
sym::rustc_if_this_changed,
13+
sym::rustc_then_this_would_need,
14+
sym::rustc_dirty,
15+
sym::rustc_clean,
16+
sym::rustc_partition_reused,
17+
sym::rustc_partition_codegened,
18+
sym::rustc_expected_cgu_reuse,
19+
];

compiler/rustc_crate/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![feature(int_error_matching)]
2+
#![feature(min_specialization)]
23
#![feature(once_cell)]
4+
#![feature(option_expect_none)]
35
#![feature(or_patterns)]
46

57
#[macro_use]
@@ -13,6 +15,7 @@ use rustc_span::symbol::Symbol;
1315
pub mod codegen_fn_attrs;
1416
pub mod cstore;
1517
pub mod dependency_format;
18+
pub mod ich;
1619
pub mod limits;
1720
pub mod privacy;
1821
pub mod stability;

compiler/rustc_middle/src/ich/impls_ty.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! This module contains `HashStable` implementations for various data types
22
//! from `rustc_middle::ty` in no particular order.
33
4-
use crate::ich::{NodeIdHashingMode, StableHashingContext};
4+
use crate::ich::StableHashingContext;
55
use crate::middle::region;
66
use crate::mir;
77
use crate::ty;
@@ -183,13 +183,3 @@ impl<'a> HashStable<StableHashingContext<'a>> for ty::FloatVid {
183183
bug!("ty::TyKind::hash_stable() - can't hash a FloatVid {:?}.", *self)
184184
}
185185
}
186-
187-
impl<'a> HashStable<StableHashingContext<'a>> for rustc_crate::privacy::AccessLevels {
188-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
189-
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
190-
let rustc_crate::privacy::AccessLevels { ref map } = *self;
191-
192-
map.hash_stable(hcx, hasher);
193-
});
194-
}
195-
}

compiler/rustc_middle/src/ich/mod.rs

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,54 @@
11
//! ICH - Incremental Compilation Hash
22
3-
pub use self::hcx::{
4-
hash_stable_trait_impls, NodeIdHashingMode, StableHashingContext, StableHashingContextProvider,
5-
};
6-
use rustc_span::symbol::{sym, Symbol};
3+
use crate::ty::{fast_reject, TyCtxt};
4+
use rustc_data_structures::fx::FxHashMap;
5+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
6+
use rustc_hir::def_id::DefId;
7+
use smallvec::SmallVec;
8+
use std::cmp::Ord;
79

8-
mod hcx;
10+
pub use rustc_crate::ich::{NodeIdHashingMode, StableHashingContext, StableHashingContextProvider};
911

10-
mod impls_hir;
11-
mod impls_syntax;
1212
mod impls_ty;
1313

14-
pub const IGNORED_ATTRIBUTES: &[Symbol] = &[
15-
sym::cfg,
16-
sym::rustc_if_this_changed,
17-
sym::rustc_then_this_would_need,
18-
sym::rustc_dirty,
19-
sym::rustc_clean,
20-
sym::rustc_partition_reused,
21-
sym::rustc_partition_codegened,
22-
sym::rustc_expected_cgu_reuse,
23-
];
14+
impl StableHashingContextProvider<'tcx> for TyCtxt<'tcx> {
15+
fn get_stable_hashing_context(&self) -> StableHashingContext<'tcx> {
16+
(*self).create_stable_hashing_context()
17+
}
18+
}
19+
20+
pub fn hash_stable_trait_impls<'a>(
21+
hcx: &mut StableHashingContext<'a>,
22+
hasher: &mut StableHasher,
23+
blanket_impls: &[DefId],
24+
non_blanket_impls: &FxHashMap<fast_reject::SimplifiedType, Vec<DefId>>,
25+
) {
26+
{
27+
let mut blanket_impls: SmallVec<[_; 8]> =
28+
blanket_impls.iter().map(|&def_id| hcx.def_path_hash(def_id)).collect();
29+
30+
if blanket_impls.len() > 1 {
31+
blanket_impls.sort_unstable();
32+
}
33+
34+
blanket_impls.hash_stable(hcx, hasher);
35+
}
36+
37+
{
38+
let mut keys: SmallVec<[_; 8]> =
39+
non_blanket_impls.keys().map(|k| (k, k.map_def(|d| hcx.def_path_hash(d)))).collect();
40+
keys.sort_unstable_by(|&(_, ref k1), &(_, ref k2)| k1.cmp(k2));
41+
keys.len().hash_stable(hcx, hasher);
42+
for (key, ref stable_key) in keys {
43+
stable_key.hash_stable(hcx, hasher);
44+
let mut impls: SmallVec<[_; 8]> =
45+
non_blanket_impls[key].iter().map(|&impl_id| hcx.def_path_hash(impl_id)).collect();
46+
47+
if impls.len() > 1 {
48+
impls.sort_unstable();
49+
}
50+
51+
impls.hash_stable(hcx, hasher);
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)