aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_cli/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-06-16 09:08:10 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-06-16 09:08:10 +0100
commite6fbff3246cdd3278ff1c376d5abfc1d579f86c2 (patch)
tree736052286d9c0d8d06798165590bdf145a12d783 /crates/ra_cli/src
parentce9ea0939a1ae94a83d56ddafc7aeb757dcda776 (diff)
parentb0be4207d04b65580e7af10cb256ddd5d9ca006d (diff)
Merge #1406
1406: reuse AnalysisHost in batch analysis r=matklad a=matklad We do some custom setup in `AnalysisHost`, like setting up LRU size. I figure it's a good idea to not duplicate this work in batch analysis, *if* we want to keep batch and non-batch close. Long-term, I see a value in keeping batch a separate, lighter weight thing. However, because now we use batch to measure performance, keeping them closer makes more sense. I'd also like to add ability to get completions by using batch analysis, and that will require ra_ide_api as well. @flodiebold were there some reason why we haven't started with this approach from the start? Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_cli/src')
-rw-r--r--crates/ra_cli/src/analysis_stats.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs
index c19976bd2..d76c37d84 100644
--- a/crates/ra_cli/src/analysis_stats.rs
+++ b/crates/ra_cli/src/analysis_stats.rs
@@ -1,7 +1,6 @@
1use std::{collections::HashSet, time::Instant, fmt::Write}; 1use std::{collections::HashSet, time::Instant, fmt::Write};
2 2
3use ra_db::SourceDatabase; 3use ra_db::SourceDatabase;
4use ra_batch::BatchDatabase;
5use ra_hir::{Crate, ModuleDef, Ty, ImplItem, HasSource}; 4use ra_hir::{Crate, ModuleDef, Ty, ImplItem, HasSource};
6use ra_syntax::AstNode; 5use ra_syntax::AstNode;
7 6
@@ -9,16 +8,17 @@ use crate::Result;
9 8
10pub fn run(verbose: bool, path: &str, only: Option<&str>) -> Result<()> { 9pub fn run(verbose: bool, path: &str, only: Option<&str>) -> Result<()> {
11 let db_load_time = Instant::now(); 10 let db_load_time = Instant::now();
12 let (db, roots) = BatchDatabase::load_cargo(path)?; 11 let (host, roots) = ra_batch::load_cargo(path.as_ref())?;
12 let db = host.raw_database();
13 println!("Database loaded, {} roots, {:?}", roots.len(), db_load_time.elapsed()); 13 println!("Database loaded, {} roots, {:?}", roots.len(), db_load_time.elapsed());
14 let analysis_time = Instant::now(); 14 let analysis_time = Instant::now();
15 let mut num_crates = 0; 15 let mut num_crates = 0;
16 let mut visited_modules = HashSet::new(); 16 let mut visited_modules = HashSet::new();
17 let mut visit_queue = Vec::new(); 17 let mut visit_queue = Vec::new();
18 for root in roots { 18 for root in roots {
19 for krate in Crate::source_root_crates(&db, root) { 19 for krate in Crate::source_root_crates(db, root) {
20 num_crates += 1; 20 num_crates += 1;
21 let module = krate.root_module(&db).expect("crate in source root without root module"); 21 let module = krate.root_module(db).expect("crate in source root without root module");
22 visit_queue.push(module); 22 visit_queue.push(module);
23 } 23 }
24 } 24 }
@@ -27,17 +27,17 @@ pub fn run(verbose: bool, path: &str, only: Option<&str>) -> Result<()> {
27 let mut funcs = Vec::new(); 27 let mut funcs = Vec::new();
28 while let Some(module) = visit_queue.pop() { 28 while let Some(module) = visit_queue.pop() {
29 if visited_modules.insert(module) { 29 if visited_modules.insert(module) {
30 visit_queue.extend(module.children(&db)); 30 visit_queue.extend(module.children(db));
31 31
32 for decl in module.declarations(&db) { 32 for decl in module.declarations(db) {
33 num_decls += 1; 33 num_decls += 1;
34 if let ModuleDef::Function(f) = decl { 34 if let ModuleDef::Function(f) = decl {
35 funcs.push(f); 35 funcs.push(f);
36 } 36 }
37 } 37 }
38 38
39 for impl_block in module.impl_blocks(&db) { 39 for impl_block in module.impl_blocks(db) {
40 for item in impl_block.items(&db) { 40 for item in impl_block.items(db) {
41 num_decls += 1; 41 num_decls += 1;
42 if let ImplItem::Method(f) = item { 42 if let ImplItem::Method(f) = item {
43 funcs.push(f); 43 funcs.push(f);
@@ -61,11 +61,11 @@ pub fn run(verbose: bool, path: &str, only: Option<&str>) -> Result<()> {
61 let mut num_exprs_unknown = 0; 61 let mut num_exprs_unknown = 0;
62 let mut num_exprs_partially_unknown = 0; 62 let mut num_exprs_partially_unknown = 0;
63 for f in funcs { 63 for f in funcs {
64 let name = f.name(&db); 64 let name = f.name(db);
65 let mut msg = format!("processing: {}", name); 65 let mut msg = format!("processing: {}", name);
66 if verbose { 66 if verbose {
67 let src = f.source(&db); 67 let src = f.source(db);
68 let original_file = src.file_id.original_file(&db); 68 let original_file = src.file_id.original_file(db);
69 let path = db.file_relative_path(original_file); 69 let path = db.file_relative_path(original_file);
70 let syntax_range = src.ast.syntax().range(); 70 let syntax_range = src.ast.syntax().range();
71 write!(msg, " ({:?} {})", path, syntax_range).unwrap(); 71 write!(msg, " ({:?} {})", path, syntax_range).unwrap();
@@ -76,8 +76,8 @@ pub fn run(verbose: bool, path: &str, only: Option<&str>) -> Result<()> {
76 continue; 76 continue;
77 } 77 }
78 } 78 }
79 let body = f.body(&db); 79 let body = f.body(db);
80 let inference_result = f.infer(&db); 80 let inference_result = f.infer(db);
81 for (expr_id, _) in body.exprs() { 81 for (expr_id, _) in body.exprs() {
82 let ty = &inference_result[expr_id]; 82 let ty = &inference_result[expr_id];
83 num_exprs += 1; 83 num_exprs += 1;