mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Remove module_lang_items
It isn't used anywhere except in `crate_lang_items`. Remove it to slightly reduce memory usage and simplify the code.
This commit is contained in:
parent
785860bd17
commit
21b68a328c
@ -6,8 +6,8 @@ pub use hir_def::db::{
|
|||||||
FunctionDataQuery, GenericParamsQuery, ImplDataQuery, ImportMapQuery, InternConstQuery,
|
FunctionDataQuery, GenericParamsQuery, ImplDataQuery, ImportMapQuery, InternConstQuery,
|
||||||
InternDatabase, InternDatabaseStorage, InternEnumQuery, InternFunctionQuery, InternImplQuery,
|
InternDatabase, InternDatabaseStorage, InternEnumQuery, InternFunctionQuery, InternImplQuery,
|
||||||
InternStaticQuery, InternStructQuery, InternTraitQuery, InternTypeAliasQuery, InternUnionQuery,
|
InternStaticQuery, InternStructQuery, InternTraitQuery, InternTypeAliasQuery, InternUnionQuery,
|
||||||
ItemTreeQuery, LangItemQuery, ModuleLangItemsQuery, StaticDataQuery, StructDataQuery,
|
ItemTreeQuery, LangItemQuery, StaticDataQuery, StructDataQuery, TraitDataQuery,
|
||||||
TraitDataQuery, TypeAliasDataQuery, UnionDataQuery,
|
TypeAliasDataQuery, UnionDataQuery,
|
||||||
};
|
};
|
||||||
pub use hir_expand::db::{
|
pub use hir_expand::db::{
|
||||||
AstDatabase, AstDatabaseStorage, AstIdMapQuery, InternEagerExpansionQuery, InternMacroQuery,
|
AstDatabase, AstDatabaseStorage, AstIdMapQuery, InternEagerExpansionQuery, InternMacroQuery,
|
||||||
|
@ -16,8 +16,8 @@ use crate::{
|
|||||||
lang_item::{LangItemTarget, LangItems},
|
lang_item::{LangItemTarget, LangItems},
|
||||||
nameres::CrateDefMap,
|
nameres::CrateDefMap,
|
||||||
AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc,
|
AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc,
|
||||||
GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId,
|
GenericDefId, ImplId, ImplLoc, StaticId, StaticLoc, StructId, StructLoc, TraitId, TraitLoc,
|
||||||
TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc,
|
TypeAliasId, TypeAliasLoc, UnionId, UnionLoc,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[salsa::query_group(InternDatabaseStorage)]
|
#[salsa::query_group(InternDatabaseStorage)]
|
||||||
@ -95,9 +95,6 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
|
|||||||
#[salsa::invoke(Attrs::attrs_query)]
|
#[salsa::invoke(Attrs::attrs_query)]
|
||||||
fn attrs(&self, def: AttrDefId) -> Attrs;
|
fn attrs(&self, def: AttrDefId) -> Attrs;
|
||||||
|
|
||||||
#[salsa::invoke(LangItems::module_lang_items_query)]
|
|
||||||
fn module_lang_items(&self, module: ModuleId) -> Option<Arc<LangItems>>;
|
|
||||||
|
|
||||||
#[salsa::invoke(LangItems::crate_lang_items_query)]
|
#[salsa::invoke(LangItems::crate_lang_items_query)]
|
||||||
fn crate_lang_items(&self, krate: CrateId) -> Arc<LangItems>;
|
fn crate_lang_items(&self, krate: CrateId) -> Arc<LangItems>;
|
||||||
|
|
||||||
|
@ -8,8 +8,8 @@ use rustc_hash::FxHashMap;
|
|||||||
use syntax::SmolStr;
|
use syntax::SmolStr;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::DefDatabase, AdtId, AttrDefId, CrateId, EnumId, FunctionId, ImplId, ModuleDefId, ModuleId,
|
db::DefDatabase, AdtId, AttrDefId, CrateId, EnumId, FunctionId, ImplId, ModuleDefId, StaticId,
|
||||||
StaticId, StructId, TraitId,
|
StructId, TraitId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
@ -84,29 +84,36 @@ impl LangItems {
|
|||||||
|
|
||||||
let crate_def_map = db.crate_def_map(krate);
|
let crate_def_map = db.crate_def_map(krate);
|
||||||
|
|
||||||
crate_def_map
|
for (_, module_data) in crate_def_map.modules.iter() {
|
||||||
.modules
|
for impl_def in module_data.scope.impls() {
|
||||||
.iter()
|
lang_items.collect_lang_item(db, impl_def, LangItemTarget::ImplDefId)
|
||||||
.filter_map(|(local_id, _)| db.module_lang_items(ModuleId { krate, local_id }))
|
}
|
||||||
.for_each(|it| lang_items.items.extend(it.items.iter().map(|(k, v)| (k.clone(), *v))));
|
|
||||||
|
for def in module_data.scope.declarations() {
|
||||||
|
match def {
|
||||||
|
ModuleDefId::TraitId(trait_) => {
|
||||||
|
lang_items.collect_lang_item(db, trait_, LangItemTarget::TraitId)
|
||||||
|
}
|
||||||
|
ModuleDefId::AdtId(AdtId::EnumId(e)) => {
|
||||||
|
lang_items.collect_lang_item(db, e, LangItemTarget::EnumId)
|
||||||
|
}
|
||||||
|
ModuleDefId::AdtId(AdtId::StructId(s)) => {
|
||||||
|
lang_items.collect_lang_item(db, s, LangItemTarget::StructId)
|
||||||
|
}
|
||||||
|
ModuleDefId::FunctionId(f) => {
|
||||||
|
lang_items.collect_lang_item(db, f, LangItemTarget::FunctionId)
|
||||||
|
}
|
||||||
|
ModuleDefId::StaticId(s) => {
|
||||||
|
lang_items.collect_lang_item(db, s, LangItemTarget::StaticId)
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Arc::new(lang_items)
|
Arc::new(lang_items)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn module_lang_items_query(
|
|
||||||
db: &dyn DefDatabase,
|
|
||||||
module: ModuleId,
|
|
||||||
) -> Option<Arc<LangItems>> {
|
|
||||||
let _p = profile::span("module_lang_items_query");
|
|
||||||
let mut lang_items = LangItems::default();
|
|
||||||
lang_items.collect_lang_items(db, module);
|
|
||||||
if lang_items.items.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(Arc::new(lang_items))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Salsa query. Look for a lang item, starting from the specified crate and recursively
|
/// Salsa query. Look for a lang item, starting from the specified crate and recursively
|
||||||
/// traversing its dependencies.
|
/// traversing its dependencies.
|
||||||
pub(crate) fn lang_item_query(
|
pub(crate) fn lang_item_query(
|
||||||
@ -126,34 +133,6 @@ impl LangItems {
|
|||||||
.find_map(|dep| db.lang_item(dep.crate_id, item.clone()))
|
.find_map(|dep| db.lang_item(dep.crate_id, item.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_lang_items(&mut self, db: &dyn DefDatabase, module: ModuleId) {
|
|
||||||
// Look for impl targets
|
|
||||||
let def_map = db.crate_def_map(module.krate);
|
|
||||||
let module_data = &def_map[module.local_id];
|
|
||||||
for impl_def in module_data.scope.impls() {
|
|
||||||
self.collect_lang_item(db, impl_def, LangItemTarget::ImplDefId)
|
|
||||||
}
|
|
||||||
|
|
||||||
for def in module_data.scope.declarations() {
|
|
||||||
match def {
|
|
||||||
ModuleDefId::TraitId(trait_) => {
|
|
||||||
self.collect_lang_item(db, trait_, LangItemTarget::TraitId)
|
|
||||||
}
|
|
||||||
ModuleDefId::AdtId(AdtId::EnumId(e)) => {
|
|
||||||
self.collect_lang_item(db, e, LangItemTarget::EnumId)
|
|
||||||
}
|
|
||||||
ModuleDefId::AdtId(AdtId::StructId(s)) => {
|
|
||||||
self.collect_lang_item(db, s, LangItemTarget::StructId)
|
|
||||||
}
|
|
||||||
ModuleDefId::FunctionId(f) => {
|
|
||||||
self.collect_lang_item(db, f, LangItemTarget::FunctionId)
|
|
||||||
}
|
|
||||||
ModuleDefId::StaticId(s) => self.collect_lang_item(db, s, LangItemTarget::StaticId),
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn collect_lang_item<T>(
|
fn collect_lang_item<T>(
|
||||||
&mut self,
|
&mut self,
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
|
@ -163,7 +163,6 @@ impl RootDatabase {
|
|||||||
hir::db::ExprScopesQuery
|
hir::db::ExprScopesQuery
|
||||||
hir::db::GenericParamsQuery
|
hir::db::GenericParamsQuery
|
||||||
hir::db::AttrsQuery
|
hir::db::AttrsQuery
|
||||||
hir::db::ModuleLangItemsQuery
|
|
||||||
hir::db::CrateLangItemsQuery
|
hir::db::CrateLangItemsQuery
|
||||||
hir::db::LangItemQuery
|
hir::db::LangItemQuery
|
||||||
hir::db::ImportMapQuery
|
hir::db::ImportMapQuery
|
||||||
|
Loading…
Reference in New Issue
Block a user