aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-12-21 17:45:46 +0000
committerAleksey Kladov <[email protected]>2019-12-21 17:46:21 +0000
commitd4b135f38c8c0050768c50e62043ddca5f09079a (patch)
tree5684bfee4f4614d503ed84ad3c540440c232b4bf
parent6d8a2ec3dd350541d7c0e5aa08795a42c4dbd8f8 (diff)
Optimize and profile
-rw-r--r--Cargo.lock1
-rw-r--r--crates/ra_hir/Cargo.toml1
-rw-r--r--crates/ra_hir/src/from_source.rs4
-rw-r--r--crates/ra_hir/src/source_binder.rs3
-rw-r--r--crates/ra_hir_def/src/body.rs2
-rw-r--r--crates/ra_ide/src/inlay_hints.rs11
6 files changed, 19 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 60b6da8eb..55afcda7b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -948,6 +948,7 @@ dependencies = [
948 "ra_hir_def 0.1.0", 948 "ra_hir_def 0.1.0",
949 "ra_hir_expand 0.1.0", 949 "ra_hir_expand 0.1.0",
950 "ra_hir_ty 0.1.0", 950 "ra_hir_ty 0.1.0",
951 "ra_prof 0.1.0",
951 "ra_syntax 0.1.0", 952 "ra_syntax 0.1.0",
952 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 953 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
953] 954]
diff --git a/crates/ra_hir/Cargo.toml b/crates/ra_hir/Cargo.toml
index 6ca9cc2e7..7dc31ad3c 100644
--- a/crates/ra_hir/Cargo.toml
+++ b/crates/ra_hir/Cargo.toml
@@ -14,6 +14,7 @@ either = "1.5"
14 14
15ra_syntax = { path = "../ra_syntax" } 15ra_syntax = { path = "../ra_syntax" }
16ra_db = { path = "../ra_db" } 16ra_db = { path = "../ra_db" }
17ra_prof = { path = "../ra_prof" }
17hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" } 18hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" }
18hir_def = { path = "../ra_hir_def", package = "ra_hir_def" } 19hir_def = { path = "../ra_hir_def", package = "ra_hir_def" }
19hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" } 20hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" }
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs
index 42ca55fe7..ebd9ee2a8 100644
--- a/crates/ra_hir/src/from_source.rs
+++ b/crates/ra_hir/src/from_source.rs
@@ -7,6 +7,7 @@ use hir_def::{
7 StaticId, StructId, TraitId, TypeAliasId, UnionId, VariantId, 7 StaticId, StructId, TraitId, TypeAliasId, UnionId, VariantId,
8}; 8};
9use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind}; 9use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind};
10use ra_prof::profile;
10use ra_syntax::{ 11use ra_syntax::{
11 ast::{self, AstNode, NameOwner}, 12 ast::{self, AstNode, NameOwner},
12 match_ast, SyntaxNode, 13 match_ast, SyntaxNode,
@@ -169,6 +170,7 @@ impl TypeParam {
169 170
170impl Module { 171impl Module {
171 pub fn from_declaration(db: &impl DefDatabase, src: InFile<ast::Module>) -> Option<Self> { 172 pub fn from_declaration(db: &impl DefDatabase, src: InFile<ast::Module>) -> Option<Self> {
173 let _p = profile("Module::from_declaration");
172 let parent_declaration = src.value.syntax().ancestors().skip(1).find_map(ast::Module::cast); 174 let parent_declaration = src.value.syntax().ancestors().skip(1).find_map(ast::Module::cast);
173 175
174 let parent_module = match parent_declaration { 176 let parent_module = match parent_declaration {
@@ -191,6 +193,7 @@ impl Module {
191 } 193 }
192 194
193 pub fn from_definition(db: &impl DefDatabase, src: InFile<ModuleSource>) -> Option<Self> { 195 pub fn from_definition(db: &impl DefDatabase, src: InFile<ModuleSource>) -> Option<Self> {
196 let _p = profile("Module::from_definition");
194 match src.value { 197 match src.value {
195 ModuleSource::Module(ref module) => { 198 ModuleSource::Module(ref module) => {
196 assert!(!module.has_semi()); 199 assert!(!module.has_semi());
@@ -214,6 +217,7 @@ impl Module {
214} 217}
215 218
216fn analyze_container(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> DynMap { 219fn analyze_container(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> DynMap {
220 let _p = profile("analyze_container");
217 return child_by_source(db, src).unwrap_or_default(); 221 return child_by_source(db, src).unwrap_or_default();
218 222
219 fn child_by_source(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> Option<DynMap> { 223 fn child_by_source(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> Option<DynMap> {
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index b60a6b87e..85b378483 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -26,6 +26,7 @@ use hir_ty::{
26 method_resolution::{self, implements_trait}, 26 method_resolution::{self, implements_trait},
27 Canonical, InEnvironment, InferenceResult, TraitEnvironment, Ty, 27 Canonical, InEnvironment, InferenceResult, TraitEnvironment, Ty,
28}; 28};
29use ra_prof::profile;
29use ra_syntax::{ 30use ra_syntax::{
30 ast::{self, AstNode}, 31 ast::{self, AstNode},
31 match_ast, AstPtr, 32 match_ast, AstPtr,
@@ -83,6 +84,7 @@ fn def_with_body_from_child_node(
83 db: &impl HirDatabase, 84 db: &impl HirDatabase,
84 child: InFile<&SyntaxNode>, 85 child: InFile<&SyntaxNode>,
85) -> Option<DefWithBody> { 86) -> Option<DefWithBody> {
87 let _p = profile("def_with_body_from_child_node");
86 child.cloned().ancestors_with_macros(db).find_map(|node| { 88 child.cloned().ancestors_with_macros(db).find_map(|node| {
87 let n = &node.value; 89 let n = &node.value;
88 match_ast! { 90 match_ast! {
@@ -169,6 +171,7 @@ impl SourceAnalyzer {
169 node: InFile<&SyntaxNode>, 171 node: InFile<&SyntaxNode>,
170 offset: Option<TextUnit>, 172 offset: Option<TextUnit>,
171 ) -> SourceAnalyzer { 173 ) -> SourceAnalyzer {
174 let _p = profile("SourceAnalyzer::new");
172 let def_with_body = def_with_body_from_child_node(db, node); 175 let def_with_body = def_with_body_from_child_node(db, node);
173 if let Some(def) = def_with_body { 176 if let Some(def) = def_with_body {
174 let (_body, source_map) = db.body_with_source_map(def.into()); 177 let (_body, source_map) = db.body_with_source_map(def.into());
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index 445d215b7..148ff007e 100644
--- a/crates/ra_hir_def/src/body.rs
+++ b/crates/ra_hir_def/src/body.rs
@@ -11,6 +11,7 @@ use hir_expand::{
11 ast_id_map::AstIdMap, hygiene::Hygiene, AstId, HirFileId, InFile, MacroCallKind, MacroDefId, 11 ast_id_map::AstIdMap, hygiene::Hygiene, AstId, HirFileId, InFile, MacroCallKind, MacroDefId,
12}; 12};
13use ra_arena::{map::ArenaMap, Arena}; 13use ra_arena::{map::ArenaMap, Arena};
14use ra_prof::profile;
14use ra_syntax::{ast, AstNode, AstPtr}; 15use ra_syntax::{ast, AstNode, AstPtr};
15use rustc_hash::FxHashMap; 16use rustc_hash::FxHashMap;
16 17
@@ -168,6 +169,7 @@ impl Body {
168 db: &impl DefDatabase, 169 db: &impl DefDatabase,
169 def: DefWithBodyId, 170 def: DefWithBodyId,
170 ) -> (Arc<Body>, Arc<BodySourceMap>) { 171 ) -> (Arc<Body>, Arc<BodySourceMap>) {
172 let _p = profile("body_with_source_map_query");
171 let mut params = None; 173 let mut params = None;
172 174
173 let (file_id, module, body) = match def { 175 let (file_id, module, body) = match def {
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs
index 3154df457..c5e406977 100644
--- a/crates/ra_ide/src/inlay_hints.rs
+++ b/crates/ra_ide/src/inlay_hints.rs
@@ -1,12 +1,15 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use crate::{db::RootDatabase, FileId};
4use hir::{HirDisplay, SourceAnalyzer}; 3use hir::{HirDisplay, SourceAnalyzer};
4use once_cell::unsync::Lazy;
5use ra_prof::profile;
5use ra_syntax::{ 6use ra_syntax::{
6 ast::{self, AstNode, TypeAscriptionOwner}, 7 ast::{self, AstNode, TypeAscriptionOwner},
7 match_ast, SmolStr, SourceFile, SyntaxKind, SyntaxNode, TextRange, 8 match_ast, SmolStr, SourceFile, SyntaxKind, SyntaxNode, TextRange,
8}; 9};
9 10
11use crate::{db::RootDatabase, FileId};
12
10#[derive(Debug, PartialEq, Eq)] 13#[derive(Debug, PartialEq, Eq)]
11pub enum InlayKind { 14pub enum InlayKind {
12 TypeHint, 15 TypeHint,
@@ -27,7 +30,7 @@ pub(crate) fn inlay_hints(
27) -> Vec<InlayHint> { 30) -> Vec<InlayHint> {
28 file.syntax() 31 file.syntax()
29 .descendants() 32 .descendants()
30 .map(|node| get_inlay_hints(db, file_id, &node, max_inlay_hint_length).unwrap_or_default()) 33 .flat_map(|node| get_inlay_hints(db, file_id, &node, max_inlay_hint_length))
31 .flatten() 34 .flatten()
32 .collect() 35 .collect()
33} 36}
@@ -38,7 +41,9 @@ fn get_inlay_hints(
38 node: &SyntaxNode, 41 node: &SyntaxNode,
39 max_inlay_hint_length: Option<usize>, 42 max_inlay_hint_length: Option<usize>,
40) -> Option<Vec<InlayHint>> { 43) -> Option<Vec<InlayHint>> {
41 let analyzer = SourceAnalyzer::new(db, hir::InFile::new(file_id.into(), node), None); 44 let _p = profile("get_inlay_hints");
45 let analyzer =
46 Lazy::new(|| SourceAnalyzer::new(db, hir::InFile::new(file_id.into(), node), None));
42 match_ast! { 47 match_ast! {
43 match node { 48 match node {
44 ast::LetStmt(it) => { 49 ast::LetStmt(it) => {