@@ -15,23 +15,25 @@ use rustc_data_structures::fx::FxHashMap;
15
15
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
16
16
use rustc_hir:: def_id:: LocalDefId ;
17
17
use rustc_hir:: * ;
18
- use rustc_index:: vec:: IndexVec ;
18
+ use rustc_index:: vec:: { Idx , IndexVec } ;
19
19
use rustc_span:: DUMMY_SP ;
20
20
use std:: collections:: BTreeMap ;
21
21
22
- #[ derive( Debug ) ]
23
- struct HirOwnerData < ' hir > {
24
- signature : Option < & ' hir Owner < ' hir > > ,
25
- with_bodies : Option < & ' hir mut OwnerNodes < ' hir > > ,
26
- }
27
-
22
+ /// Result of HIR indexing.
28
23
#[ derive( Debug ) ]
29
24
pub struct IndexedHir < ' hir > {
30
- map : IndexVec < LocalDefId , HirOwnerData < ' hir > > ,
25
+ /// Contents of the HIR owned by each definition. None for definitions that are not HIR owners.
26
+ // The `mut` comes from construction time, and is harmless since we only ever hand out
27
+ // immutable refs to IndexedHir.
28
+ map : IndexVec < LocalDefId , Option < & ' hir mut OwnerNodes < ' hir > > > ,
29
+ /// Map from each owner to its parent's HirId inside another owner.
30
+ // This map is separate from `map` to eventually allow for per-owner indexing.
31
31
parenting : FxHashMap < LocalDefId , HirId > ,
32
32
}
33
33
34
- #[ derive( Debug ) ]
34
+ /// Top-level HIR node for current owner. This only contains the node for which
35
+ /// `HirId::local_id == 0`, and excludes bodies.
36
+ #[ derive( Copy , Clone , Debug ) ]
35
37
pub struct Owner < ' tcx > {
36
38
node : Node < ' tcx > ,
37
39
}
@@ -43,6 +45,9 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Owner<'tcx> {
43
45
}
44
46
}
45
47
48
+ /// HIR node coupled with its parent's id in the same HIR owner.
49
+ ///
50
+ /// The parent is trash when the node is a HIR owner.
46
51
#[ derive( Clone , Debug ) ]
47
52
pub struct ParentedNode < ' tcx > {
48
53
parent : ItemLocalId ,
@@ -51,8 +56,12 @@ pub struct ParentedNode<'tcx> {
51
56
52
57
#[ derive( Debug ) ]
53
58
pub struct OwnerNodes < ' tcx > {
59
+ /// Pre-computed hash of the full HIR.
54
60
hash : Fingerprint ,
61
+ /// Full HIR for the current owner.
62
+ // The zeroth node's parent is trash, but is never accessed.
55
63
nodes : IndexVec < ItemLocalId , Option < ParentedNode < ' tcx > > > ,
64
+ /// Content of local bodies.
56
65
bodies : FxHashMap < ItemLocalId , & ' tcx Body < ' tcx > > ,
57
66
}
58
67
@@ -65,6 +74,8 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for OwnerNodes<'tcx> {
65
74
}
66
75
}
67
76
77
+ /// Attributes owner by a HIR owner. It is build as a slice inside the attributes map, restricted
78
+ /// to the nodes whose `HirId::owner` is `prefix`.
68
79
#[ derive( Copy , Clone ) ]
69
80
pub struct AttributeMap < ' tcx > {
70
81
map : & ' tcx BTreeMap < HirId , & ' tcx [ Attribute ] > ,
@@ -127,8 +138,12 @@ pub fn provide(providers: &mut Providers) {
127
138
providers. index_hir = map:: index_hir;
128
139
providers. crate_hash = map:: crate_hash;
129
140
providers. hir_module_items = |tcx, id| & tcx. untracked_crate . modules [ & id] ;
130
- providers. hir_owner = |tcx, id| tcx. index_hir ( ( ) ) . map [ id] . signature ;
131
- providers. hir_owner_nodes = |tcx, id| tcx. index_hir ( ( ) ) . map [ id] . with_bodies . as_deref ( ) ;
141
+ providers. hir_owner = |tcx, id| {
142
+ let owner = tcx. index_hir ( ( ) ) . map [ id] . as_ref ( ) ?;
143
+ let node = owner. nodes [ ItemLocalId :: new ( 0 ) ] . as_ref ( ) ?. node ;
144
+ Some ( Owner { node } )
145
+ } ;
146
+ providers. hir_owner_nodes = |tcx, id| tcx. index_hir ( ( ) ) . map [ id] . as_deref ( ) ;
132
147
providers. hir_owner_parent = |tcx, id| {
133
148
let index = tcx. index_hir ( ( ) ) ;
134
149
index. parenting . get ( & id) . copied ( ) . unwrap_or ( CRATE_HIR_ID )
0 commit comments