Skip to content

internal: Add some profiling calls to name resolution #10414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions crates/hir_def/src/nameres/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 } => {
Expand Down