Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hir: replace "items" terminology with "nodes" where appropriate. #70092

Merged
merged 2 commits into from
Mar 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustc/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ macro_rules! arena_types {
// HIR query types
[few] indexed_hir: rustc::hir::map::IndexedHir<$tcx>,
[few] hir_definitions: rustc::hir::map::definitions::Definitions,
[] hir_owner: rustc::hir::HirOwner<$tcx>,
[] hir_owner_items: rustc::hir::HirOwnerItems<$tcx>,
[] hir_owner: rustc::hir::Owner<$tcx>,
[] hir_owner_nodes: rustc::hir::OwnerNodes<$tcx>,
], $tcx);
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ impl DepGraph {
// bug that must be fixed before removing this.
match dep_dep_node.kind {
DepKind::hir_owner
| DepKind::hir_owner_items
| DepKind::hir_owner_nodes
| DepKind::CrateMetadata => {
if let Some(def_id) = dep_dep_node.extract_def_id(tcx) {
if def_id_corresponds_to_hir_dep_node(tcx, def_id) {
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/hir/map/collector.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::arena::Arena;
use crate::hir::map::definitions::{self, DefPathHash};
use crate::hir::map::{Entry, HirOwnerData, Map};
use crate::hir::{HirItem, HirOwner, HirOwnerItems};
use crate::hir::{Owner, OwnerNodes, ParentedNode};
use crate::ich::StableHashingContext;
use crate::middle::cstore::CrateStore;
use rustc_data_structures::fingerprint::Fingerprint;
Expand Down Expand Up @@ -203,30 +203,30 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
let data = &mut self.map[id.owner];

if data.with_bodies.is_none() {
data.with_bodies = Some(arena.alloc(HirOwnerItems {
data.with_bodies = Some(arena.alloc(OwnerNodes {
hash,
items: IndexVec::new(),
nodes: IndexVec::new(),
bodies: FxHashMap::default(),
}));
}

let items = data.with_bodies.as_mut().unwrap();
let nodes = data.with_bodies.as_mut().unwrap();

if i == 0 {
// Overwrite the dummy hash with the real HIR owner hash.
items.hash = hash;
nodes.hash = hash;

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

data.signature =
Some(self.arena.alloc(HirOwner { parent: entry.parent, node: entry.node }));
Some(self.arena.alloc(Owner { parent: entry.parent, node: entry.node }));
} else {
assert_eq!(entry.parent.owner, id.owner);
insert_vec_map(
&mut items.items,
&mut nodes.nodes,
id.local_id,
HirItem { parent: entry.parent.local_id, node: entry.node },
ParentedNode { parent: entry.parent.local_id, node: entry.node },
);
}
}
Expand Down
17 changes: 10 additions & 7 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub use self::definitions::{
DefKey, DefPath, DefPathData, DefPathHash, Definitions, DisambiguatedDefPathData,
};

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

pub(super) struct HirOwnerData<'hir> {
pub(super) signature: Option<&'hir HirOwner<'hir>>,
pub(super) with_bodies: Option<&'hir mut HirOwnerItems<'hir>>,
pub(super) signature: Option<&'hir Owner<'hir>>,
pub(super) with_bodies: Option<&'hir mut OwnerNodes<'hir>>,
}

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

Expand All @@ -373,7 +376,7 @@ impl<'hir> Map<'hir> {
}

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

pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
Expand Down
22 changes: 11 additions & 11 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ use rustc_hir::ItemLocalId;
use rustc_hir::Node;
use rustc_index::vec::IndexVec;

pub struct HirOwner<'tcx> {
pub struct Owner<'tcx> {
parent: HirId,
node: Node<'tcx>,
}

impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for HirOwner<'tcx> {
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Owner<'tcx> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let HirOwner { parent, node } = self;
let Owner { parent, node } = self;
hcx.while_hashing_hir_bodies(false, |hcx| {
parent.hash_stable(hcx, hasher);
node.hash_stable(hcx, hasher);
Expand All @@ -34,22 +34,22 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for HirOwner<'tcx> {
}

#[derive(Clone)]
pub struct HirItem<'tcx> {
pub struct ParentedNode<'tcx> {
parent: ItemLocalId,
node: Node<'tcx>,
}

pub struct HirOwnerItems<'tcx> {
pub struct OwnerNodes<'tcx> {
hash: Fingerprint,
items: IndexVec<ItemLocalId, Option<HirItem<'tcx>>>,
nodes: IndexVec<ItemLocalId, Option<ParentedNode<'tcx>>>,
bodies: FxHashMap<ItemLocalId, &'tcx Body<'tcx>>,
}

impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for HirOwnerItems<'tcx> {
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for OwnerNodes<'tcx> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
// We ignore the `items` and `bodies` fields since these refer to information included in
// We ignore the `nodes` and `bodies` fields since these refer to information included in
// `hash` which is hashed in the collector and used for the crate hash.
let HirOwnerItems { hash, items: _, bodies: _ } = *self;
let OwnerNodes { hash, nodes: _, bodies: _ } = *self;
hash.hash_stable(hcx, hasher);
}
}
Expand Down Expand Up @@ -79,8 +79,8 @@ pub fn provide(providers: &mut Providers<'_>) {
&tcx.untracked_crate.modules[&module]
};
providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature.unwrap();
providers.hir_owner_items = |tcx, id| {
tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_ref().map(|items| &**items).unwrap()
providers.hir_owner_nodes = |tcx, id| {
tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_ref().map(|nodes| &**nodes).unwrap()
};
map::provide(providers);
}
13 changes: 7 additions & 6 deletions src/librustc/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,28 @@ rustc_queries! {
}

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

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

// The HIR items which do not themselves have a `LocalDefId` and are
// owned by another HIR item with a `LocalDefId`.
// Gives access to the HIR nodes and bodies inside the HIR owner `key`.
//
// This can be conveniently accessed by methods on `tcx.hir()`.
// Avoid calling this query directly.
query hir_owner_items(key: LocalDefId) -> &'tcx HirOwnerItems<'tcx> {
query hir_owner_nodes(key: LocalDefId) -> &'tcx crate::hir::OwnerNodes<'tcx> {
eval_always
desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
}
Expand Down
1 change: 0 additions & 1 deletion src/librustc/ty/query/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::dep_graph::{self, DepConstructor, DepNode, DepNodeParams};
use crate::hir::exports::Export;
use crate::hir::map;
use crate::hir::{HirOwner, HirOwnerItems};
use crate::infer::canonical::{self, Canonical};
use crate::lint::LintLevelMap;
use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_incremental/persist/dirty_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ const BASE_FN: &[&str] = &[

/// DepNodes for Hir, which is pretty much everything
const BASE_HIR: &[&str] = &[
// hir_owner and hir_owner_items should be computed for all nodes
// hir_owner and hir_owner_nodes should be computed for all nodes
label_strs::hir_owner,
label_strs::hir_owner_items,
label_strs::hir_owner_nodes,
];

/// `impl` implementation of struct/trait
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
cdata.get_deprecation(def_id.index).map(DeprecationEntry::external)
}
item_attrs => { cdata.get_item_attrs(def_id.index, tcx.sess) }
// FIXME(#38501) We've skipped a `read` on the `hir_owner_items` of
// FIXME(#38501) We've skipped a `read` on the `hir_owner_nodes` of
// a `fn` when encoding, so the dep-tracking wouldn't work.
// This is only used by rustdoc anyway, which shouldn't have
// incremental recompilation ever enabled.
Expand Down
22 changes: 11 additions & 11 deletions src/test/incremental/hashes/call_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn change_callee_function() {
}

#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="hir_owner_items,mir_built,optimized_mir,typeck_tables_of")]
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")]
#[rustc_clean(cfg="cfail3")]
pub fn change_callee_function() {
callee2(1, 2)
Expand All @@ -40,7 +40,7 @@ pub fn change_argument_function() {
}

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

#[rustc_clean(label="hir_owner", cfg="cfail2")]
#[rustc_clean(label="hir_owner", cfg="cfail3")]
#[rustc_dirty(label="hir_owner_items", cfg="cfail2")]
#[rustc_clean(label="hir_owner_items", cfg="cfail3")]
#[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
#[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]


pub fn change_callee_indirectly_function() {
Expand All @@ -81,7 +81,7 @@ pub fn change_callee_method() {
}

#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="hir_owner_items,mir_built,optimized_mir,typeck_tables_of")]
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")]
#[rustc_clean(cfg="cfail3")]
pub fn change_callee_method() {
let s = Struct;
Expand All @@ -98,7 +98,7 @@ pub fn change_argument_method() {
}

#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="hir_owner_items,mir_built,optimized_mir")]
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")]
#[rustc_clean(cfg="cfail3")]
pub fn change_argument_method() {
let s = Struct;
Expand All @@ -115,7 +115,7 @@ pub fn change_ufcs_callee_method() {
}

#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="hir_owner_items,mir_built,optimized_mir,typeck_tables_of")]
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")]
#[rustc_clean(cfg="cfail3")]
pub fn change_ufcs_callee_method() {
let s = Struct;
Expand All @@ -132,7 +132,7 @@ pub fn change_argument_method_ufcs() {
}

#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="hir_owner_items,mir_built,optimized_mir")]
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")]
#[rustc_clean(cfg="cfail3")]
pub fn change_argument_method_ufcs() {
let s = Struct;
Expand All @@ -149,9 +149,9 @@ pub fn change_to_ufcs() {
}

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

#[rustc_clean(cfg="cfail2", except="hir_owner_items,mir_built,optimized_mir,typeck_tables_of")]
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")]
#[rustc_clean(cfg="cfail3")]


Expand Down
12 changes: 6 additions & 6 deletions src/test/incremental/hashes/closure_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn change_closure_body() {
}

#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="hir_owner_items")]
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes")]
#[rustc_clean(cfg="cfail3")]
pub fn change_closure_body() {
let _ = || 3u32;
Expand All @@ -37,7 +37,7 @@ pub fn add_parameter() {
}

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

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

#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="hir_owner_items")]
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes")]
#[rustc_clean(cfg="cfail3")]
pub fn add_move() {
let _ = move || 1;
Expand All @@ -84,7 +84,7 @@ pub fn add_type_ascription_to_parameter() {
}

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

#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="hir_owner_items, mir_built, optimized_mir, typeck_tables_of")]
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir, typeck_tables_of")]
#[rustc_clean(cfg="cfail3")]
pub fn change_parameter_type() {
let closure = |x: u16| (x as u64) + 1;
Expand Down
Loading