From 95aa7e46fc69b5279a1af74dfa7008396a4455a5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 30 Jan 2019 22:18:17 +0300 Subject: move item_map_query --- crates/ra_hir/src/db.rs | 2 +- crates/ra_hir/src/nameres.rs | 29 ++++++++++++++++++++++++++--- crates/ra_hir/src/query_definitions.rs | 33 ++------------------------------- 3 files changed, 29 insertions(+), 35 deletions(-) diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 70d9de212..e7c5d1436 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -67,7 +67,7 @@ pub trait HirDatabase: SourceDatabase + AsRef { #[salsa::invoke(crate::nameres::lower::LoweredModule::lower_module_source_map_query)] fn lower_module_source_map(&self, module: Module) -> Arc; - #[salsa::invoke(query_definitions::item_map)] + #[salsa::invoke(crate::nameres::ItemMap::item_map_query)] fn item_map(&self, crate_id: CrateId) -> Arc; #[salsa::invoke(crate::module_tree::ModuleTree::module_tree_query)] diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 97ce6c946..d06cd5c69 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -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 PerNs { } } -pub(crate) struct Resolver<'a, DB> { +struct Resolver<'a, DB> { db: &'a DB, input: &'a FxHashMap>, 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>, krate: CrateId, @@ -331,6 +331,29 @@ enum ReachedFixedPoint { } impl ItemMap { + pub(crate) fn item_map_query(db: &impl HirDatabase, crate_id: CrateId) -> Arc { + 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::>(); + + 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, diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs index bf9ac0dfb..6724649e1 100644 --- a/crates/ra_hir/src/query_definitions.rs +++ b/crates/ra_hir/src/query_definitions.rs @@ -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 { @@ -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 { - 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::>(); - - let resolver = Resolver::new(db, &input, crate_id); - let res = resolver.resolve(); - let elapsed = start.elapsed(); - log::info!("item_map: {:?}", elapsed); - Arc::new(res) -} -- cgit v1.2.3