Skip to content

Commit

Permalink
fix: Tracing span names should match function names
Browse files Browse the repository at this point in the history
When viewing traces, it's slightly confusing when the span name doesn't
match the function name. Ensure the names are consistent.

(It might be worth moving most of these to use #[tracing::instrument]
so the name can never go stale. @davidbarsky suggested that is marginally
slower, so I've just done the simple change here.)
  • Loading branch information
Wilfred committed Apr 27, 2024
1 parent 1ed7e2d commit da92c1f
Show file tree
Hide file tree
Showing 20 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion crates/base-db/src/change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl FileChange {
}

pub fn apply(self, db: &mut dyn SourceDatabaseExt) {
let _p = tracing::span!(tracing::Level::INFO, "RootDatabase::apply_change").entered();
let _p = tracing::span!(tracing::Level::INFO, "FileChange::apply").entered();
if let Some(roots) = self.roots {
for (idx, root) in roots.into_iter().enumerate() {
let root_id = SourceRootId(idx as u32);
Expand Down
2 changes: 1 addition & 1 deletion crates/base-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn toolchain_channel(db: &dyn SourceDatabase, krate: CrateId) -> Option<ReleaseC
}

fn parse(db: &dyn SourceDatabase, file_id: FileId) -> Parse<ast::SourceFile> {
let _p = tracing::span!(tracing::Level::INFO, "parse_query", ?file_id).entered();
let _p = tracing::span!(tracing::Level::INFO, "parse", ?file_id).entered();
let text = db.file_text(file_id);
// FIXME: Edition based parsing
SourceFile::parse(&text, span::Edition::CURRENT)
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/chalk_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ pub(crate) fn impl_datum_query(
krate: CrateId,
impl_id: ImplId,
) -> Arc<ImplDatum> {
let _p = tracing::span!(tracing::Level::INFO, "impl_datum").entered();
let _p = tracing::span!(tracing::Level::INFO, "impl_datum_query").entered();
debug!("impl_datum {:?}", impl_id);
let impl_: hir_def::ImplId = from_chalk(db, impl_id);
impl_def_datum(db, krate, impl_id, impl_)
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/method_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ pub(crate) fn incoherent_inherent_impl_crates(
krate: CrateId,
fp: TyFingerprint,
) -> SmallVec<[CrateId; 2]> {
let _p = tracing::span!(tracing::Level::INFO, "inherent_impl_crates_query").entered();
let _p = tracing::span!(tracing::Level::INFO, "incoherent_inherent_impl_crates").entered();
let mut res = SmallVec::new();
let crate_graph = db.crate_graph();

Expand Down
2 changes: 1 addition & 1 deletion crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4495,7 +4495,7 @@ impl Type {
name: Option<&Name>,

Check warning on line 4495 in crates/hir/src/lib.rs

View workflow job for this annotation

GitHub Actions / Rust (ubuntu-latest)

Diff in /home/runner/work/rust-analyzer/rust-analyzer/crates/hir/src/lib.rs
mut callback: impl FnMut(Function) -> Option<T>,
) -> Option<T> {
let _p = tracing::span!(tracing::Level::INFO, "iterate_method_candidates").entered();
let _p = tracing::span!(tracing::Level::INFO, "iterate_method_candidates_with_traits").entered();
let mut slot = None;

self.iterate_method_candidates_dyn(
Expand Down
4 changes: 2 additions & 2 deletions crates/hir/src/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ impl<'db> SemanticsImpl<'db> {
mut token: SyntaxToken,
f: &mut dyn FnMut(InFile<SyntaxToken>) -> ControlFlow<()>,
) {
let _p = tracing::span!(tracing::Level::INFO, "descend_into_macros").entered();
let _p = tracing::span!(tracing::Level::INFO, "descend_into_macros_impl").entered();
let (sa, span, file_id) =
match token.parent().and_then(|parent| self.analyze_no_infer(&parent)) {
Some(sa) => match sa.file_id.file_id() {
Expand Down Expand Up @@ -1372,7 +1372,7 @@ impl<'db> SemanticsImpl<'db> {
offset: Option<TextSize>,
infer_body: bool,
) -> Option<SourceAnalyzer> {
let _p = tracing::span!(tracing::Level::INFO, "Semantics::analyze_impl").entered();
let _p = tracing::span!(tracing::Level::INFO, "SemanticsImpl::analyze_impl").entered();
let node = self.find_file(node);

let container = self.with_ctx(|ctx| ctx.find_container(node))?;
Expand Down
2 changes: 1 addition & 1 deletion crates/hir/src/semantics/source_to_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub(super) struct SourceToDefCtx<'a, 'b> {

impl SourceToDefCtx<'_, '_> {
pub(super) fn file_to_def(&self, file: FileId) -> SmallVec<[ModuleId; 1]> {
let _p = tracing::span!(tracing::Level::INFO, "SourceBinder::file_to_module_def").entered();
let _p = tracing::span!(tracing::Level::INFO, "SourceToDefCtx::file_to_def").entered();
let mut mods = SmallVec::new();
for &crate_id in self.db.relevant_crates(file).iter() {
// Note: `mod` declarations in block modules cannot be supported here
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-completion/src/completions/flyimport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ fn import_on_the_fly_pat_(
position: SyntaxNode,
potential_import_name: String,
) -> Option<()> {
let _p = tracing::span!(tracing::Level::INFO, "import_on_the_fly_pat", ?potential_import_name)
let _p = tracing::span!(tracing::Level::INFO, "import_on_the_fly_pat_", ?potential_import_name)
.entered();

ImportScope::find_insert_use_container(&position, &ctx.sema)?;
Expand Down
6 changes: 3 additions & 3 deletions crates/ide-completion/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ fn render_resolution_pat(
import_to_add: Option<LocatedImport>,
resolution: ScopeDef,
) -> Builder {
let _p = tracing::span!(tracing::Level::INFO, "render_resolution").entered();
let _p = tracing::span!(tracing::Level::INFO, "render_resolution_pat").entered();
use hir::ModuleDef::*;

if let ScopeDef::ModuleDef(Macro(mac)) = resolution {
Expand All @@ -386,7 +386,7 @@ fn render_resolution_path(
import_to_add: Option<LocatedImport>,
resolution: ScopeDef,
) -> Builder {
let _p = tracing::span!(tracing::Level::INFO, "render_resolution").entered();
let _p = tracing::span!(tracing::Level::INFO, "render_resolution_path").entered();
use hir::ModuleDef::*;

match resolution {
Expand Down Expand Up @@ -494,7 +494,7 @@ fn render_resolution_simple_(
import_to_add: Option<LocatedImport>,
resolution: ScopeDef,
) -> Builder {
let _p = tracing::span!(tracing::Level::INFO, "render_resolution").entered();
let _p = tracing::span!(tracing::Level::INFO, "render_resolution_simple_").entered();

let db = ctx.db();
let ctx = ctx.import_to_add(import_to_add);
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-completion/src/render/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub(crate) fn render_variant_lit(
variant: hir::Variant,
path: Option<hir::ModPath>,
) -> Option<Builder> {
let _p = tracing::span!(tracing::Level::INFO, "render_enum_variant").entered();
let _p = tracing::span!(tracing::Level::INFO, "render_variant_lit").entered();
let db = ctx.db();

let name = local_name.unwrap_or_else(|| variant.name(db));
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-completion/src/render/macro_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub(crate) fn render_macro_pat(
name: hir::Name,
macro_: hir::Macro,
) -> Builder {
let _p = tracing::span!(tracing::Level::INFO, "render_macro").entered();
let _p = tracing::span!(tracing::Level::INFO, "render_macro_pat").entered();
render(ctx, false, false, false, name, macro_)
}

Expand Down
14 changes: 7 additions & 7 deletions crates/ide-db/src/imports/import_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl ImportAssets {
prefer_prelude: bool,
) -> impl Iterator<Item = LocatedImport> {
let _p =
tracing::span!(tracing::Level::INFO, "import_assets::search_for_imports").entered();
tracing::span!(tracing::Level::INFO, "ImportAssets::search_for_imports").entered();
self.search_for(sema, Some(prefix_kind), prefer_no_std, prefer_prelude)
}

Expand All @@ -221,7 +221,7 @@ impl ImportAssets {
prefer_no_std: bool,
prefer_prelude: bool,
) -> impl Iterator<Item = LocatedImport> {
let _p = tracing::span!(tracing::Level::INFO, "import_assets::search_for_relative_paths")
let _p = tracing::span!(tracing::Level::INFO, "ImportAssets::search_for_relative_paths")
.entered();
self.search_for(sema, None, prefer_no_std, prefer_prelude)
}
Expand Down Expand Up @@ -263,7 +263,7 @@ impl ImportAssets {
prefer_no_std: bool,
prefer_prelude: bool,
) -> impl Iterator<Item = LocatedImport> {
let _p = tracing::span!(tracing::Level::INFO, "import_assets::search_for").entered();
let _p = tracing::span!(tracing::Level::INFO, "ImportAssets::search_for").entered();

let scope = match sema.scope(&self.candidate_node) {
Some(it) => it,
Expand Down Expand Up @@ -308,7 +308,7 @@ impl ImportAssets {
}

fn scope_definitions(&self, sema: &Semantics<'_, RootDatabase>) -> FxHashSet<ScopeDef> {
let _p = tracing::span!(tracing::Level::INFO, "import_assets::scope_definitions").entered();
let _p = tracing::span!(tracing::Level::INFO, "ImportAssets::scope_definitions").entered();
let mut scope_definitions = FxHashSet::default();
if let Some(scope) = sema.scope(&self.candidate_node) {
scope.process_all_names(&mut |_, scope_def| {
Expand All @@ -327,7 +327,7 @@ fn path_applicable_imports(
scope_filter: impl Fn(ItemInNs) -> bool + Copy,
) -> FxHashSet<LocatedImport> {
let _p =
tracing::span!(tracing::Level::INFO, "import_assets::path_applicable_imports").entered();
tracing::span!(tracing::Level::INFO, "ImportAssets::path_applicable_imports").entered();

match &path_candidate.qualifier {
None => {
Expand Down Expand Up @@ -374,7 +374,7 @@ fn import_for_item(
original_item: ItemInNs,
scope_filter: impl Fn(ItemInNs) -> bool,
) -> Option<LocatedImport> {
let _p = tracing::span!(tracing::Level::INFO, "import_assets::import_for_item").entered();
let _p = tracing::span!(tracing::Level::INFO, "ImportAssets::import_for_item").entered();
let [first_segment, ..] = unresolved_qualifier else { return None };

let item_as_assoc = item_as_assoc(db, original_item);
Expand Down Expand Up @@ -509,7 +509,7 @@ fn trait_applicable_items(
scope_filter: impl Fn(hir::Trait) -> bool,
) -> FxHashSet<LocatedImport> {
let _p =
tracing::span!(tracing::Level::INFO, "import_assets::trait_applicable_items").entered();
tracing::span!(tracing::Level::INFO, "ImportAssets::trait_applicable_items").entered();

let db = sema.db;

Expand Down
2 changes: 1 addition & 1 deletion crates/ide-db/src/imports/insert_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ fn insert_use_with_alias_option(
cfg: &InsertUseConfig,
alias: Option<ast::Rename>,
) {
let _p = tracing::span!(tracing::Level::INFO, "insert_use").entered();
let _p = tracing::span!(tracing::Level::INFO, "insert_use_with_alias_option").entered();
let mut mb = match cfg.granularity {
ImportGranularity::Crate => Some(MergeBehavior::Crate),
ImportGranularity::Module => Some(MergeBehavior::Module),
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-db/src/prime_caches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn parallel_prime_caches(
num_worker_threads: u8,
cb: &(dyn Fn(ParallelPrimeCachesProgress) + Sync),
) {
let _p = tracing::span!(tracing::Level::INFO, "prime_caches").entered();
let _p = tracing::span!(tracing::Level::INFO, "parallel_prime_caches").entered();

let graph = db.crate_graph();
let mut crates_to_prime = {
Expand Down
2 changes: 1 addition & 1 deletion crates/ide/src/inlay_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ pub(crate) fn inlay_hints_resolve(
config: &InlayHintsConfig,
hasher: impl Fn(&InlayHint) -> u64,
) -> Option<InlayHint> {
let _p = tracing::span!(tracing::Level::INFO, "inlay_hints").entered();
let _p = tracing::span!(tracing::Level::INFO, "inlay_hints_resolve").entered();
let sema = Semantics::new(db);
let file = sema.parse(file_id);
let file = file.syntax();
Expand Down
2 changes: 1 addition & 1 deletion crates/load-cargo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ fn load_crate_graph(
}

Check warning on line 352 in crates/load-cargo/src/lib.rs

View workflow job for this annotation

GitHub Actions / Rust (ubuntu-latest)

Diff in /home/runner/work/rust-analyzer/rust-analyzer/crates/load-cargo/src/lib.rs
}
vfs::loader::Message::Loaded { files } | vfs::loader::Message::Changed { files } => {
let _p = tracing::span!(Level::INFO, "LoadCargo::load_file_contents").entered();
let _p = tracing::span!(Level::INFO, "load_cargo::load_crate_craph/LoadedChanged").entered();
for (path, contents) in files {
vfs.set_file_contents(path.into(), contents);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/proc-macro-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl ProcMacroServer {
}

pub fn load_dylib(&self, dylib: MacroDylib) -> Result<Vec<ProcMacro>, ServerError> {
let _p = tracing::span!(tracing::Level::INFO, "ProcMacroClient::load_dylib").entered();
let _p = tracing::span!(tracing::Level::INFO, "ProcMacroServer::load_dylib").entered();
let macros =
self.process.lock().unwrap_or_else(|e| e.into_inner()).find_proc_macros(&dylib.path)?;

Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/cli/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::cli::{flags, read_stdin};

impl flags::Parse {
pub fn run(self) -> anyhow::Result<()> {
let _p = tracing::span!(tracing::Level::INFO, "parsing").entered();
let _p = tracing::span!(tracing::Level::INFO, "flags::Parse::run").entered();
let text = read_stdin()?;
let file = SourceFile::parse(&text, Edition::CURRENT).tree();
if !self.no_dump {
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/handlers/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
}

pub(crate) fn handle_cancel_flycheck(state: &mut GlobalState, _: ()) -> anyhow::Result<()> {
let _p = tracing::span!(tracing::Level::INFO, "handle_stop_flycheck").entered();
let _p = tracing::span!(tracing::Level::INFO, "handle_cancel_flycheck").entered();
state.flycheck.iter().for_each(|flycheck| flycheck.cancel());
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/handlers/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1841,7 +1841,7 @@ pub(crate) fn handle_view_recursive_memory_layout(
snap: GlobalStateSnapshot,
params: lsp_types::TextDocumentPositionParams,
) -> anyhow::Result<Option<lsp_ext::RecursiveMemoryLayout>> {
let _p = tracing::span!(tracing::Level::INFO, "view_recursive_memory_layout").entered();
let _p = tracing::span!(tracing::Level::INFO, "handle_view_recursive_memory_layout").entered();
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
let line_index = snap.file_line_index(file_id)?;
let offset = from_proto::offset(&line_index, params.position)?;
Expand Down

0 comments on commit da92c1f

Please sign in to comment.