Skip to content

Commit ef08662

Browse files
committed
hir::{hir,def,itemlikevisit,pat_util,print} -> rustc_hir
Also fix fallout wrt. HashStable.
1 parent 1f7b4e9 commit ef08662

File tree

13 files changed

+420
-311
lines changed

13 files changed

+420
-311
lines changed

src/librustc/hir.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,23 @@
33
//! [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html
44
55
pub mod check_attr;
6-
pub mod def;
6+
pub use rustc_hir::def;
77
pub mod exports;
88
pub use rustc_hir::def_id;
99
pub use rustc_hir::hir_id::*;
1010
pub mod intravisit;
11-
pub mod itemlikevisit;
11+
pub use rustc_hir::itemlikevisit;
1212
pub mod map;
13-
pub mod pat_util;
14-
pub mod print;
13+
pub use rustc_hir::pat_util;
14+
pub use rustc_hir::print;
1515
pub mod upvars;
1616

17-
mod hir;
18-
pub use hir::BlockCheckMode::*;
19-
pub use hir::FunctionRetTy::*;
20-
pub use hir::PrimTy::*;
21-
pub use hir::UnOp::*;
22-
pub use hir::UnsafeSource::*;
23-
pub use hir::*;
17+
pub use rustc_hir::BlockCheckMode::*;
18+
pub use rustc_hir::FunctionRetTy::*;
19+
pub use rustc_hir::PrimTy::*;
20+
pub use rustc_hir::UnOp::*;
21+
pub use rustc_hir::UnsafeSource::*;
22+
pub use rustc_hir::*;
2423

2524
use crate::ty::query::Providers;
2625

src/librustc/hir/map/mod.rs

-39
Original file line numberDiff line numberDiff line change
@@ -1266,45 +1266,6 @@ impl<'hir> print::PpAnn for Map<'hir> {
12661266
}
12671267
}
12681268

1269-
impl<'a> print::State<'a> {
1270-
pub fn print_node(&mut self, node: Node<'_>) {
1271-
match node {
1272-
Node::Param(a) => self.print_param(&a),
1273-
Node::Item(a) => self.print_item(&a),
1274-
Node::ForeignItem(a) => self.print_foreign_item(&a),
1275-
Node::TraitItem(a) => self.print_trait_item(a),
1276-
Node::ImplItem(a) => self.print_impl_item(a),
1277-
Node::Variant(a) => self.print_variant(&a),
1278-
Node::AnonConst(a) => self.print_anon_const(&a),
1279-
Node::Expr(a) => self.print_expr(&a),
1280-
Node::Stmt(a) => self.print_stmt(&a),
1281-
Node::PathSegment(a) => self.print_path_segment(&a),
1282-
Node::Ty(a) => self.print_type(&a),
1283-
Node::TraitRef(a) => self.print_trait_ref(&a),
1284-
Node::Binding(a) | Node::Pat(a) => self.print_pat(&a),
1285-
Node::Arm(a) => self.print_arm(&a),
1286-
Node::Block(a) => {
1287-
// Containing cbox, will be closed by print-block at `}`.
1288-
self.cbox(print::INDENT_UNIT);
1289-
// Head-ibox, will be closed by print-block after `{`.
1290-
self.ibox(0);
1291-
self.print_block(&a)
1292-
}
1293-
Node::Lifetime(a) => self.print_lifetime(&a),
1294-
Node::Visibility(a) => self.print_visibility(&a),
1295-
Node::GenericParam(_) => bug!("cannot print Node::GenericParam"),
1296-
Node::Field(_) => bug!("cannot print StructField"),
1297-
// These cases do not carry enough information in the
1298-
// `hir_map` to reconstruct their full structure for pretty
1299-
// printing.
1300-
Node::Ctor(..) => bug!("cannot print isolated Ctor"),
1301-
Node::Local(a) => self.print_local_decl(&a),
1302-
Node::MacroDef(_) => bug!("cannot print MacroDef"),
1303-
Node::Crate => bug!("cannot print Crate"),
1304-
}
1305-
}
1306-
}
1307-
13081269
fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
13091270
let id_str = format!(" (hir_id={})", id);
13101271
let id_str = if include_id { &id_str[..] } else { "" };

src/librustc/ich/hcx.rs

