diff options
author | Florian Diebold <[email protected]> | 2019-08-25 18:28:32 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-09-02 13:56:38 +0100 |
commit | a7858bb7bf0a784d56b2b9ef97785a4fa78f7853 (patch) | |
tree | ffc29db397d35b9cfa55d2418db996dbf22e4995 | |
parent | 6ecb36740a81445cf103577c3f9e9e6f831d0a1b (diff) |
Report type mismatches in analysis-stats
Only the number usually; each one individually when running with -v.
-rw-r--r-- | crates/ra_cli/src/analysis_stats.rs | 38 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/expr.rs | 12 |
3 files changed, 44 insertions, 8 deletions
diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs index 7e7e6c073..77fa1d26e 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, 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,40 @@ 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.source(db); | ||
108 | let original_file = src.file_id.original_file(db); | ||
109 | let path = db.file_relative_path(original_file); | ||
110 | let line_index = host.analysis().file_line_index(original_file).unwrap(); | ||
111 | let body_source_map = f.body_source_map(db); | ||
112 | let syntax_node = body_source_map.expr_syntax(expr_id); | ||
113 | let line_col = syntax_node.map(|syntax_node| { | ||
114 | ( | ||
115 | line_index.line_col(syntax_node.range().start()), | ||
116 | line_index.line_col(syntax_node.range().end()), | ||
117 | ) | ||
118 | }); | ||
119 | let line_col = match line_col { | ||
120 | Some((start, end)) => format!( | ||
121 | "{}:{}-{}:{}", | ||
122 | start.line + 1, | ||
123 | start.col_utf16, | ||
124 | end.line + 1, | ||
125 | end.col_utf16 | ||
126 | ), | ||
127 | None => "?:?".to_string(), | ||
128 | }; | ||
129 | bar.println(format!( | ||
130 | "{} {}: Expected {}, got {}", | ||
131 | path.display(), | ||
132 | line_col, | ||
133 | mismatch.expected.display(db), | ||
134 | mismatch.actual.display(db) | ||
135 | )); | ||
136 | } | ||
137 | } | ||
103 | } | 138 | } |
104 | bar.inc(1); | 139 | bar.inc(1); |
105 | } | 140 | } |
@@ -115,6 +150,7 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) - | |||
115 | num_exprs_partially_unknown, | 150 | num_exprs_partially_unknown, |
116 | (num_exprs_partially_unknown * 100 / num_exprs) | 151 | (num_exprs_partially_unknown * 100 / num_exprs) |
117 | ); | 152 | ); |
153 | println!("Type mismatches: {}", num_type_mismatches); | ||
118 | println!("Inference: {:?}, {}", inference_time.elapsed(), ra_prof::memory_usage()); | 154 | println!("Inference: {:?}, {}", inference_time.elapsed(), ra_prof::memory_usage()); |
119 | println!("Total: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage()); | 155 | println!("Total: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage()); |
120 | 156 | ||
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 66a58efed..0f9ff97f1 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -617,7 +617,7 @@ impl Function { | |||
617 | self.data(db).name.clone() | 617 | self.data(db).name.clone() |
618 | } | 618 | } |
619 | 619 | ||
620 | pub(crate) fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> { | 620 | pub fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> { |
621 | db.body_with_source_map(self.into()).1 | 621 | db.body_with_source_map(self.into()).1 |
622 | } | 622 | } |
623 | 623 | ||
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 7cdc7555c..57225ae91 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -128,27 +128,27 @@ impl Index<PatId> for Body { | |||
128 | } | 128 | } |
129 | 129 | ||
130 | impl BodySourceMap { | 130 | impl BodySourceMap { |
131 | pub(crate) fn expr_syntax(&self, expr: ExprId) -> Option<SyntaxNodePtr> { | 131 | pub fn expr_syntax(&self, expr: ExprId) -> Option<SyntaxNodePtr> { |
132 | self.expr_map_back.get(expr).cloned() | 132 | self.expr_map_back.get(expr).cloned() |
133 | } | 133 | } |
134 | 134 | ||
135 | pub(crate) fn syntax_expr(&self, ptr: SyntaxNodePtr) -> Option<ExprId> { | 135 | pub fn syntax_expr(&self, ptr: SyntaxNodePtr) -> Option<ExprId> { |
136 | self.expr_map.get(&ptr).cloned() | 136 | self.expr_map.get(&ptr).cloned() |
137 | } | 137 | } |
138 | 138 | ||
139 | pub(crate) fn node_expr(&self, node: &ast::Expr) -> Option<ExprId> { | 139 | pub fn node_expr(&self, node: &ast::Expr) -> Option<ExprId> { |
140 | self.expr_map.get(&SyntaxNodePtr::new(node.syntax())).cloned() | 140 | self.expr_map.get(&SyntaxNodePtr::new(node.syntax())).cloned() |
141 | } | 141 | } |
142 | 142 | ||
143 | pub(crate) fn pat_syntax(&self, pat: PatId) -> Option<PatPtr> { | 143 | pub fn pat_syntax(&self, pat: PatId) -> Option<PatPtr> { |
144 | self.pat_map_back.get(pat).cloned() | 144 | self.pat_map_back.get(pat).cloned() |
145 | } | 145 | } |
146 | 146 | ||
147 | pub(crate) fn node_pat(&self, node: &ast::Pat) -> Option<PatId> { | 147 | pub fn node_pat(&self, node: &ast::Pat) -> Option<PatId> { |
148 | self.pat_map.get(&Either::A(AstPtr::new(node))).cloned() | 148 | self.pat_map.get(&Either::A(AstPtr::new(node))).cloned() |
149 | } | 149 | } |
150 | 150 | ||
151 | pub(crate) fn field_syntax(&self, expr: ExprId, field: usize) -> AstPtr<ast::RecordField> { | 151 | pub fn field_syntax(&self, expr: ExprId, field: usize) -> AstPtr<ast::RecordField> { |
152 | self.field_map[&(expr, field)] | 152 | self.field_map[&(expr, field)] |
153 | } | 153 | } |
154 | } | 154 | } |