Unnamed repository; edit this file 'description' to name the repository.
Hookup analysis_stats
Lukas Wirth 8 weeks ago
parent 408301a · commit f32fe40
-rw-r--r--crates/hir-def/src/expr_store.rs5
-rw-r--r--crates/hir-def/src/resolver.rs10
-rw-r--r--crates/hir-ty/src/infer.rs35
-rw-r--r--crates/hir-ty/src/infer/unify.rs4
-rw-r--r--crates/hir-ty/src/next_solver/def_id.rs18
-rw-r--r--crates/hir/src/lib.rs39
-rw-r--r--crates/hir/src/source_analyzer.rs11
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs165
8 files changed, 214 insertions, 73 deletions
diff --git a/crates/hir-def/src/expr_store.rs b/crates/hir-def/src/expr_store.rs
index 8552c72845..b5436f3ba3 100644
--- a/crates/hir-def/src/expr_store.rs
+++ b/crates/hir-def/src/expr_store.rs
@@ -319,7 +319,7 @@ impl ExpressionStoreBuilder {
mut bindings,
mut binding_owners,
mut ident_hygiene,
- const_expr_origins,
+ mut const_expr_origins,
mut types,
mut lifetimes,
@@ -379,6 +379,9 @@ impl ExpressionStoreBuilder {
let store = {
let expr_only = if has_exprs {
+ if let Some(const_expr_origins) = &mut const_expr_origins {
+ const_expr_origins.shrink_to_fit();
+ }
Some(Box::new(ExpressionOnlyStore {
exprs,
pats,
diff --git a/crates/hir-def/src/resolver.rs b/crates/hir-def/src/resolver.rs
index 392010df85..38b461770c 100644
--- a/crates/hir-def/src/resolver.rs
+++ b/crates/hir-def/src/resolver.rs
@@ -860,7 +860,15 @@ impl<'db> Resolver<'db> {
owner: impl Into<ExpressionStoreOwner>,
expr_id: ExprId,
) -> UpdateGuard {
- let owner = owner.into();
+ self.update_to_inner_scope_(db, owner.into(), expr_id)
+ }
+
+ fn update_to_inner_scope_(
+ &mut self,
+ db: &'db dyn DefDatabase,
+ owner: ExpressionStoreOwner,
+ expr_id: ExprId,
+ ) -> UpdateGuard {
#[inline(always)]
fn append_expr_scope<'db>(
db: &'db dyn DefDatabase,
diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs
index a78d5d8a30..9d78f5de9e 100644
--- a/crates/hir-ty/src/infer.rs
+++ b/crates/hir-ty/src/infer.rs
@@ -33,9 +33,9 @@ use std::{cell::OnceCell, convert::identity, iter};
use base_db::Crate;
use either::Either;
use hir_def::{
- AdtId, AnonConstId, AssocItemId, ConstId, ConstParamId, DefWithBodyId, ExpressionStoreOwner,
- FieldId, FunctionId, GenericDefId, GenericParamId, ItemContainerId, LocalFieldId, Lookup,
- TraitId, TupleFieldId, TupleId, TypeAliasId, TypeOrConstParamId, VariantId,
+ AdtId, AssocItemId, ConstId, ConstParamId, DefWithBodyId, ExpressionStoreOwner, FieldId,
+ FunctionId, GenericDefId, GenericParamId, ItemContainerId, LocalFieldId, Lookup, TraitId,
+ TupleFieldId, TupleId, TypeAliasId, TypeOrConstParamId, VariantId,
expr_store::{ConstExprOrigin, ExpressionStore, HygieneId, path::Path},
hir::{BindingAnnotation, BindingId, ExprId, ExprOrPatId, LabelId, PatId},
lang_item::LangItems,
@@ -146,6 +146,10 @@ pub fn infer_query_with_inspect<'db>(
ctx.infer_mut_body(body.body_expr);
+ finalize_infer(ctx)
+}
+
+fn finalize_infer(mut ctx: InferenceContext<'_, '_>) -> InferenceResult {
ctx.handle_opaque_type_uses();
ctx.type_inference_fallback();
@@ -213,9 +217,7 @@ fn infer_signature_query(db: &dyn HirDatabase, def: GenericDefId) -> InferenceRe
ctx.infer_expr(root_expr, &expected, ExprIsRead::Yes);
}
- ctx.type_inference_fallback();
- ctx.table.select_obligations_where_possible();
- ctx.resolve_all()
+ finalize_infer(ctx)
}
fn infer_signature_cycle_result(
@@ -618,24 +620,6 @@ impl InferenceResult {
}
impl InferenceResult {
- /// Look up inference results for a specific anonymous const in a signature.
- ///
- /// This delegates to [`Self::for_signature`] on the anon const's owner.
- /// The returned `InferenceResult` contains types for *all* expressions in
- /// the owner's signature store, not just this anon const's sub-tree.
- /// Callers should index into it with `loc.expr` to get the root expression's
- /// type.
- // FIXME: This function doesn't make sense in that we can't return a full inference result here
- // as the anon const is just part of an inference result.
- pub fn for_anon_const(db: &dyn HirDatabase, id: AnonConstId) -> &InferenceResult {
- match id.lookup(db).owner {
- ExpressionStoreOwner::Signature(generic_def_id) => {
- Self::for_signature(db, generic_def_id)
- }
- ExpressionStoreOwner::Body(def_with_body_id) => Self::for_body(db, def_with_body_id),
- }
- }
-
fn new(error_ty: Ty<'_>) -> Self {
Self {
method_resolutions: Default::default(),
@@ -943,8 +927,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
db.trait_environment_for_body(def_with_body_id)
}
};
- let table =
- unify::InferenceTable::new(db, trait_env, resolver.krate(), owner.as_def_with_body());
+ let table = unify::InferenceTable::new(db, trait_env, resolver.krate(), Some(owner));
let types = crate::next_solver::default_types(db);
InferenceContext {
result: InferenceResult::new(types.types.error),
diff --git a/crates/hir-ty/src/infer/unify.rs b/crates/hir-ty/src/infer/unify.rs
index 2057159c46..77f76c97b8 100644
--- a/crates/hir-ty/src/infer/unify.rs
+++ b/crates/hir-ty/src/infer/unify.rs
@@ -3,7 +3,7 @@
use std::fmt;
use base_db::Crate;
-use hir_def::{AdtId, DefWithBodyId, GenericParamId};
+use hir_def::{AdtId, ExpressionStoreOwner, GenericParamId};
use hir_expand::name::Name;
use intern::sym;
use rustc_hash::FxHashSet;
@@ -147,7 +147,7 @@ impl<'db> InferenceTable<'db> {
db: &'db dyn HirDatabase,
trait_env: ParamEnv<'db>,
krate: Crate,
- owner: Option<DefWithBodyId>,
+ owner: Option<ExpressionStoreOwner>,
) -> Self {
let interner = DbInterner::new_with(db, krate);
let typing_mode = match owner {
diff --git a/crates/hir-ty/src/next_solver/def_id.rs b/crates/hir-ty/src/next_solver/def_id.rs
index e76ab16fc2..f725af320d 100644
--- a/crates/hir-ty/src/next_solver/def_id.rs
+++ b/crates/hir-ty/src/next_solver/def_id.rs
@@ -2,8 +2,8 @@
use hir_def::{
AdtId, AnonConstId, AttrDefId, BuiltinDeriveImplId, CallableDefId, ConstId, DefWithBodyId,
- EnumId, EnumVariantId, FunctionId, GeneralConstId, GenericDefId, ImplId, StaticId, StructId,
- TraitId, TypeAliasId, UnionId,
+ EnumId, EnumVariantId, ExpressionStoreOwner, FunctionId, GeneralConstId, GenericDefId, ImplId,
+ StaticId, StructId, TraitId, TypeAliasId, UnionId,
};
use rustc_type_ir::inherent;
use stdx::impl_from;
@@ -12,13 +12,13 @@ use crate::db::{InternedClosureId, InternedCoroutineId, InternedOpaqueTyId};
use super::DbInterner;
-#[derive(Debug, PartialOrd, Ord, Clone, Copy, PartialEq, Eq, Hash, salsa::Supertype)]
+#[derive(Debug, PartialOrd, Ord, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Ctor {
Struct(StructId),
Enum(EnumVariantId),
}
-#[derive(PartialOrd, Ord, Clone, Copy, PartialEq, Eq, Hash, salsa::Supertype)]
+#[derive(PartialOrd, Ord, Clone, Copy, PartialEq, Eq, Hash)]
pub enum SolverDefId {
AdtId(AdtId),
ConstId(ConstId),
@@ -33,7 +33,6 @@ pub enum SolverDefId {
InternedCoroutineId(InternedCoroutineId),
InternedOpaqueTyId(InternedOpaqueTyId),
EnumVariantId(EnumVariantId),
- // FIXME(next-solver): Do we need the separation of `Ctor`? It duplicates some variants.
Ctor(Ctor),
}
@@ -139,6 +138,15 @@ impl From<GenericDefId> for SolverDefId {
}
}
+impl From<ExpressionStoreOwner> for SolverDefId {
+ fn from(value: ExpressionStoreOwner) -> Self {
+ match value {
+ ExpressionStoreOwner::Signature(generic_def_id) => generic_def_id.into(),
+ ExpressionStoreOwner::Body(def_with_body_id) => def_with_body_id.into(),
+ }
+ }
+}
+
impl From<GeneralConstId> for SolverDefId {
#[inline]
fn from(value: GeneralConstId) -> Self {
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 6dfb94cbf3..34372a4a95 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -508,6 +508,21 @@ impl ModuleDef {
}
}
+ pub fn as_generic_def(self) -> Option<GenericDef> {
+ match self {
+ ModuleDef::Function(it) => Some(it.into()),
+ ModuleDef::Adt(it) => Some(it.into()),
+ ModuleDef::Trait(it) => Some(it.into()),
+ ModuleDef::TypeAlias(it) => Some(it.into()),
+ ModuleDef::Static(it) => Some(it.into()),
+ ModuleDef::Const(it) => Some(it.into()),
+ ModuleDef::Variant(_)
+ | ModuleDef::Module(_)
+ | ModuleDef::BuiltinType(_)
+ | ModuleDef::Macro(_) => None,
+ }
+ }
+
pub fn attrs(&self, db: &dyn HirDatabase) -> Option<AttrsWithOwner> {
Some(match self {
ModuleDef::Module(it) => it.attrs(db),
@@ -3972,6 +3987,30 @@ impl_from!(
);
impl GenericDef {
+ pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
+ match self {
+ GenericDef::Function(it) => Some(it.name(db)),
+ GenericDef::Adt(it) => Some(it.name(db)),
+ GenericDef::Trait(it) => Some(it.name(db)),
+ GenericDef::TypeAlias(it) => Some(it.name(db)),
+ GenericDef::Impl(_) => None,
+ GenericDef::Const(it) => it.name(db),
+ GenericDef::Static(it) => Some(it.name(db)),
+ }
+ }
+
+ pub fn module(self, db: &dyn HirDatabase) -> Module {
+ match self {
+ GenericDef::Function(it) => it.module(db),
+ GenericDef::Adt(it) => it.module(db),
+ GenericDef::Trait(it) => it.module(db),
+ GenericDef::TypeAlias(it) => it.module(db),
+ GenericDef::Impl(it) => it.module(db),
+ GenericDef::Const(it) => it.module(db),
+ GenericDef::Static(it) => it.module(db),
+ }
+ }
+
pub fn params(self, db: &dyn HirDatabase) -> Vec<GenericParam> {
let Ok(id) = self.try_into() else {
// Let's pretend builtin derive impls don't have generic parameters.
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs
index ad7aea3918..1d3cfc748e 100644
--- a/crates/hir/src/source_analyzer.rs
+++ b/crates/hir/src/source_analyzer.rs
@@ -152,7 +152,7 @@ impl<'db> SourceAnalyzer<'db> {
node: InFile<&SyntaxNode>,
offset: Option<TextSize>,
) -> SourceAnalyzer<'db> {
- Self::new_generic_def_(db, def, node, offset, Some(InferenceResult::for_signature(db, def)))
+ Self::new_generic_def_(db, def, node, offset, true)
}
pub(crate) fn new_generic_def_no_infer(
@@ -161,7 +161,7 @@ impl<'db> SourceAnalyzer<'db> {
node: InFile<&SyntaxNode>,
offset: Option<TextSize>,
) -> SourceAnalyzer<'db> {
- Self::new_generic_def_(db, def, node, offset, None)
+ Self::new_generic_def_(db, def, node, offset, false)
}
pub(crate) fn new_generic_def_(
@@ -169,7 +169,7 @@ impl<'db> SourceAnalyzer<'db> {
def: GenericDefId,
node @ InFile { file_id, .. }: InFile<&SyntaxNode>,
offset: Option<TextSize>,
- infer: Option<&'db InferenceResult>,
+ infer: bool,
) -> SourceAnalyzer<'db> {
let (generics, store, source_map) = db.generic_params_and_store_and_source_map(def);
let scopes = db.expr_scopes(def.into());
@@ -186,6 +186,11 @@ impl<'db> SourceAnalyzer<'db> {
}
};
let resolver = resolver_for_scope(db, def, scope);
+ let infer = if infer && !Arc::ptr_eq(&store, &ExpressionStore::empty_singleton().0) {
+ Some(InferenceResult::for_signature(db, def))
+ } else {
+ None
+ };
SourceAnalyzer {
resolver,
body_or_sig: Some(BodyOrSig::Sig { def, store, source_map, generics, infer }),
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index ad1cca08cb..3ee3797654 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -10,8 +10,8 @@ use std::{
use cfg::{CfgAtom, CfgDiff};
use hir::{
- Adt, AssocItem, Crate, DefWithBody, FindPathConfig, HasCrate, HasSource, HirDisplay, ModuleDef,
- Name, crate_lang_items,
+ Adt, AssocItem, Crate, DefWithBody, FindPathConfig, GenericDef, HasCrate, HasSource,
+ HirDisplay, ModuleDef, Name, crate_lang_items,
db::{DefDatabase, ExpandDatabase, HirDatabase},
next_solver::{DbInterner, GenericArgs},
};
@@ -229,6 +229,7 @@ impl flags::AnalysisStats {
eprint!(" crates: {num_crates}");
let mut num_decls = 0;
let mut bodies = Vec::new();
+ let mut signatures = Vec::new();
let mut adts = Vec::new();
let mut file_ids = Vec::new();
@@ -267,24 +268,32 @@ impl flags::AnalysisStats {
},
_ => (),
};
+ if let Some(g) = decl.as_generic_def() {
+ signatures.push(g);
+ }
}
for impl_def in module.impl_defs(db) {
+ signatures.push(impl_def.into());
for item in impl_def.items(db) {
num_decls += 1;
match item {
- AssocItem::Function(f) => bodies.push(DefWithBody::from(f)),
+ AssocItem::Function(f) => {
+ bodies.push(DefWithBody::from(f));
+ signatures.push(f.into())
+ }
AssocItem::Const(c) => {
bodies.push(DefWithBody::from(c));
+ signatures.push(c.into());
}
- _ => (),
+ AssocItem::TypeAlias(t) => signatures.push(t.into()),
}
}
}
}
}
eprintln!(
- ", mods: {}, decls: {num_decls}, bodies: {}, adts: {}, consts: {}",
+ ", mods: {}, decls: {num_decls}, bodies: {}, adts: {}, consts: {}, signatures: {}",
visited_modules.len(),
bodies.len(),
adts.len(),
@@ -292,6 +301,7 @@ impl flags::AnalysisStats {
.iter()
.filter(|it| matches!(it, DefWithBody::Const(_) | DefWithBody::Static(_)))
.count(),
+ signatures.len(),
);
eprintln!(" Workspace:");
@@ -327,15 +337,15 @@ impl flags::AnalysisStats {
}
if !self.skip_lowering {
- self.run_body_lowering(db, &vfs, &bodies, verbosity);
+ self.run_body_lowering(db, &vfs, &bodies, &signatures, verbosity);
}
if !self.skip_inference {
- self.run_inference(db, &vfs, &bodies, verbosity);
+ self.run_inference(db, &vfs, &bodies, &signatures, verbosity);
}
if !self.skip_mir_stats {
- self.run_mir_lowering(db, &bodies, verbosity);
+ self.run_mir_lowering(db, &bodies, &signatures, verbosity);
}
if !self.skip_data_layout {
@@ -343,7 +353,7 @@ impl flags::AnalysisStats {
}
if !self.skip_const_eval {
- self.run_const_eval(db, &bodies, verbosity);
+ self.run_const_eval(db, &bodies, &signatures, verbosity);
}
});
@@ -416,7 +426,13 @@ impl flags::AnalysisStats {
report_metric("data layout time", data_layout_time.time.as_millis() as u64, "ms");
}
- fn run_const_eval(&self, db: &RootDatabase, bodies: &[DefWithBody], verbosity: Verbosity) {
+ fn run_const_eval(
+ &self,
+ db: &RootDatabase,
+ bodies: &[DefWithBody],
+ _signatures: &[GenericDef],
+ verbosity: Verbosity,
+ ) {
let len = bodies
.iter()
.filter(|body| matches!(body, DefWithBody::Const(_) | DefWithBody::Static(_)))
@@ -431,7 +447,9 @@ impl flags::AnalysisStats {
let mut all = 0;
let mut fail = 0;
for &b in bodies {
- bar.set_message(move || format!("const eval: {}", full_name(db, b, b.module(db))));
+ bar.set_message(move || {
+ format!("const eval: {}", full_name(db, || b.name(db), b.module(db)))
+ });
let res = match b {
DefWithBody::Const(c) => c.eval(db),
DefWithBody::Static(s) => s.eval(db),
@@ -687,7 +705,13 @@ impl flags::AnalysisStats {
bar.finish_and_clear();
}
- fn run_mir_lowering(&self, db: &RootDatabase, bodies: &[DefWithBody], verbosity: Verbosity) {
+ fn run_mir_lowering(
+ &self,
+ db: &RootDatabase,
+ bodies: &[DefWithBody],
+ _signatures: &[GenericDef],
+ verbosity: Verbosity,
+ ) {
let mut bar = match verbosity {
Verbosity::Quiet | Verbosity::Spammy => ProgressReport::hidden(),
_ if self.parallel || self.output.is_some() => ProgressReport::hidden(),
@@ -698,14 +722,14 @@ impl flags::AnalysisStats {
let mut fail = 0;
for &body in bodies {
bar.set_message(move || {
- format!("mir lowering: {}", full_name(db, body, body.module(db)))
+ format!("mir lowering: {}", full_name(db, || body.name(db), body.module(db)))
});
bar.inc(1);
if matches!(body, DefWithBody::Variant(_)) {
continue;
}
let module = body.module(db);
- if !self.should_process(db, body, module) {
+ if !self.should_process(db, || body.name(db), module) {
continue;
}
@@ -743,6 +767,7 @@ impl flags::AnalysisStats {
db: &RootDatabase,
vfs: &Vfs,
bodies: &[DefWithBody],
+ signatures: &[GenericDef],
verbosity: Verbosity,
) {
let mut bar = match verbosity {
@@ -757,10 +782,19 @@ impl flags::AnalysisStats {
bodies
.par_iter()
.map_with(db.clone(), |snap, &body| {
- snap.body(body);
InferenceResult::for_body(snap, body);
})
.count();
+ let signatures = signatures
+ .iter()
+ .filter_map(|&signatures| signatures.try_into().ok())
+ .collect::<Vec<_>>();
+ signatures
+ .par_iter()
+ .map_with(db.clone(), |snap, &signatures| {
+ InferenceResult::for_signature(snap, signatures);
+ })
+ .count();
eprintln!("{:<20} {}", "Parallel Inference:", inference_sw.elapsed());
}
@@ -782,7 +816,7 @@ impl flags::AnalysisStats {
let display_target = module.krate(db).to_display_target(db);
if let Some(only_name) = self.only.as_deref()
&& name.display(db, Edition::LATEST).to_string() != only_name
- && full_name(db, body_id, module) != only_name
+ && full_name(db, || body_id.name(db), module) != only_name
{
continue;
}
@@ -800,15 +834,15 @@ impl flags::AnalysisStats {
let syntax_range = src.text_range();
format!(
"processing: {} ({} {:?})",
- full_name(db, body_id, module),
+ full_name(db, || body_id.name(db), module),
path,
syntax_range
)
} else {
- format!("processing: {}", full_name(db, body_id, module))
+ format!("processing: {}", full_name(db, || body_id.name(db), module))
}
} else {
- format!("processing: {}", full_name(db, body_id, module))
+ format!("processing: {}", full_name(db, || body_id.name(db), module))
}
};
if verbosity.is_spammy() {
@@ -822,11 +856,22 @@ impl flags::AnalysisStats {
Ok(inference_result) => inference_result,
Err(p) => {
if let Some(s) = p.downcast_ref::<&str>() {
- eprintln!("infer panicked for {}: {}", full_name(db, body_id, module), s);
+ eprintln!(
+ "infer panicked for {}: {}",
+ full_name(db, || body_id.name(db), module),
+ s
+ );
} else if let Some(s) = p.downcast_ref::<String>() {
- eprintln!("infer panicked for {}: {}", full_name(db, body_id, module), s);
+ eprintln!(
+ "infer panicked for {}: {}",
+ full_name(db, || body_id.name(db), module),
+ s
+ );
} else {
- eprintln!("infer panicked for {}", full_name(db, body_id, module));
+ eprintln!(
+ "infer panicked for {}",
+ full_name(db, || body_id.name(db), module)
+ );
}
panics += 1;
bar.inc(1);
@@ -932,7 +977,7 @@ impl flags::AnalysisStats {
if verbosity.is_spammy() {
bar.println(format!(
"In {}: {} exprs, {} unknown, {} partial",
- full_name(db, body_id, module),
+ full_name(db, || body_id.name(db), module),
num_exprs - previous_exprs,
num_exprs_unknown - previous_unknown,
num_exprs_partially_unknown - previous_partially_unknown
@@ -1034,7 +1079,7 @@ impl flags::AnalysisStats {
if verbosity.is_spammy() {
bar.println(format!(
"In {}: {} pats, {} unknown, {} partial",
- full_name(db, body_id, module),
+ full_name(db, || body_id.name(db), module),
num_pats - previous_pats,
num_pats_unknown - previous_unknown,
num_pats_partially_unknown - previous_partially_unknown
@@ -1078,20 +1123,65 @@ impl flags::AnalysisStats {
db: &RootDatabase,
vfs: &Vfs,
bodies: &[DefWithBody],
+ signatures: &[GenericDef],
verbosity: Verbosity,
) {
let mut bar = match verbosity {
Verbosity::Quiet | Verbosity::Spammy => ProgressReport::hidden(),
_ if self.output.is_some() => ProgressReport::hidden(),
- _ => ProgressReport::new(bodies.len()),
+ _ => ProgressReport::new(bodies.len() + signatures.len()),
};
let mut sw = self.stop_watch();
bar.tick();
+ for &signature in signatures {
+ let Ok(signature_id) = signature.try_into() else { continue };
+ let module = signature.module(db);
+ if !self.should_process(db, || signature.name(db), module) {
+ continue;
+ }
+ let msg = move || {
+ if verbosity.is_verbose() {
+ let source = match signature {
+ GenericDef::Function(it) => it.source(db).map(|it| it.syntax().cloned()),
+ GenericDef::Static(it) => it.source(db).map(|it| it.syntax().cloned()),
+ GenericDef::Const(it) => it.source(db).map(|it| it.syntax().cloned()),
+ GenericDef::Adt(adt) => adt.source(db).map(|it| it.syntax().cloned()),
+ GenericDef::Trait(it) => it.source(db).map(|it| it.syntax().cloned()),
+ GenericDef::TypeAlias(type_alias) => {
+ type_alias.source(db).map(|it| it.syntax().cloned())
+ }
+ GenericDef::Impl(it) => it.source(db).map(|it| it.syntax().cloned()),
+ };
+ if let Some(src) = source {
+ let original_file = src.file_id.original_file(db);
+ let path = vfs.file_path(original_file.file_id(db));
+ let syntax_range = src.text_range();
+ format!(
+ "processing: {} ({} {:?})",
+ full_name(db, || signature.name(db), module),
+ path,
+ syntax_range
+ )
+ } else {
+ format!("processing: {}", full_name(db, || signature.name(db), module))
+ }
+ } else {
+ format!("processing: {}", full_name(db, || signature.name(db), module))
+ }
+ };
+ if verbosity.is_spammy() {
+ bar.println(msg());
+ }
+ bar.set_message(msg);
+ db.generic_params_and_store(signature_id);
+ bar.inc(1);
+ }
+
for &body_id in bodies {
let Ok(body_def_id) = body_id.try_into() else { continue };
let module = body_id.module(db);
- if !self.should_process(db, body_id, module) {
+ if !self.should_process(db, || body_id.name(db), module) {
continue;
}
let msg = move || {
@@ -1108,15 +1198,15 @@ impl flags::AnalysisStats {
let syntax_range = src.text_range();
format!(
"processing: {} ({} {:?})",
- full_name(db, body_id, module),
+ full_name(db, || body_id.name(db), module),
path,
syntax_range
)
} else {
- format!("processing: {}", full_name(db, body_id, module))
+ format!("processing: {}", full_name(db, || body_id.name(db), module))
}
} else {
- format!("processing: {}", full_name(db, body_id, module))
+ format!("processing: {}", full_name(db, || body_id.name(db), module))
}
};
if verbosity.is_spammy() {
@@ -1129,7 +1219,7 @@ impl flags::AnalysisStats {
bar.finish_and_clear();
let body_lowering_time = sw.elapsed();
- eprintln!("{:<20} {}", "Body lowering:", body_lowering_time);
+ eprintln!("{:<20} {}", "Expression Store Lowering:", body_lowering_time);
report_metric("body lowering time", body_lowering_time.time.as_millis() as u64, "ms");
}
@@ -1283,12 +1373,17 @@ impl flags::AnalysisStats {
eprintln!("{:<20} {} ({} files)", "IDE:", ide_time, file_ids.len());
}
- fn should_process(&self, db: &RootDatabase, body_id: DefWithBody, module: hir::Module) -> bool {
+ fn should_process(
+ &self,
+ db: &RootDatabase,
+ name_fn: impl Fn() -> Option<Name>,
+ module: hir::Module,
+ ) -> bool {
if let Some(only_name) = self.only.as_deref() {
- let name = body_id.name(db).unwrap_or_else(Name::missing);
+ let name = name_fn().unwrap_or_else(Name::missing);
if name.display(db, Edition::LATEST).to_string() != only_name
- && full_name(db, body_id, module) != only_name
+ && full_name(db, name_fn, module) != only_name
{
return false;
}
@@ -1301,7 +1396,7 @@ impl flags::AnalysisStats {
}
}
-fn full_name(db: &RootDatabase, body_id: DefWithBody, module: hir::Module) -> String {
+fn full_name(db: &RootDatabase, name: impl Fn() -> Option<Name>, module: hir::Module) -> String {
module
.krate(db)
.display_name(db)
@@ -1313,7 +1408,7 @@ fn full_name(db: &RootDatabase, body_id: DefWithBody, module: hir::Module) -> St
.into_iter()
.filter_map(|it| it.name(db))
.rev()
- .chain(Some(body_id.name(db).unwrap_or_else(Name::missing)))
+ .chain(Some(name().unwrap_or_else(Name::missing)))
.map(|it| it.display(db, Edition::LATEST).to_string()),
)
.join("::")