Store lowering outputs per owner.
This commit is contained in:
parent
f9e1de979d
commit
48a339ddbb
13 changed files with 170 additions and 125 deletions
|
@ -662,6 +662,16 @@ pub struct WhereEqPredicate<'hir> {
|
|||
pub rhs_ty: &'hir Ty<'hir>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OwnerInfo<'hir> {
|
||||
pub node: OwnerNode<'hir>,
|
||||
pub attrs: BTreeMap<ItemLocalId, &'hir [Attribute]>,
|
||||
pub bodies: BTreeMap<ItemLocalId, Body<'hir>>,
|
||||
/// Map indicating what traits are in scope for places where this
|
||||
/// is relevant; generated by resolve.
|
||||
pub trait_map: FxHashMap<ItemLocalId, Box<[TraitCandidate]>>,
|
||||
}
|
||||
|
||||
/// The top-level data structure that stores the entire contents of
|
||||
/// the crate currently being compiled.
|
||||
///
|
||||
|
@ -670,40 +680,39 @@ pub struct WhereEqPredicate<'hir> {
|
|||
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
|
||||
#[derive(Debug)]
|
||||
pub struct Crate<'hir> {
|
||||
pub owners: IndexVec<LocalDefId, Option<OwnerNode<'hir>>>,
|
||||
pub bodies: BTreeMap<BodyId, Body<'hir>>,
|
||||
|
||||
/// Map indicating what traits are in scope for places where this
|
||||
/// is relevant; generated by resolve.
|
||||
pub trait_map: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Box<[TraitCandidate]>>>,
|
||||
|
||||
/// Collected attributes from HIR nodes.
|
||||
pub attrs: BTreeMap<HirId, &'hir [Attribute]>,
|
||||
pub owners: IndexVec<LocalDefId, Option<OwnerInfo<'hir>>>,
|
||||
}
|
||||
|
||||
impl Crate<'hir> {
|
||||
pub fn module(&self) -> &'hir Mod<'hir> {
|
||||
if let Some(OwnerNode::Crate(m)) = self.owners[CRATE_DEF_ID] { m } else { panic!() }
|
||||
let i = self.owners[CRATE_DEF_ID].as_ref().unwrap().node;
|
||||
if let OwnerNode::Crate(m) = i { m } else { panic!() }
|
||||
}
|
||||
|
||||
pub fn item(&self, id: ItemId) -> &'hir Item<'hir> {
|
||||
self.owners[id.def_id].as_ref().unwrap().expect_item()
|
||||
self.owners[id.def_id].as_ref().unwrap().node.expect_item()
|
||||
}
|
||||
|
||||
pub fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir> {
|
||||
self.owners[id.def_id].as_ref().unwrap().expect_trait_item()
|
||||
self.owners[id.def_id].as_ref().unwrap().node.expect_trait_item()
|
||||
}
|
||||
|
||||
pub fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir> {
|
||||
self.owners[id.def_id].as_ref().unwrap().expect_impl_item()
|
||||
self.owners[id.def_id].as_ref().unwrap().node.expect_impl_item()
|
||||
}
|
||||
|
||||
pub fn foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir> {
|
||||
self.owners[id.def_id].as_ref().unwrap().expect_foreign_item()
|
||||
self.owners[id.def_id].as_ref().unwrap().node.expect_foreign_item()
|
||||
}
|
||||
|
||||
pub fn body(&self, id: BodyId) -> &Body<'hir> {
|
||||
&self.bodies[&id]
|
||||
let HirId { owner, local_id } = id.hir_id;
|
||||
&self.owners[owner].as_ref().unwrap().bodies[&local_id]
|
||||
}
|
||||
|
||||
pub fn attrs(&self, id: HirId) -> &'hir [Attribute] {
|
||||
let HirId { owner, local_id } = id;
|
||||
&self.owners[owner].as_ref().unwrap().attrs.get(&local_id).map(|la| *la).unwrap_or(&[])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue