From 033f87c2f0b46840168b1b3c7754a99e62b4a4ba Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 1 Oct 2021 15:30:00 +0200 Subject: [PATCH] Add some profiling calls to name resolution --- crates/hir_def/src/nameres/collector.rs | 26 +++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 53ab87005c..dbd4378968 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -275,6 +275,8 @@ struct DefCollector<'a> { impl DefCollector<'_> { fn seed_with_top_level(&mut self) { + let _p = profile::span("seed_with_top_level"); + let file_id = self.db.crate_graph()[self.def_map.krate].root_file_id; let item_tree = self.db.file_item_tree(file_id.into()); let module_id = self.def_map.root; @@ -346,15 +348,20 @@ impl DefCollector<'_> { } } - fn collect(&mut self) { + fn resolution_loop(&mut self) { + let _p = profile::span("DefCollector::resolution_loop"); + // main name resolution fixed-point loop. let mut i = 0; 'outer: loop { loop { self.db.unwind_if_cancelled(); - loop { - if self.resolve_imports() == ReachedFixedPoint::Yes { - break; + { + let _p = profile::span("resolve_imports loop"); + loop { + if self.resolve_imports() == ReachedFixedPoint::Yes { + break; + } } } if self.resolve_macros() == ReachedFixedPoint::Yes { @@ -372,6 +379,12 @@ impl DefCollector<'_> { break; } } + } + + fn collect(&mut self) { + let _p = profile::span("DefCollector::collect"); + + self.resolution_loop(); // Resolve all indeterminate resolved imports again // As some of the macros will expand newly import shadowing partial resolved imports @@ -723,6 +736,7 @@ impl DefCollector<'_> { } fn resolve_import(&self, module_id: LocalModuleId, import: &Import) -> PartialResolvedImport { + let _p = profile::span("resolve_import").detail(|| format!("{}", import.path)); tracing::debug!("resolving import: {:?} ({:?})", import, self.def_map.edition); if import.is_extern_crate { let name = import @@ -790,6 +804,8 @@ impl DefCollector<'_> { } fn record_resolved_import(&mut self, directive: &ImportDirective) { + let _p = profile::span("record_resolved_import"); + let module_id = directive.module_id; let import = &directive.import; let mut def = directive.status.namespaces(); @@ -1244,6 +1260,8 @@ impl DefCollector<'_> { fn finish(mut self) -> DefMap { // Emit diagnostics for all remaining unexpanded macros. + let _p = profile::span("DefCollector::finish"); + for directive in &self.unresolved_macros { match &directive.kind { MacroDirectiveKind::FnLike { ast_id, expand_to } => {