diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2021-02-01 00:33:38 +0100 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2021-02-15 19:32:29 +0100 |
| commit | 996dc8d5c55a496bfbdc99a936fb6055bcbe2fcd (patch) | |
| tree | 2b92c207effac29986b51278ec11b7d5883cdf0e /compiler/rustc_hir/src | |
| parent | 786a80e9ea7af4909f67207c542eb02727f74756 (diff) | |
| download | rust-996dc8d5c55a496bfbdc99a936fb6055bcbe2fcd.tar.gz rust-996dc8d5c55a496bfbdc99a936fb6055bcbe2fcd.zip | |
Only store a LocalDefId in hir::ForeignItem.
Diffstat (limited to 'compiler/rustc_hir/src')
| -rw-r--r-- | compiler/rustc_hir/src/hir.rs | 33 | ||||
| -rw-r--r-- | compiler/rustc_hir/src/intravisit.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_hir/src/stable_hash_impls.rs | 26 |
3 files changed, 46 insertions, 15 deletions
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index ea23013fa0a..a0950958455 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -2783,7 +2783,14 @@ pub enum AssocItemKind { // so it can fetched later. #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug)] pub struct ForeignItemId { - pub hir_id: HirId, + pub def_id: LocalDefId, +} + +impl ForeignItemId { + pub fn hir_id(&self) -> HirId { + // Items are always HIR owners. + HirId::make_owner(self.def_id) + } } /// A reference from a foreign block to one of its items. This @@ -2801,17 +2808,27 @@ pub struct ForeignItemRef<'hir> { pub vis: Visibility<'hir>, } -#[derive(Debug, HashStable_Generic)] +#[derive(Debug)] pub struct ForeignItem<'hir> { - #[stable_hasher(project(name))] pub ident: Ident, pub attrs: &'hir [Attribute], pub kind: ForeignItemKind<'hir>, - pub hir_id: HirId, + pub def_id: LocalDefId, pub span: Span, pub vis: Visibility<'hir>, } +impl ForeignItem<'_> { + pub fn hir_id(&self) -> HirId { + // Items are always HIR owners. + HirId::make_owner(self.def_id) + } + + pub fn foreign_item_id(&self) -> ForeignItemId { + ForeignItemId { def_id: self.def_id } + } +} + /// An item within an `extern` block. #[derive(Debug, HashStable_Generic)] pub enum ForeignItemKind<'hir> { @@ -2923,9 +2940,9 @@ impl<'hir> Node<'hir> { match self { Node::Item(Item { def_id, .. }) | Node::TraitItem(TraitItem { def_id, .. }) - | Node::ImplItem(ImplItem { def_id, .. }) => Some(HirId::make_owner(*def_id)), - Node::ForeignItem(ForeignItem { hir_id, .. }) - | Node::Field(StructField { hir_id, .. }) + | Node::ImplItem(ImplItem { def_id, .. }) + | Node::ForeignItem(ForeignItem { def_id, .. }) => Some(HirId::make_owner(*def_id)), + Node::Field(StructField { hir_id, .. }) | Node::AnonConst(AnonConst { hir_id, .. }) | Node::Expr(Expr { hir_id, .. }) | Node::Stmt(Stmt { hir_id, .. }) @@ -2960,5 +2977,5 @@ mod size_asserts { rustc_data_structures::static_assert_size!(super::Item<'static>, 200); rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 144); rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 168); - rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 160); + rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 152); } diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index 960a06e0438..c59464a0cb6 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -836,7 +836,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) { } pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItem<'v>) { - visitor.visit_id(foreign_item.hir_id); + visitor.visit_id(foreign_item.hir_id()); visitor.visit_vis(&foreign_item.vis); visitor.visit_ident(foreign_item.ident); diff --git a/compiler/rustc_hir/src/stable_hash_impls.rs b/compiler/rustc_hir/src/stable_hash_impls.rs index a344af1237f..091e1ed9971 100644 --- a/compiler/rustc_hir/src/stable_hash_impls.rs +++ b/compiler/rustc_hir/src/stable_hash_impls.rs @@ -1,8 +1,8 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; use crate::hir::{ - BodyId, Expr, ForeignItemId, ImplItem, ImplItemId, Item, ItemId, Mod, TraitItem, TraitItemId, - Ty, VisibilityKind, + BodyId, Expr, ForeignItem, ForeignItemId, ImplItem, ImplItemId, Item, ItemId, Mod, TraitItem, + TraitItemId, Ty, VisibilityKind, }; use crate::hir_id::{HirId, ItemLocalId}; use rustc_span::def_id::{DefPathHash, LocalDefId}; @@ -62,11 +62,11 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ImplItemId { } impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ForeignItemId { - type KeyType = (DefPathHash, ItemLocalId); + type KeyType = DefPathHash; #[inline] - fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) { - self.hir_id.to_stable_hash_key(hcx) + fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash { + hcx.local_def_path_hash(self.def_id) } } @@ -97,7 +97,7 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ItemId { impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ForeignItemId { fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { - hcx.hash_reference_to_item(self.hir_id, hasher) + hcx.hash_reference_to_item(self.hir_id(), hasher) } } @@ -176,6 +176,20 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItem<'_> { } } +impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ForeignItem<'_> { + fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { + let ForeignItem { def_id: _, ident, ref attrs, ref kind, span, ref vis } = *self; + + hcx.hash_hir_item_like(|hcx| { + ident.name.hash_stable(hcx, hasher); + attrs.hash_stable(hcx, hasher); + kind.hash_stable(hcx, hasher); + span.hash_stable(hcx, hasher); + vis.hash_stable(hcx, hasher); + }); + } +} + impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Item<'_> { fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { let Item { ident, ref attrs, def_id: _, ref kind, ref vis, span } = *self; |