+4-29
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ pub struct StableHashingContext<'a> {
3333
sess: &'a Session,
3434
definitions: &'a Definitions,
3535
cstore: &'a dyn CrateStore,
36-
body_resolver: BodyResolver<'a>,
36+
pub(super) body_resolver: BodyResolver<'a>,
3737
hash_spans: bool,
3838
hash_bodies: bool,
39-
node_id_hashing_mode: NodeIdHashingMode,
39+
pub(super) node_id_hashing_mode: NodeIdHashingMode,
4040

4141
// Very often, we are hashing something that does not need the
4242
// `CachingSourceMapView`, so we initialize it lazily.
@@ -54,12 +54,12 @@ pub enum NodeIdHashingMode {
5454
/// We could also just store a plain reference to the `hir::Crate` but we want
5555
/// to avoid that the crate is used to get untracked access to all of the HIR.
5656
#[derive(Clone, Copy)]
57-
struct BodyResolver<'tcx>(&'tcx hir::Crate<'tcx>);
57+
pub(super) struct BodyResolver<'tcx>(&'tcx hir::Crate<'tcx>);
5858

5959
impl<'tcx> BodyResolver<'tcx> {
6060
/// Returns a reference to the `hir::Body` with the given `BodyId`.
6161
/// **Does not do any tracking**; use carefully.
62-
fn body(self, id: hir::BodyId) -> &'tcx hir::Body<'tcx> {
62+
pub(super) fn body(self, id: hir::BodyId) -> &'tcx hir::Body<'tcx> {
6363
self.0.body(id)
6464
}
6565
}
@@ -207,31 +207,6 @@ impl<'a> StableHashingContextProvider<'a> for StableHashingContext<'a> {
207207

208208
impl<'a> crate::dep_graph::DepGraphSafe for StableHashingContext<'a> {}
209209

210-
impl<'a> HashStable<StableHashingContext<'a>> for hir::BodyId {
211-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
212-
if hcx.hash_bodies() {
213-
hcx.body_resolver.body(*self).hash_stable(hcx, hasher);
214-
}
215-
}
216-
}
217-
218-
impl<'a> HashStable<StableHashingContext<'a>> for hir::HirId {
219-
#[inline]
220-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
221-
match hcx.node_id_hashing_mode {
222-
NodeIdHashingMode::Ignore => {
223-
// Don't do anything.
224-
}
225-
NodeIdHashingMode::HashDefPath => {
226-
let hir::HirId { owner, local_id } = *self;
227-
228-
hcx.local_def_path_hash(owner).hash_stable(hcx, hasher);
229-
local_id.hash_stable(hcx, hasher);
230-
}
231-
}
232-
}
233-
}
234-
235210
impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::HirId {
236211
type KeyType = (DefPathHash, hir::ItemLocalId);
237212

src/librustc/ich/impls_hir.rs

+125-106
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,132 @@ use smallvec::SmallVec;
1111
use std::mem;
1212
use syntax::attr;
1313

14-
impl<'a> HashStable<StableHashingContext<'a>> for DefId {
14+
impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
1515
#[inline]
16-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
17-
hcx.def_path_hash(*self).hash_stable(hcx, hasher);
16+
fn hash_def_id(&mut self, def_id: DefId, hasher: &mut StableHasher) {
17+
let hcx = self;
18+
hcx.def_path_hash(def_id).hash_stable(hcx, hasher);
19+
}
20+
21+
#[inline]
22+
fn hash_hir_id(&mut self, hir_id: hir::HirId, hasher: &mut StableHasher) {
23+
let hcx = self;
24+
match hcx.node_id_hashing_mode {
25+
NodeIdHashingMode::Ignore => {
26+
// Don't do anything.
27+
}
28+
NodeIdHashingMode::HashDefPath => {
29+
let hir::HirId { owner, local_id } = hir_id;
30+
31+
hcx.local_def_path_hash(owner).hash_stable(hcx, hasher);
32+
local_id.hash_stable(hcx, hasher);
33+
}
34+
}
35+
}
36+
37+
fn hash_body_id(&mut self, id: hir::BodyId, hasher: &mut StableHasher) {
38+
let hcx = self;
39+
if hcx.hash_bodies() {
40+
hcx.body_resolver.body(id).hash_stable(hcx, hasher);
41+
}
42+
}
43+
44+
// The following implementations of HashStable for `ItemId`, `TraitItemId`, and
45+
// `ImplItemId` deserve special attention. Normally we do not hash `NodeId`s within
46+
// the HIR, since they just signify a HIR nodes own path. But `ItemId` et al
47+
// are used when another item in the HIR is *referenced* and we certainly
48+
// want to pick up on a reference changing its target, so we hash the NodeIds
49+
// in "DefPath Mode".
50+
51+
fn hash_item_id(&mut self, id: hir::ItemId, hasher: &mut StableHasher) {
52+
let hcx = self;
53+
let hir::ItemId { id } = id;
54+
55+
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
56+
id.hash_stable(hcx, hasher);
57+
})
58+
}
59+
60+
fn hash_impl_item_id(&mut self, id: hir::ImplItemId, hasher: &mut StableHasher) {
61+
let hcx = self;
62+
let hir::ImplItemId { hir_id } = id;
63+
64+
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
65+
hir_id.hash_stable(hcx, hasher);
66+
})
67+
}
68+
69+
fn hash_trait_item_id(&mut self, id: hir::TraitItemId, hasher: &mut StableHasher) {
70+
let hcx = self;
71+
let hir::TraitItemId { hir_id } = id;
72+
73+
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
74+
hir_id.hash_stable(hcx, hasher);
75+
})
76+
}
77+
78+
fn hash_hir_mod(&mut self, module: &hir::Mod<'_>, hasher: &mut StableHasher) {
79+
let hcx = self;
80+
let hir::Mod { inner: ref inner_span, ref item_ids } = *module;
81+
82+
inner_span.hash_stable(hcx, hasher);
83+
84+
// Combining the `DefPathHash`s directly is faster than feeding them
85+
// into the hasher. Because we use a commutative combine, we also don't
86+
// have to sort the array.
87+
let item_ids_hash = item_ids
88+
.iter()
89+
.map(|id| {
90+
let (def_path_hash, local_id) = id.id.to_stable_hash_key(hcx);
91+
debug_assert_eq!(local_id, hir::ItemLocalId::from_u32(0));
92+
def_path_hash.0
93+
})
94+
.fold(Fingerprint::ZERO, |a, b| a.combine_commutative(b));
95+
96+
item_ids.len().hash_stable(hcx, hasher);
97+
item_ids_hash.hash_stable(hcx, hasher);
98+
}
99+
100+
fn hash_hir_expr(&mut self, expr: &hir::Expr<'_>, hasher: &mut StableHasher) {
101+
self.while_hashing_hir_bodies(true, |hcx| {
102+
let hir::Expr { hir_id: _, ref span, ref kind, ref attrs } = *expr;
103+
104+
span.hash_stable(hcx, hasher);
105+
kind.hash_stable(hcx, hasher);
106+
attrs.hash_stable(hcx, hasher);
107+
})
108+
}
109+
110+
fn hash_hir_ty(&mut self, ty: &hir::Ty<'_>, hasher: &mut StableHasher) {
111+
self.while_hashing_hir_bodies(true, |hcx| {
112+
let hir::Ty { hir_id: _, ref kind, ref span } = *ty;
113+
114+
kind.hash_stable(hcx, hasher);
115+
span.hash_stable(hcx, hasher);
116+
})
117+
}
118+
119+
fn hash_hir_visibility_kind(
120+
&mut self,
121+
vis: &hir::VisibilityKind<'_>,
122+
hasher: &mut StableHasher,
123+
) {
124+
let hcx = self;
125+
mem::discriminant(vis).hash_stable(hcx, hasher);
126+
match *vis {
127+
hir::VisibilityKind::Public | hir::VisibilityKind::Inherited => {
128+
// No fields to hash.
129+
}
130+
hir::VisibilityKind::Crate(sugar) => {
131+
sugar.hash_stable(hcx, hasher);
132+
}
133+
hir::VisibilityKind::Restricted { ref path, hir_id } => {
134+
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
135+
hir_id.hash_stable(hcx, hasher);
136+
});
137+
path.hash_stable(hcx, hasher);
138+
}
139+
}
18140
}
19141
}
20142

