move item_map_query

This commit is contained in:
Aleksey Kladov 2019-01-30 22:18:17 +03:00
parent b704ce803b
commit 95aa7e46fc
3 changed files with 29 additions and 35 deletions

View file

@ -67,7 +67,7 @@ pub trait HirDatabase: SourceDatabase + AsRef<HirInterner> {
#[salsa::invoke(crate::nameres::lower::LoweredModule::lower_module_source_map_query)]
fn lower_module_source_map(&self, module: Module) -> Arc<ImportSourceMap>;
#[salsa::invoke(query_definitions::item_map)]
#[salsa::invoke(crate::nameres::ItemMap::item_map_query)]
fn item_map(&self, crate_id: CrateId) -> Arc<ItemMap>;
#[salsa::invoke(crate::module_tree::ModuleTree::module_tree_query)]

View file

@ -16,7 +16,7 @@
//! structure itself is modified.
pub(crate) mod lower;
use std::sync::Arc;
use std::{time, sync::Arc};
use ra_db::CrateId;
use ra_arena::map::ArenaMap;
@ -156,7 +156,7 @@ impl<T> PerNs<T> {
}
}
pub(crate) struct Resolver<'a, DB> {
struct Resolver<'a, DB> {
db: &'a DB,
input: &'a FxHashMap<ModuleId, Arc<LoweredModule>>,
krate: CrateId,
@ -169,7 +169,7 @@ impl<'a, DB> Resolver<'a, DB>
where
DB: HirDatabase,
{
pub(crate) fn new(
fn new(
db: &'a DB,
input: &'a FxHashMap<ModuleId, Arc<LoweredModule>>,
krate: CrateId,
@ -331,6 +331,29 @@ enum ReachedFixedPoint {
}
impl ItemMap {
pub(crate) fn item_map_query(db: &impl HirDatabase, crate_id: CrateId) -> Arc<ItemMap> {
let start = time::Instant::now();
let module_tree = db.module_tree(crate_id);
let input = module_tree
.modules()
.map(|module_id| {
(
module_id,
db.lower_module_module(Module {
krate: crate_id,
module_id,
}),
)
})
.collect::<FxHashMap<_, _>>();
let resolver = Resolver::new(db, &input, crate_id);
let res = resolver.resolve();
let elapsed = start.elapsed();
log::info!("item_map: {:?}", elapsed);
Arc::new(res)
}
pub(crate) fn resolve_path(
&self,
db: &impl HirDatabase,

View file

@ -1,17 +1,11 @@
use std::{
sync::Arc,
time::Instant,
};
use std::sync::Arc;
use rustc_hash::FxHashMap;
use ra_syntax::{SyntaxNode, TreeArc};
use ra_db::{CrateId};
use crate::{
SourceFileItems, SourceItemId, HirFileId,
Function, FnScopes, Module,
Function, FnScopes,
db::HirDatabase,
nameres::{ItemMap, Resolver},
};
pub(super) fn fn_scopes(db: &impl HirDatabase, func: Function) -> Arc<FnScopes> {
@ -35,26 +29,3 @@ pub(super) fn file_item(
.to_node(&source_file)
.to_owned()
}
pub(super) fn item_map(db: &impl HirDatabase, crate_id: CrateId) -> Arc<ItemMap> {
let start = Instant::now();
let module_tree = db.module_tree(crate_id);
let input = module_tree
.modules()
.map(|module_id| {
(
module_id,
db.lower_module_module(Module {
krate: crate_id,
module_id,
}),
)
})
.collect::<FxHashMap<_, _>>();
let resolver = Resolver::new(db, &input, crate_id);
let res = resolver.resolve();
let elapsed = start.elapsed();
log::info!("item_map: {:?}", elapsed);
Arc::new(res)
}