Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4e16e0f

Browse files
committed
Don't allocate DefDatabase::crate_lang_items if its empty
1 parent 9673915 commit 4e16e0f

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

crates/hir-def/src/attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ fn parse_comma_sep<S>(subtree: &tt::Subtree<S>) -> Vec<SmolStr> {
355355
}
356356

357357
impl AttrsWithOwner {
358-
pub(crate) fn attrs_with_owner(db: &dyn DefDatabase, owner: AttrDefId) -> Self {
358+
pub fn attrs_with_owner(db: &dyn DefDatabase, owner: AttrDefId) -> Self {
359359
Self { attrs: db.attrs(owner), owner }
360360
}
361361

crates/hir-def/src/db.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,6 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDataba
214214
#[salsa::invoke(lang_item::lang_attr_query)]
215215
fn lang_attr(&self, def: AttrDefId) -> Option<LangItem>;
216216

217-
#[salsa::transparent]
218-
#[salsa::invoke(AttrsWithOwner::attrs_with_owner)]
219-
fn attrs_with_owner(&self, def: AttrDefId) -> AttrsWithOwner;
220-
221217
// endregion:attrs
222218

223219
#[salsa::invoke(LangItems::lang_item_query)]
@@ -241,7 +237,7 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDataba
241237
// endregion:visibilities
242238

243239
#[salsa::invoke(LangItems::crate_lang_items_query)]
244-
fn crate_lang_items(&self, krate: CrateId) -> Arc<LangItems>;
240+
fn crate_lang_items(&self, krate: CrateId) -> Option<Arc<LangItems>>;
245241

246242
fn crate_supports_no_std(&self, crate_id: CrateId) -> bool;
247243
}

crates/hir-def/src/lang_item.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ impl LangItems {
8787
}
8888

8989
/// Salsa query. This will look for lang items in a specific crate.
90-
pub(crate) fn crate_lang_items_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<LangItems> {
90+
pub(crate) fn crate_lang_items_query(
91+
db: &dyn DefDatabase,
92+
krate: CrateId,
93+
) -> Option<Arc<LangItems>> {
9194
let _p = profile::span("crate_lang_items_query");
9295

9396
let mut lang_items = LangItems::default();
@@ -150,7 +153,11 @@ impl LangItems {
150153
}
151154
}
152155

153-
Arc::new(lang_items)
156+
if lang_items.items.is_empty() {
157+
None
158+
} else {
159+
Some(Arc::new(lang_items))
160+
}
154161
}
155162

156163
/// Salsa query. Look for a lang item, starting from the specified crate and recursively
@@ -161,9 +168,9 @@ impl LangItems {
161168
item: LangItem,
162169
) -> Option<LangItemTarget> {
163170
let _p = profile::span("lang_item_query");
164-
let lang_items = db.crate_lang_items(start_crate);
165-
let start_crate_target = lang_items.items.get(&item);
166-
if let Some(&target) = start_crate_target {
171+
if let Some(target) =
172+
db.crate_lang_items(start_crate).and_then(|it| it.items.get(&item).copied())
173+
{
167174
return Some(target);
168175
}
169176
db.crate_graph()[start_crate]

crates/hir/src/attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ macro_rules! impl_has_attrs {
3535
impl HasAttrs for $def {
3636
fn attrs(self, db: &dyn HirDatabase) -> AttrsWithOwner {
3737
let def = AttrDefId::$def_id(self.into());
38-
db.attrs_with_owner(def)
38+
AttrsWithOwner::attrs_with_owner(db.upcast(), def)
3939
}
4040
fn attr_id(self) -> AttrDefId {
4141
AttrDefId::$def_id(self.into())

0 commit comments

Comments
 (0)