@@ -69,66 +191,6 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::ItemLocalId {
69191
}
70192
}
71193

72-
// The following implementations of HashStable for `ItemId`, `TraitItemId`, and
73-
// `ImplItemId` deserve special attention. Normally we do not hash `NodeId`s within
74-
// the HIR, since they just signify a HIR nodes own path. But `ItemId` et al
75-
// are used when another item in the HIR is *referenced* and we certainly
76-
// want to pick up on a reference changing its target, so we hash the NodeIds
77-
// in "DefPath Mode".
78-
79-
impl<'a> HashStable<StableHashingContext<'a>> for hir::ItemId {
80-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
81-
let hir::ItemId { id } = *self;
82-
83-
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
84-
id.hash_stable(hcx, hasher);
85-
})
86-
}
87-
}
88-
89-
impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItemId {
90-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
91-
let hir::TraitItemId { hir_id } = *self;
92-
93-
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
94-
hir_id.hash_stable(hcx, hasher);
95-
})
96-
}
97-
}
98-
99-
impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItemId {
100-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
101-
let hir::ImplItemId { hir_id } = *self;
102-
103-
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
104-
hir_id.hash_stable(hcx, hasher);
105-
})
106-
}
107-
}
108-
109-
impl<'a> HashStable<StableHashingContext<'a>> for hir::Ty<'_> {
110-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
111-
hcx.while_hashing_hir_bodies(true, |hcx| {
112-
let hir::Ty { hir_id: _, ref kind, ref span } = *self;
113-
114-
kind.hash_stable(hcx, hasher);
115-
span.hash_stable(hcx, hasher);
116-
})
117-
}
118-
}
119-
120-
impl<'a> HashStable<StableHashingContext<'a>> for hir::Expr<'_> {
121-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
122-
hcx.while_hashing_hir_bodies(true, |hcx| {
123-
let hir::Expr { hir_id: _, ref span, ref kind, ref attrs } = *self;
124-
125-
span.hash_stable(hcx, hasher);
126-
kind.hash_stable(hcx, hasher);
127-
attrs.hash_stable(hcx, hasher);
128-
})
129-
}
130-
}
131-
132194
impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItem<'_> {
133195
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
134196
let hir::TraitItem { hir_id: _, ident, ref attrs, ref generics, ref kind, span } = *self;
@@ -168,49 +230,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItem<'_> {
168230
}
169231
}
170232

171-
impl<'a> HashStable<StableHashingContext<'a>> for hir::VisibilityKind<'_> {
172-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
173-
mem::discriminant(self).hash_stable(hcx, hasher);
174-
match *self {
175-
hir::VisibilityKind::Public | hir::VisibilityKind::Inherited => {
176-
// No fields to hash.
177-
}
178-
hir::VisibilityKind::Crate(sugar) => {
179-
sugar.hash_stable(hcx, hasher);
180-
}
181-
hir::VisibilityKind::Restricted { ref path, hir_id } => {
182-
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
183-
hir_id.hash_stable(hcx, hasher);
184-
});
185-
path.hash_stable(hcx, hasher);
186-
}
187-
}
188-
}
189-
}
190-
191-
impl<'a> HashStable<StableHashingContext<'a>> for hir::Mod<'_> {
192-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
193-
let hir::Mod { inner: ref inner_span, ref item_ids } = *self;
194-
195-
inner_span.hash_stable(hcx, hasher);
196-
197-
// Combining the `DefPathHash`s directly is faster than feeding them
198-
// into the hasher. Because we use a commutative combine, we also don't
199-
// have to sort the array.
200-
let item_ids_hash = item_ids
201-
.iter()
202-
.map(|id| {
203-
let (def_path_hash, local_id) = id.id.to_stable_hash_key(hcx);
204-
debug_assert_eq!(local_id, hir::ItemLocalId::from_u32(0));
205-
def_path_hash.0
206-
})
207-
.fold(Fingerprint::ZERO, |a, b| a.combine_commutative(b));
208-
209-
item_ids.len().hash_stable(hcx, hasher);
210-
item_ids_hash.hash_stable(hcx, hasher);
211-
}
212-
}
213-
214233
impl<'a> HashStable<StableHashingContext<'a>> for hir::Item<'_> {
215234
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
216235
let hir::Item { ident, ref attrs, hir_id: _, ref kind, ref vis, span } = *self;

0 commit comments

Comments
 (0)