diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-09-02 15:07:17 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-09-02 15:07:17 +0100 |
commit | f39f72db57a78b7f92f99377be0e05ec3db6dc98 (patch) | |
tree | 789f733506520663e6cb5f99eec7d56c1a443831 /crates/ra_cli | |
parent | 6ecb36740a81445cf103577c3f9e9e6f831d0a1b (diff) | |
parent | f92177cfb5088809892455262841e24cf1ecf5b6 (diff) |
Merge #1737
1737: Report type mismatches in analysis-stats r=matklad a=flodiebold
Only the number usually; each one individually when running with `-v`.
Getting the file/line locations for the exprs was really annoying and I had to make some stuff public (that I didn't remember why it would be `pub(crate)`); maybe I missed some easier way? It would be nice to have some general way for mapping locations :thinking:
This reports 1768 mismatches on RA currently; from skimming, this seems to be mostly various kinds of coercions, though there were also some other things.
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_cli')
-rw-r--r-- | crates/ra_cli/src/analysis_stats.rs | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs index 7e7e6c073..d355fa2e8 100644 --- a/crates/ra_cli/src/analysis_stats.rs +++ b/crates/ra_cli/src/analysis_stats.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use std::{collections::HashSet, fmt::Write, path::Path, time::Instant}; | 1 | use std::{collections::HashSet, fmt::Write, path::Path, time::Instant}; |
2 | 2 | ||
3 | use ra_db::SourceDatabase; | 3 | use ra_db::SourceDatabase; |
4 | use ra_hir::{Crate, HasSource, ImplItem, ModuleDef, Ty}; | 4 | use ra_hir::{Crate, HasBodySource, HasSource, HirDisplay, ImplItem, ModuleDef, Ty}; |
5 | use ra_syntax::AstNode; | 5 | use ra_syntax::AstNode; |
6 | 6 | ||
7 | use crate::Result; | 7 | use crate::Result; |
@@ -66,6 +66,7 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) - | |||
66 | let mut num_exprs = 0; | 66 | let mut num_exprs = 0; |
67 | let mut num_exprs_unknown = 0; | 67 | let mut num_exprs_unknown = 0; |
68 | let mut num_exprs_partially_unknown = 0; | 68 | let mut num_exprs_partially_unknown = 0; |
69 | let mut num_type_mismatches = 0; | ||
69 | for f in funcs { | 70 | for f in funcs { |
70 | let name = f.name(db); | 71 | let name = f.name(db); |
71 | let mut msg = format!("processing: {}", name); | 72 | let mut msg = format!("processing: {}", name); |
@@ -100,6 +101,39 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) - | |||
100 | num_exprs_partially_unknown += 1; | 101 | num_exprs_partially_unknown += 1; |
101 | } | 102 | } |
102 | } | 103 | } |
104 | if let Some(mismatch) = inference_result.type_mismatch_for_expr(expr_id) { | ||
105 | num_type_mismatches += 1; | ||
106 | if verbose { | ||
107 | let src = f.expr_source(db, expr_id); | ||
108 | if let Some(src) = src { | ||
109 | // FIXME: it might be nice to have a function (on Analysis?) that goes from Source<T> -> (LineCol, LineCol) directly | ||
110 | let original_file = src.file_id.original_file(db); | ||
111 | let path = db.file_relative_path(original_file); | ||
112 | let line_index = host.analysis().file_line_index(original_file).unwrap(); | ||
113 | let (start, end) = ( | ||
114 | line_index.line_col(src.ast.syntax().text_range().start()), | ||
115 | line_index.line_col(src.ast.syntax().text_range().end()), | ||
116 | ); | ||
117 | bar.println(format!( | ||
118 | "{} {}:{}-{}:{}: Expected {}, got {}", | ||
119 | path.display(), | ||
120 | start.line + 1, | ||
121 | start.col_utf16, | ||
122 | end.line + 1, | ||
123 | end.col_utf16, | ||
124 | mismatch.expected.display(db), | ||
125 | mismatch.actual.display(db) | ||
126 | )); | ||
127 | } else { | ||
128 | bar.println(format!( | ||
129 | "{}: Expected {}, got {}", | ||
130 | name, | ||
131 | mismatch.expected.display(db), | ||
132 | mismatch.actual.display(db) | ||
133 | )); | ||
134 | } | ||
135 | } | ||
136 | } | ||
103 | } | 137 | } |
104 | bar.inc(1); | 138 | bar.inc(1); |
105 | } | 139 | } |
@@ -115,6 +149,7 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) - | |||
115 | num_exprs_partially_unknown, | 149 | num_exprs_partially_unknown, |
116 | (num_exprs_partially_unknown * 100 / num_exprs) | 150 | (num_exprs_partially_unknown * 100 / num_exprs) |
117 | ); | 151 | ); |
152 | println!("Type mismatches: {}", num_type_mismatches); | ||
118 | println!("Inference: {:?}, {}", inference_time.elapsed(), ra_prof::memory_usage()); | 153 | println!("Inference: {:?}, {}", inference_time.elapsed(), ra_prof::memory_usage()); |
119 | println!("Total: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage()); | 154 | println!("Total: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage()); |
120 | 155 | ||