mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Report type mismatches in analysis-stats
Only the number usually; each one individually when running with -v.
This commit is contained in:
parent
6ecb36740a
commit
a7858bb7bf
3 changed files with 44 additions and 8 deletions
|
@ -1,7 +1,7 @@
|
||||||
use std::{collections::HashSet, fmt::Write, path::Path, time::Instant};
|
use std::{collections::HashSet, fmt::Write, path::Path, time::Instant};
|
||||||
|
|
||||||
use ra_db::SourceDatabase;
|
use ra_db::SourceDatabase;
|
||||||
use ra_hir::{Crate, HasSource, ImplItem, ModuleDef, Ty};
|
use ra_hir::{Crate, HasSource, HirDisplay, ImplItem, ModuleDef, Ty};
|
||||||
use ra_syntax::AstNode;
|
use ra_syntax::AstNode;
|
||||||
|
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
|
@ -66,6 +66,7 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) -
|
||||||
let mut num_exprs = 0;
|
let mut num_exprs = 0;
|
||||||
let mut num_exprs_unknown = 0;
|
let mut num_exprs_unknown = 0;
|
||||||
let mut num_exprs_partially_unknown = 0;
|
let mut num_exprs_partially_unknown = 0;
|
||||||
|
let mut num_type_mismatches = 0;
|
||||||
for f in funcs {
|
for f in funcs {
|
||||||
let name = f.name(db);
|
let name = f.name(db);
|
||||||
let mut msg = format!("processing: {}", name);
|
let mut msg = format!("processing: {}", name);
|
||||||
|
@ -100,6 +101,40 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) -
|
||||||
num_exprs_partially_unknown += 1;
|
num_exprs_partially_unknown += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let Some(mismatch) = inference_result.type_mismatch_for_expr(expr_id) {
|
||||||
|
num_type_mismatches += 1;
|
||||||
|
if verbose {
|
||||||
|
let src = f.source(db);
|
||||||
|
let original_file = src.file_id.original_file(db);
|
||||||
|
let path = db.file_relative_path(original_file);
|
||||||
|
let line_index = host.analysis().file_line_index(original_file).unwrap();
|
||||||
|
let body_source_map = f.body_source_map(db);
|
||||||
|
let syntax_node = body_source_map.expr_syntax(expr_id);
|
||||||
|
let line_col = syntax_node.map(|syntax_node| {
|
||||||
|
(
|
||||||
|
line_index.line_col(syntax_node.range().start()),
|
||||||
|
line_index.line_col(syntax_node.range().end()),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
let line_col = match line_col {
|
||||||
|
Some((start, end)) => format!(
|
||||||
|
"{}:{}-{}:{}",
|
||||||
|
start.line + 1,
|
||||||
|
start.col_utf16,
|
||||||
|
end.line + 1,
|
||||||
|
end.col_utf16
|
||||||
|
),
|
||||||
|
None => "?:?".to_string(),
|
||||||
|
};
|
||||||
|
bar.println(format!(
|
||||||
|
"{} {}: Expected {}, got {}",
|
||||||
|
path.display(),
|
||||||
|
line_col,
|
||||||
|
mismatch.expected.display(db),
|
||||||
|
mismatch.actual.display(db)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
bar.inc(1);
|
bar.inc(1);
|
||||||
}
|
}
|
||||||
|
@ -115,6 +150,7 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) -
|
||||||
num_exprs_partially_unknown,
|
num_exprs_partially_unknown,
|
||||||
(num_exprs_partially_unknown * 100 / num_exprs)
|
(num_exprs_partially_unknown * 100 / num_exprs)
|
||||||
);
|
);
|
||||||
|
println!("Type mismatches: {}", num_type_mismatches);
|
||||||
println!("Inference: {:?}, {}", inference_time.elapsed(), ra_prof::memory_usage());
|
println!("Inference: {:?}, {}", inference_time.elapsed(), ra_prof::memory_usage());
|
||||||
println!("Total: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage());
|
println!("Total: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage());
|
||||||
|
|
||||||
|
|
|
@ -617,7 +617,7 @@ impl Function {
|
||||||
self.data(db).name.clone()
|
self.data(db).name.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
|
pub fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
|
||||||
db.body_with_source_map(self.into()).1
|
db.body_with_source_map(self.into()).1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,27 +128,27 @@ impl Index<PatId> for Body {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BodySourceMap {
|
impl BodySourceMap {
|
||||||
pub(crate) fn expr_syntax(&self, expr: ExprId) -> Option<SyntaxNodePtr> {
|
pub fn expr_syntax(&self, expr: ExprId) -> Option<SyntaxNodePtr> {
|
||||||
self.expr_map_back.get(expr).cloned()
|
self.expr_map_back.get(expr).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn syntax_expr(&self, ptr: SyntaxNodePtr) -> Option<ExprId> {
|
pub fn syntax_expr(&self, ptr: SyntaxNodePtr) -> Option<ExprId> {
|
||||||
self.expr_map.get(&ptr).cloned()
|
self.expr_map.get(&ptr).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn node_expr(&self, node: &ast::Expr) -> Option<ExprId> {
|
pub fn node_expr(&self, node: &ast::Expr) -> Option<ExprId> {
|
||||||
self.expr_map.get(&SyntaxNodePtr::new(node.syntax())).cloned()
|
self.expr_map.get(&SyntaxNodePtr::new(node.syntax())).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn pat_syntax(&self, pat: PatId) -> Option<PatPtr> {
|
pub fn pat_syntax(&self, pat: PatId) -> Option<PatPtr> {
|
||||||
self.pat_map_back.get(pat).cloned()
|
self.pat_map_back.get(pat).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn node_pat(&self, node: &ast::Pat) -> Option<PatId> {
|
pub fn node_pat(&self, node: &ast::Pat) -> Option<PatId> {
|
||||||
self.pat_map.get(&Either::A(AstPtr::new(node))).cloned()
|
self.pat_map.get(&Either::A(AstPtr::new(node))).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn field_syntax(&self, expr: ExprId, field: usize) -> AstPtr<ast::RecordField> {
|
pub fn field_syntax(&self, expr: ExprId, field: usize) -> AstPtr<ast::RecordField> {
|
||||||
self.field_map[&(expr, field)]
|
self.field_map[&(expr, field)]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue