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

Make encode_attrs use queries instead of accessing the HIR #105496

Closed
Closed
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 compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,8 +1127,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
let mut is_public: Option<bool> = None;

let mut attrs = tcx
.hir()
.attrs(tcx.hir().local_def_id_to_hir_id(def_id))
.opt_local_def_id_to_hir_id(def_id)
.map_or(Default::default(), |hir_id| tcx.hir().attrs(hir_id))
.iter()
.filter(move |attr| should_encode_attr(tcx, attr, def_id, &mut is_public));

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ pub fn provide(providers: &mut Providers) {
let node = owner.node();
Some(Owner { node, hash_without_bodies: owner.nodes.hash_without_bodies })
};
providers.local_def_id_to_hir_id = |tcx, id| {
providers.opt_local_def_id_to_hir_id = |tcx, id| {
let owner = tcx.hir_crate(()).owners[id].map(|_| ());
match owner {
Some(match owner {
MaybeOwner::Owner(_) => HirId::make_owner(id),
MaybeOwner::Phantom => bug!("No HirId for {:?}", id),
MaybeOwner::NonOwner(hir_id) => hir_id,
}
})
};
providers.hir_owner_nodes = |tcx, id| tcx.hir_crate(()).owners[id.def_id].map(|i| &i.nodes);
providers.hir_owner_parent = |tcx, id| {
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ rustc_queries! {
desc { |tcx| "getting HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
}

/// Gives access to the HIR ID for the given `LocalDefId` owner `key`.
/// Gives access to the HIR ID for the given `LocalDefId` owner `key` if any.
///
/// This can be conveniently accessed by methods on `tcx.hir()`.
/// Avoid calling this query directly.
query local_def_id_to_hir_id(key: LocalDefId) -> hir::HirId {
/// Definitions that were generated with no HIR, would be feeded to return `None`.
query opt_local_def_id_to_hir_id(key: LocalDefId) -> Option<hir::HirId>{
desc { |tcx| "getting HIR ID of `{}`", tcx.def_path_str(key.to_def_id()) }
}

Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2359,6 +2359,10 @@ impl<'tcx> TyCtxt<'tcx> {
})
)
}

pub fn local_def_id_to_hir_id(self, local_def_id: LocalDefId) -> HirId {
self.opt_local_def_id_to_hir_id(local_def_id).unwrap()
}
}

impl<'tcx> TyCtxtAt<'tcx> {
Expand Down