Skip to content

Commit 569272a

Browse files
authored
Rollup merge of #70092 - eddyb:hir-items-are-just-nodes, r=Zoxc
hir: replace "items" terminology with "nodes" where appropriate. The newly added `HirOwnerItems` confused me before I realized that "items" there actually referred to HIR nodes, not `hir:Item` or "item-like" (which we should IMO replace with "owner"). I suspect the naming had something to do with `ItemLocalId`'s use of "item". That is, `ItemLocalId` could be interpreted to mean one of two things: * `IntraItemNodeId` i.e. `IntraOwnerNodeId` * this is IMO correct, and I'd even like to rename it, but I didn't want to throw that into this PR * `IntraOwnerItemId` * this is what `HirOwnerItems` would seem to imply r? @Zoxc cc @michaelwoerister @nikomatsakis
2 parents a6d0c35 + be9679d commit 569272a

40 files changed

+394
-391
lines changed

src/librustc/arena.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ macro_rules! arena_types {
165165
// HIR query types
166166
[few] indexed_hir: rustc::hir::map::IndexedHir<$tcx>,
167167
[few] hir_definitions: rustc::hir::map::definitions::Definitions,
168-
[] hir_owner: rustc::hir::HirOwner<$tcx>,
169-
[] hir_owner_items: rustc::hir::HirOwnerItems<$tcx>,
168+
[] hir_owner: rustc::hir::Owner<$tcx>,
169+
[] hir_owner_nodes: rustc::hir::OwnerNodes<$tcx>,
170170
], $tcx);
171171
)
172172
}

src/librustc/dep_graph/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ impl DepGraph {
659659
// bug that must be fixed before removing this.
660660
match dep_dep_node.kind {
661661
DepKind::hir_owner
662-
| DepKind::hir_owner_items
662+
| DepKind::hir_owner_nodes
663663
| DepKind::CrateMetadata => {
664664
if let Some(def_id) = dep_dep_node.extract_def_id(tcx) {
665665
if def_id_corresponds_to_hir_dep_node(tcx, def_id) {

src/librustc/hir/map/collector.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::arena::Arena;
22
use crate::hir::map::definitions::{self, DefPathHash};
33
use crate::hir::map::{Entry, HirOwnerData, Map};
4-
use crate::hir::{HirItem, HirOwner, HirOwnerItems};
4+
use crate::hir::{Owner, OwnerNodes, ParentedNode};
55
use crate::ich::StableHashingContext;
66
use crate::middle::cstore::CrateStore;
77
use rustc_data_structures::fingerprint::Fingerprint;
@@ -203,30 +203,30 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
203203
let data = &mut self.map[id.owner];
204204

205205
if data.with_bodies.is_none() {
206-
data.with_bodies = Some(arena.alloc(HirOwnerItems {
206+
data.with_bodies = Some(arena.alloc(OwnerNodes {
207207
hash,
208-
items: IndexVec::new(),
208+
nodes: IndexVec::new(),
209209
bodies: FxHashMap::default(),
210210
}));
211211
}
212212

213-
let items = data.with_bodies.as_mut().unwrap();
213+
let nodes = data.with_bodies.as_mut().unwrap();
214214

215215
if i == 0 {
216216
// Overwrite the dummy hash with the real HIR owner hash.
217-
items.hash = hash;
217+
nodes.hash = hash;
218218

219219
// FIXME: feature(impl_trait_in_bindings) broken and trigger this assert
220220
//assert!(data.signature.is_none());
221221

222222
data.signature =
223-
Some(self.arena.alloc(HirOwner { parent: entry.parent, node: entry.node }));
223+
Some(self.arena.alloc(Owner { parent: entry.parent, node: entry.node }));
224224
} else {
225225
assert_eq!(entry.parent.owner, id.owner);
226226
insert_vec_map(
227-
&mut items.items,
227+
&mut nodes.nodes,
228228
id.local_id,
229-
HirItem { parent: entry.parent.local_id, node: entry.node },
229+
ParentedNode { parent: entry.parent.local_id, node: entry.node },
230230
);
231231
}
232232
}

src/librustc/hir/map/mod.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub use self::definitions::{
33
DefKey, DefPath, DefPathData, DefPathHash, Definitions, DisambiguatedDefPathData,
44
};
55

6-
use crate::hir::{HirOwner, HirOwnerItems};
6+
use crate::hir::{Owner, OwnerNodes};
77
use crate::ty::query::Providers;
88
use crate::ty::TyCtxt;
99
use rustc_ast::ast::{self, Name, NodeId};
@@ -130,8 +130,8 @@ fn is_body_owner<'hir>(node: Node<'hir>, hir_id: HirId) -> bool {
130130
}
131131

132132
pub(super) struct HirOwnerData<'hir> {
133-
pub(super) signature: Option<&'hir HirOwner<'hir>>,
134-
pub(super) with_bodies: Option<&'hir mut HirOwnerItems<'hir>>,
133+
pub(super) signature: Option<&'hir Owner<'hir>>,
134+
pub(super) with_bodies: Option<&'hir mut OwnerNodes<'hir>>,
135135
}
136136

137137
pub struct IndexedHir<'hir> {
@@ -345,9 +345,12 @@ impl<'hir> Map<'hir> {
345345
let owner = self.tcx.hir_owner(id.owner);
346346
Entry { parent: owner.parent, node: owner.node }
347347
} else {
348-
let owner = self.tcx.hir_owner_items(id.owner);
349-
let item = owner.items[id.local_id].as_ref().unwrap();
350-
Entry { parent: HirId { owner: id.owner, local_id: item.parent }, node: item.node }
348+
let owner = self.tcx.hir_owner_nodes(id.owner);
349+
let node = owner.nodes[id.local_id].as_ref().unwrap();
350+
// FIXME(eddyb) use a single generic type insted of having both
351+
// `Entry` and `ParentedNode`, which are effectively the same.
352+
// Alternatively, rewrite code using `Entry` to use `ParentedNode`.
353+
Entry { parent: HirId { owner: id.owner, local_id: node.parent }, node: node.node }
351354
}
352355
}
353356

@@ -373,7 +376,7 @@ impl<'hir> Map<'hir> {
373376
}
374377

375378
pub fn body(&self, id: BodyId) -> &'hir Body<'hir> {
376-
self.tcx.hir_owner_items(id.hir_id.owner).bodies.get(&id.hir_id.local_id).unwrap()
379+
self.tcx.hir_owner_nodes(id.hir_id.owner).bodies.get(&id.hir_id.local_id).unwrap()
377380
}
378381

379382
pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {

src/librustc/hir/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ use rustc_hir::ItemLocalId;
1818
use rustc_hir::Node;
1919
use rustc_index::vec::IndexVec;
2020

21-
pub struct HirOwner<'tcx> {
21+
pub struct Owner<'tcx> {
2222
parent: HirId,
2323
node: Node<'tcx>,
2424
}
2525

26-
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for HirOwner<'tcx> {
26+
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Owner<'tcx> {
2727
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
28-
let HirOwner { parent, node } = self;
28+
let Owner { parent, node } = self;
2929
hcx.while_hashing_hir_bodies(false, |hcx| {
3030
parent.hash_stable(hcx, hasher);
3131
node.hash_stable(hcx, hasher);
@@ -34,22 +34,22 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for HirOwner<'tcx> {
3434
}
3535

3636
#[derive(Clone)]
37-
pub struct HirItem<'tcx> {
37+
pub struct ParentedNode<'tcx> {
3838
parent: ItemLocalId,
3939
node: Node<'tcx>,
4040
}
4141

42-
pub struct HirOwnerItems<'tcx> {
42+
pub struct OwnerNodes<'tcx> {
4343
hash: Fingerprint,
44-
items: IndexVec<ItemLocalId, Option<HirItem<'tcx>>>,
44+
nodes: IndexVec<ItemLocalId, Option<ParentedNode<'tcx>>>,
4545
bodies: FxHashMap<ItemLocalId, &'tcx Body<'tcx>>,
4646
}
4747

48-
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for HirOwnerItems<'tcx> {
48+
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for OwnerNodes<'tcx> {
4949
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
50-
// We ignore the `items` and `bodies` fields since these refer to information included in
50+
// We ignore the `nodes` and `bodies` fields since these refer to information included in
5151
// `hash` which is hashed in the collector and used for the crate hash.
52-
let HirOwnerItems { hash, items: _, bodies: _ } = *self;
52+
let OwnerNodes { hash, nodes: _, bodies: _ } = *self;
5353
hash.hash_stable(hcx, hasher);
5454
}
5555
}
@@ -79,8 +79,8 @@ pub fn provide(providers: &mut Providers<'_>) {
7979
&tcx.untracked_crate.modules[&module]
8080
};
8181
providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature.unwrap();
82-
providers.hir_owner_items = |tcx, id| {
83-
tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_ref().map(|items| &**items).unwrap()
82+
providers.hir_owner_nodes = |tcx, id| {
83+
tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_ref().map(|nodes| &**nodes).unwrap()
8484
};
8585
map::provide(providers);
8686
}

src/librustc/query/mod.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,28 @@ rustc_queries! {
6464
}
6565

6666
// The items in a module.
67+
//
6768
// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
6869
// Avoid calling this query directly.
6970
query hir_module_items(key: LocalDefId) -> &'tcx hir::ModuleItems {
7071
eval_always
7172
desc { |tcx| "HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) }
7273
}
7374

74-
// An HIR item with a `LocalDefId` that can own other HIR items which do
75-
// not themselves have a `LocalDefId`.
75+
// Gives access to the HIR node for the HIR owner `key`.
76+
//
7677
// This can be conveniently accessed by methods on `tcx.hir()`.
7778
// Avoid calling this query directly.
78-
query hir_owner(key: LocalDefId) -> &'tcx HirOwner<'tcx> {
79+
query hir_owner(key: LocalDefId) -> &'tcx crate::hir::Owner<'tcx> {
7980
eval_always
8081
desc { |tcx| "HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
8182
}
8283

83-
// The HIR items which do not themselves have a `LocalDefId` and are
84-
// owned by another HIR item with a `LocalDefId`.
84+
// Gives access to the HIR nodes and bodies inside the HIR owner `key`.
85+
//
8586
// This can be conveniently accessed by methods on `tcx.hir()`.
8687
// Avoid calling this query directly.
87-
query hir_owner_items(key: LocalDefId) -> &'tcx HirOwnerItems<'tcx> {
88+
query hir_owner_nodes(key: LocalDefId) -> &'tcx crate::hir::OwnerNodes<'tcx> {
8889
eval_always
8990
desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
9091
}

src/librustc/ty/query/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::dep_graph::{self, DepConstructor, DepNode, DepNodeParams};
22
use crate::hir::exports::Export;
33
use crate::hir::map;
4-
use crate::hir::{HirOwner, HirOwnerItems};
54
use crate::infer::canonical::{self, Canonical};
65
use crate::lint::LintLevelMap;
76
use crate::middle::codegen_fn_attrs::CodegenFnAttrs;

src/librustc_incremental/persist/dirty_clean.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ const BASE_FN: &[&str] = &[
5353

5454
/// DepNodes for Hir, which is pretty much everything
5555
const BASE_HIR: &[&str] = &[
56-
// hir_owner and hir_owner_items should be computed for all nodes
56+
// hir_owner and hir_owner_nodes should be computed for all nodes
5757
label_strs::hir_owner,
58-
label_strs::hir_owner_items,
58+
label_strs::hir_owner_nodes,
5959
];
6060

6161
/// `impl` implementation of struct/trait

src/librustc_metadata/rmeta/decoder/cstore_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
140140
cdata.get_deprecation(def_id.index).map(DeprecationEntry::external)
141141
}
142142
item_attrs => { cdata.get_item_attrs(def_id.index, tcx.sess) }
143-
// FIXME(#38501) We've skipped a `read` on the `hir_owner_items` of
143+
// FIXME(#38501) We've skipped a `read` on the `hir_owner_nodes` of
144144
// a `fn` when encoding, so the dep-tracking wouldn't work.
145145
// This is only used by rustdoc anyway, which shouldn't have
146146
// incremental recompilation ever enabled.

src/test/incremental/hashes/call_expressions.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn change_callee_function() {
2525
}
2626

2727
#[cfg(not(cfail1))]
28-
#[rustc_clean(cfg="cfail2", except="hir_owner_items,mir_built,optimized_mir,typeck_tables_of")]
28+
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")]
2929
#[rustc_clean(cfg="cfail3")]
3030
pub fn change_callee_function() {
3131
callee2(1, 2)
@@ -40,7 +40,7 @@ pub fn change_argument_function() {
4040
}
4141

4242
#[cfg(not(cfail1))]
43-
#[rustc_clean(cfg="cfail2", except="hir_owner_items,mir_built,optimized_mir")]
43+
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")]
4444
#[rustc_clean(cfg="cfail3")]
4545
pub fn change_argument_function() {
4646
callee1(1, 3)
@@ -57,8 +57,8 @@ mod change_callee_indirectly_function {
5757

5858
#[rustc_clean(label="hir_owner", cfg="cfail2")]
5959
#[rustc_clean(label="hir_owner", cfg="cfail3")]
60-
#[rustc_dirty(label="hir_owner_items", cfg="cfail2")]
61-
#[rustc_clean(label="hir_owner_items", cfg="cfail3")]
60+
#[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
61+
#[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
6262

6363

6464
pub fn change_callee_indirectly_function() {
@@ -81,7 +81,7 @@ pub fn change_callee_method() {
8181
}
8282

8383
#[cfg(not(cfail1))]
84-
#[rustc_clean(cfg="cfail2", except="hir_owner_items,mir_built,optimized_mir,typeck_tables_of")]
84+
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")]
8585
#[rustc_clean(cfg="cfail3")]
8686
pub fn change_callee_method() {
8787
let s = Struct;
@@ -98,7 +98,7 @@ pub fn change_argument_method() {
9898
}
9999

100100
#[cfg(not(cfail1))]
101-
#[rustc_clean(cfg="cfail2", except="hir_owner_items,mir_built,optimized_mir")]
101+
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")]
102102
#[rustc_clean(cfg="cfail3")]
103103
pub fn change_argument_method() {
104104
let s = Struct;
@@ -115,7 +115,7 @@ pub fn change_ufcs_callee_method() {
115115
}
116116

117117
#[cfg(not(cfail1))]
118-
#[rustc_clean(cfg="cfail2", except="hir_owner_items,mir_built,optimized_mir,typeck_tables_of")]
118+
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")]
119119
#[rustc_clean(cfg="cfail3")]
120120
pub fn change_ufcs_callee_method() {
121121
let s = Struct;
@@ -132,7 +132,7 @@ pub fn change_argument_method_ufcs() {
132132
}
133133

134134
#[cfg(not(cfail1))]
135-
#[rustc_clean(cfg="cfail2", except="hir_owner_items,mir_built,optimized_mir")]
135+
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")]
136136
#[rustc_clean(cfg="cfail3")]
137137
pub fn change_argument_method_ufcs() {
138138
let s = Struct;
@@ -149,9 +149,9 @@ pub fn change_to_ufcs() {
149149
}
150150

151151
#[cfg(not(cfail1))]
152-
#[rustc_clean(cfg="cfail2", except="hir_owner_items,mir_built,optimized_mir,typeck_tables_of")]
152+
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")]
153153
#[rustc_clean(cfg="cfail3")]
154-
// One might think this would be expanded in the hir_owner_items/Mir, but it actually
154+
// One might think this would be expanded in the hir_owner_nodes/Mir, but it actually
155155
// results in slightly different hir_owner/Mir.
156156
pub fn change_to_ufcs() {
157157
let s = Struct;
@@ -171,7 +171,7 @@ pub mod change_ufcs_callee_indirectly {
171171
#[cfg(not(cfail1))]
172172
use super::Struct2 as Struct;
173173

174-
#[rustc_clean(cfg="cfail2", except="hir_owner_items,mir_built,optimized_mir,typeck_tables_of")]
174+
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")]
175175
#[rustc_clean(cfg="cfail3")]
176176

177177

src/test/incremental/hashes/closure_expressions.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn change_closure_body() {
2121
}
2222

2323
#[cfg(not(cfail1))]
24-
#[rustc_clean(cfg="cfail2", except="hir_owner_items")]
24+
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes")]
2525
#[rustc_clean(cfg="cfail3")]
2626
pub fn change_closure_body() {
2727
let _ = || 3u32;
@@ -37,7 +37,7 @@ pub fn add_parameter() {
3737
}
3838

3939
#[cfg(not(cfail1))]
40-
#[rustc_clean(cfg="cfail2", except="hir_owner_items, mir_built, optimized_mir, typeck_tables_of")]
40+
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir, typeck_tables_of")]
4141
#[rustc_clean(cfg="cfail3")]
4242
pub fn add_parameter() {
4343
let x = 0u32;
@@ -53,7 +53,7 @@ pub fn change_parameter_pattern() {
5353
}
5454

5555
#[cfg(not(cfail1))]
56-
#[rustc_clean(cfg="cfail2", except="hir_owner_items, mir_built, typeck_tables_of")]
56+
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, typeck_tables_of")]
5757
#[rustc_clean(cfg="cfail3")]
5858
pub fn change_parameter_pattern() {
5959
let _ = |(x,): (u32,)| x;
@@ -68,7 +68,7 @@ pub fn add_move() {
6868
}
6969

7070
#[cfg(not(cfail1))]
71-
#[rustc_clean(cfg="cfail2", except="hir_owner_items")]
71+
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes")]
7272
#[rustc_clean(cfg="cfail3")]
7373
pub fn add_move() {
7474
let _ = move || 1;
@@ -84,7 +84,7 @@ pub fn add_type_ascription_to_parameter() {
8484
}
8585

8686
#[cfg(not(cfail1))]
87-
#[rustc_clean(cfg = "cfail2", except = "hir_owner_items, typeck_tables_of")]
87+
#[rustc_clean(cfg = "cfail2", except = "hir_owner_nodes, typeck_tables_of")]
8888
#[rustc_clean(cfg = "cfail3")]
8989
pub fn add_type_ascription_to_parameter() {
9090
let closure = |x: u32| x + 1u32;
@@ -101,7 +101,7 @@ pub fn change_parameter_type() {
101101
}
102102

103103
#[cfg(not(cfail1))]
104-
#[rustc_clean(cfg="cfail2", except="hir_owner_items, mir_built, optimized_mir, typeck_tables_of")]
104+
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir, typeck_tables_of")]
105105
#[rustc_clean(cfg="cfail3")]
106106
pub fn change_parameter_type() {
107107
let closure = |x: u16| (x as u64) + 1;

0 commit comments

Comments
 (0)