Skip to content

Commit acb565e

Browse files
Merge #10414
10414: internal: Add some profiling calls to name resolution r=jonas-schievink a=jonas-schievink bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents 0646d5c + 033f87c commit acb565e

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

crates/hir_def/src/nameres/collector.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ struct DefCollector<'a> {
275275

276276
impl DefCollector<'_> {
277277
fn seed_with_top_level(&mut self) {
278+
let _p = profile::span("seed_with_top_level");
279+
278280
let file_id = self.db.crate_graph()[self.def_map.krate].root_file_id;
279281
let item_tree = self.db.file_item_tree(file_id.into());
280282
let module_id = self.def_map.root;
@@ -346,15 +348,20 @@ impl DefCollector<'_> {
346348
}
347349
}
348350

349-
fn collect(&mut self) {
351+
fn resolution_loop(&mut self) {
352+
let _p = profile::span("DefCollector::resolution_loop");
353+
350354
// main name resolution fixed-point loop.
351355
let mut i = 0;
352356
'outer: loop {
353357
loop {
354358
self.db.unwind_if_cancelled();
355-
loop {
356-
if self.resolve_imports() == ReachedFixedPoint::Yes {
357-
break;
359+
{
360+
let _p = profile::span("resolve_imports loop");
361+
loop {
362+
if self.resolve_imports() == ReachedFixedPoint::Yes {
363+
break;
364+
}
358365
}
359366
}
360367
if self.resolve_macros() == ReachedFixedPoint::Yes {
@@ -372,6 +379,12 @@ impl DefCollector<'_> {
372379
break;
373380
}
374381
}
382+
}
383+
384+
fn collect(&mut self) {
385+
let _p = profile::span("DefCollector::collect");
386+
387+
self.resolution_loop();
375388

376389
// Resolve all indeterminate resolved imports again
377390
// As some of the macros will expand newly import shadowing partial resolved imports
@@ -723,6 +736,7 @@ impl DefCollector<'_> {
723736
}
724737

725738
fn resolve_import(&self, module_id: LocalModuleId, import: &Import) -> PartialResolvedImport {
739+
let _p = profile::span("resolve_import").detail(|| format!("{}", import.path));
726740
tracing::debug!("resolving import: {:?} ({:?})", import, self.def_map.edition);
727741
if import.is_extern_crate {
728742
let name = import
@@ -790,6 +804,8 @@ impl DefCollector<'_> {
790804
}
791805

792806
fn record_resolved_import(&mut self, directive: &ImportDirective) {
807+
let _p = profile::span("record_resolved_import");
808+
793809
let module_id = directive.module_id;
794810
let import = &directive.import;
795811
let mut def = directive.status.namespaces();
@@ -1244,6 +1260,8 @@ impl DefCollector<'_> {
12441260
fn finish(mut self) -> DefMap {
12451261
// Emit diagnostics for all remaining unexpanded macros.
12461262

1263+
let _p = profile::span("DefCollector::finish");
1264+
12471265
for directive in &self.unresolved_macros {
12481266
match &directive.kind {
12491267
MacroDirectiveKind::FnLike { ast_id, expand_to } => {

0 commit comments

Comments
 (0)