From 6f5ac06b47b040936c6e0a1fbac9cdba13e26197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Sun, 4 Aug 2019 13:49:13 +0300 Subject: Display the parsing time in ra_cli analysis-stats --- crates/ra_cli/src/analysis_stats.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs index 403aab352..4fe3cb43a 100644 --- a/crates/ra_cli/src/analysis_stats.rs +++ b/crates/ra_cli/src/analysis_stats.rs @@ -52,6 +52,9 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) - println!("Total modules found: {}", visited_modules.len()); println!("Total declarations: {}", num_decls); println!("Total functions: {}", funcs.len()); + println!("Parsing: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage()); + + let inference_time = Instant::now(); let bar = indicatif::ProgressBar::with_draw_target( funcs.len() as u64, indicatif::ProgressDrawTarget::stderr_nohz(), @@ -112,7 +115,8 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) - num_exprs_partially_unknown, (num_exprs_partially_unknown * 100 / num_exprs) ); - println!("Analysis: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage()); + println!("Inference: {:?}, {}", inference_time.elapsed(), ra_prof::memory_usage()); + println!("Total: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage()); if memory_usage { drop(db); -- cgit v1.2.3 From b118f7511ca522e1d5199105a856f18b4dee51f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Sun, 4 Aug 2019 14:06:07 +0300 Subject: Optimize Parser::is_composite a little --- crates/ra_parser/src/parser.rs | 54 +++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/crates/ra_parser/src/parser.rs b/crates/ra_parser/src/parser.rs index 159ed50df..393586561 100644 --- a/crates/ra_parser/src/parser.rs +++ b/crates/ra_parser/src/parser.rs @@ -6,7 +6,7 @@ use crate::{ event::Event, ParseError, SyntaxKind::{self, EOF, ERROR, TOMBSTONE}, - TokenSet, TokenSource, T, + Token, TokenSet, TokenSource, T, }; /// `Parser` struct provides the low-level API for @@ -87,8 +87,9 @@ impl<'t> Parser<'t> { let mut i = 0; loop { - let mut kind = self.token_source.lookahead_nth(i).kind; - if let Some((composited, step)) = self.is_composite(kind, i) { + let token = self.token_source.lookahead_nth(i); + let mut kind = token.kind; + if let Some((composited, step)) = self.is_composite(token, i) { kind = composited; i += step; } else { @@ -250,32 +251,47 @@ impl<'t> Parser<'t> { } /// helper function for check if it is composite. - fn is_composite(&self, kind: SyntaxKind, n: usize) -> Option<(SyntaxKind, usize)> { + fn is_composite(&self, first: Token, n: usize) -> Option<(SyntaxKind, usize)> { // We assume the dollars will not occuried between // mult-byte tokens - let first = self.token_source.lookahead_nth(n); + let jn1 = first.is_jointed_to_next; + if !jn1 && first.kind != T![-] { + return None; + } + let second = self.token_source.lookahead_nth(n + 1); + if first.kind == T![-] && second.kind == T![>] { + return Some((T![->], 2)); + } + if !jn1 { + return None; + } + + match (first.kind, second.kind) { + (T![:], T![:]) => return Some((T![::], 2)), + (T![=], T![=]) => return Some((T![==], 2)), + (T![=], T![>]) => return Some((T![=>], 2)), + (T![!], T![=]) => return Some((T![!=], 2)), + _ => {} + } + + if first.kind != T![.] || second.kind != T![.] { + return None; + } + let third = self.token_source.lookahead_nth(n + 2); - let jn1 = first.is_jointed_to_next; - let la2 = second.kind; let jn2 = second.is_jointed_to_next; let la3 = third.kind; - match kind { - T![.] if jn1 && la2 == T![.] && jn2 && la3 == T![.] => Some((T![...], 3)), - T![.] if jn1 && la2 == T![.] && la3 == T![=] => Some((T![..=], 3)), - T![.] if jn1 && la2 == T![.] => Some((T![..], 2)), - - T![:] if jn1 && la2 == T![:] => Some((T![::], 2)), - T![=] if jn1 && la2 == T![=] => Some((T![==], 2)), - T![=] if jn1 && la2 == T![>] => Some((T![=>], 2)), - - T![!] if jn1 && la2 == T![=] => Some((T![!=], 2)), - T![-] if la2 == T![>] => Some((T![->], 2)), - _ => None, + if jn2 && la3 == T![.] { + return Some((T![...], 3)); + } + if la3 == T![=] { + return Some((T![..=], 3)); } + return Some((T![..], 2)); } fn eat_dollars(&mut self) { -- cgit v1.2.3 From f1cfd5ec3de3de39e5423e80a35c719463c4e5c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 5 Aug 2019 16:52:18 +0300 Subject: Update crates/ra_cli/src/analysis_stats.rs Co-Authored-By: Aleksey Kladov --- crates/ra_cli/src/analysis_stats.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs index 4fe3cb43a..7e7e6c073 100644 --- a/crates/ra_cli/src/analysis_stats.rs +++ b/crates/ra_cli/src/analysis_stats.rs @@ -52,7 +52,7 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) - println!("Total modules found: {}", visited_modules.len()); println!("Total declarations: {}", num_decls); println!("Total functions: {}", funcs.len()); - println!("Parsing: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage()); + println!("Item Collection: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage()); let inference_time = Instant::now(); let bar = indicatif::ProgressBar::with_draw_target( -- cgit v1.2.3