diff --git a/crates/hir-def/src/attr.rs b/crates/hir-def/src/attr.rs index cc59e780938..6927a017b18 100644 --- a/crates/hir-def/src/attr.rs +++ b/crates/hir-def/src/attr.rs @@ -377,7 +377,11 @@ fn parse_comma_sep(subtree: &tt::Subtree) -> Vec { } impl AttrsWithOwner { - pub(crate) fn attrs_query(db: &dyn DefDatabase, def: AttrDefId) -> Self { + pub(crate) fn attrs_with_owner(db: &dyn DefDatabase, owner: AttrDefId) -> Self { + Self { attrs: db.attrs(owner), owner } + } + + pub(crate) fn attrs_query(db: &dyn DefDatabase, def: AttrDefId) -> Attrs { let _p = profile::span("attrs_query"); // FIXME: this should use `Trace` to avoid duplication in `source_map` below let raw_attrs = match def { @@ -412,13 +416,10 @@ pub(crate) fn attrs_query(db: &dyn DefDatabase, def: AttrDefId) -> Self { } } AttrDefId::FieldId(it) => { - return Self { attrs: db.fields_attrs(it.parent)[it.local_id].clone(), owner: def }; + return db.fields_attrs(it.parent)[it.local_id].clone(); } AttrDefId::EnumVariantId(it) => { - return Self { - attrs: db.variants_attrs(it.parent)[it.local_id].clone(), - owner: def, - }; + return db.variants_attrs(it.parent)[it.local_id].clone(); } AttrDefId::AdtId(it) => match it { AdtId::StructId(it) => attrs_from_item_tree(it.lookup(db).id, db), @@ -461,7 +462,7 @@ pub(crate) fn attrs_query(db: &dyn DefDatabase, def: AttrDefId) -> Self { }; let attrs = raw_attrs.filter(db.upcast(), def.krate(db)); - Self { attrs: Attrs(attrs), owner: def } + Attrs(attrs) } pub fn source_map(&self, db: &dyn DefDatabase) -> AttrSourceMap { diff --git a/crates/hir-def/src/db.rs b/crates/hir-def/src/db.rs index 2dfe4b62648..66e8b482eb2 100644 --- a/crates/hir-def/src/db.rs +++ b/crates/hir-def/src/db.rs @@ -98,6 +98,8 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast Option>; + // region:data + #[salsa::invoke(StructData::struct_data_query)] fn struct_data(&self, id: StructId) -> Arc; @@ -153,6 +155,8 @@ fn struct_data_with_diagnostics(&self, id: StructId) #[salsa::invoke(ProcMacroData::proc_macro_data_query)] fn proc_macro_data(&self, makro: ProcMacroId) -> Arc; + // endregion:data + #[salsa::invoke(Body::body_with_source_map_query)] fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc, Arc); @@ -165,6 +169,8 @@ fn struct_data_with_diagnostics(&self, id: StructId) #[salsa::invoke(GenericParams::generic_params_query)] fn generic_params(&self, def: GenericDefId) -> Interned; + // region:attrs + #[salsa::invoke(Attrs::variants_attrs_query)] fn variants_attrs(&self, def: EnumId) -> Arc>; @@ -184,7 +190,13 @@ fn fields_attrs_source_map( ) -> Arc, AstPtr>>>; #[salsa::invoke(AttrsWithOwner::attrs_query)] - fn attrs(&self, def: AttrDefId) -> AttrsWithOwner; + fn attrs(&self, def: AttrDefId) -> Attrs; + + #[salsa::transparent] + #[salsa::invoke(AttrsWithOwner::attrs_with_owner)] + fn attrs_with_owner(&self, def: AttrDefId) -> AttrsWithOwner; + + // endregion:attrs #[salsa::invoke(LangItems::crate_lang_items_query)] fn crate_lang_items(&self, krate: CrateId) -> Arc; diff --git a/crates/hir-expand/src/attrs.rs b/crates/hir-expand/src/attrs.rs index 8d1e88725ec..7a61ca4f4d3 100644 --- a/crates/hir-expand/src/attrs.rs +++ b/crates/hir-expand/src/attrs.rs @@ -21,6 +21,7 @@ /// Syntactical attributes, without filtering of `cfg_attr`s. #[derive(Default, Debug, Clone, PartialEq, Eq)] pub struct RawAttrs { + // FIXME: Make this a ThinArc entries: Option>, } diff --git a/crates/hir/src/attrs.rs b/crates/hir/src/attrs.rs index db0b84ef088..d025aa8f5a4 100644 --- a/crates/hir/src/attrs.rs +++ b/crates/hir/src/attrs.rs @@ -41,7 +41,7 @@ macro_rules! impl_has_attrs { impl HasAttrs for $def { fn attrs(self, db: &dyn HirDatabase) -> AttrsWithOwner { let def = AttrDefId::$def_id(self.into()); - db.attrs(def) + db.attrs_with_owner(def) } fn docs(self, db: &dyn HirDatabase) -> Option { let def = AttrDefId::$def_id(self.into());