Skip to content

Commit

Permalink
Auto merge of rust-lang#17356 - Wilfred:span_shorthand, r=lnicola
Browse files Browse the repository at this point in the history
chore: Prefer tracing span shorthand macros

Use `info_span!()` and `debug_span!()` rather than the more verbose `tracing::span!(tracing::Level::INFO)`.
  • Loading branch information
bors committed Jun 7, 2024
2 parents 4739660 + 22ee477 commit 07034ff
Show file tree
Hide file tree
Showing 82 changed files with 240 additions and 275 deletions.
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/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, "FileChange::apply").entered();
let _p = tracing::info_span!("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 src/tools/rust-analyzer/crates/base-db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ impl CrateGraph {
from: CrateId,
dep: Dependency,
) -> Result<(), CyclicDependenciesError> {
let _p = tracing::span!(tracing::Level::INFO, "add_dep").entered();
let _p = tracing::info_span!("add_dep").entered();

self.check_cycle_after_dependency(from, dep.crate_id)?;

Expand Down
4 changes: 2 additions & 2 deletions src/tools/rust-analyzer/crates/base-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,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", ?file_id).entered();
let _p = tracing::info_span!("parse", ?file_id).entered();
let text = db.file_text(file_id);
// FIXME: Edition based parsing
SourceFile::parse(&text, span::Edition::CURRENT)
Expand Down Expand Up @@ -187,7 +187,7 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
}

fn relevant_crates(&self, file_id: FileId) -> Arc<[CrateId]> {
let _p = tracing::span!(tracing::Level::INFO, "relevant_crates").entered();
let _p = tracing::info_span!("relevant_crates").entered();
let source_root = self.0.file_source_root(file_id);
self.0.source_root_crates(source_root)
}
Expand Down
4 changes: 2 additions & 2 deletions src/tools/rust-analyzer/crates/hir-def/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Attrs {
db: &dyn DefDatabase,
v: VariantId,
) -> Arc<ArenaMap<LocalFieldId, Attrs>> {
let _p = tracing::span!(tracing::Level::INFO, "fields_attrs_query").entered();
let _p = tracing::info_span!("fields_attrs_query").entered();
// FIXME: There should be some proper form of mapping between item tree field ids and hir field ids
let mut res = ArenaMap::default();

Expand Down Expand Up @@ -321,7 +321,7 @@ impl AttrsWithOwner {
}

pub(crate) fn attrs_query(db: &dyn DefDatabase, def: AttrDefId) -> Attrs {
let _p = tracing::span!(tracing::Level::INFO, "attrs_query").entered();
let _p = tracing::info_span!("attrs_query").entered();
// FIXME: this should use `Trace` to avoid duplication in `source_map` below
let raw_attrs = match def {
AttrDefId::ModuleId(module) => {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl Body {
db: &dyn DefDatabase,
def: DefWithBodyId,
) -> (Arc<Body>, Arc<BodySourceMap>) {
let _p = tracing::span!(tracing::Level::INFO, "body_with_source_map_query").entered();
let _p = tracing::info_span!("body_with_source_map_query").entered();
let mut params = None;

let mut is_async_fn = false;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl ImplData {
db: &dyn DefDatabase,
id: ImplId,
) -> (Arc<ImplData>, DefDiagnostics) {
let _p = tracing::span!(tracing::Level::INFO, "impl_data_with_diagnostics_query").entered();
let _p = tracing::info_span!("impl_data_with_diagnostics_query").entered();
let ItemLoc { container: module_id, id: tree_id } = id.lookup(db);

let item_tree = tree_id.item_tree(db);
Expand Down
4 changes: 2 additions & 2 deletions src/tools/rust-analyzer/crates/hir-def/src/find_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn find_path(
ignore_local_imports: bool,
mut cfg: ImportPathConfig,
) -> Option<ModPath> {
let _p = tracing::span!(tracing::Level::INFO, "find_path").entered();
let _p = tracing::info_span!("find_path").entered();

// - if the item is a builtin, it's in scope
if let ItemInNs::Types(ModuleDefId::BuiltinType(builtin)) = item {
Expand Down Expand Up @@ -474,7 +474,7 @@ fn find_local_import_locations(
def_map: &DefMap,
mut cb: impl FnMut(&Name, ModuleId),
) {
let _p = tracing::span!(tracing::Level::INFO, "find_local_import_locations").entered();
let _p = tracing::info_span!("find_local_import_locations").entered();

// `from` can import anything below `from` with visibility of at least `from`, and anything
// above `from` with any visibility. That means we do not need to descend into private siblings
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ impl GenericParams {
db: &dyn DefDatabase,
def: GenericDefId,
) -> Interned<GenericParams> {
let _p = tracing::span!(tracing::Level::INFO, "generic_params_query").entered();
let _p = tracing::info_span!("generic_params_query").entered();

let krate = def.module(db).krate;
let cfg_options = db.crate_graph();
Expand Down
8 changes: 4 additions & 4 deletions src/tools/rust-analyzer/crates/hir-def/src/import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl ImportMap {
}

pub(crate) fn import_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<Self> {
let _p = tracing::span!(tracing::Level::INFO, "import_map_query").entered();
let _p = tracing::info_span!("import_map_query").entered();

let map = Self::collect_import_map(db, krate);

Expand Down Expand Up @@ -124,7 +124,7 @@ impl ImportMap {
}

fn collect_import_map(db: &dyn DefDatabase, krate: CrateId) -> ImportMapIndex {
let _p = tracing::span!(tracing::Level::INFO, "collect_import_map").entered();
let _p = tracing::info_span!("collect_import_map").entered();

let def_map = db.crate_def_map(krate);
let mut map = FxIndexMap::default();
Expand Down Expand Up @@ -214,7 +214,7 @@ impl ImportMap {
is_type_in_ns: bool,
trait_import_info: &ImportInfo,
) {
let _p = tracing::span!(tracing::Level::INFO, "collect_trait_assoc_items").entered();
let _p = tracing::info_span!("collect_trait_assoc_items").entered();
for &(ref assoc_item_name, item) in &db.trait_data(tr).items {
let module_def_id = match item {
AssocItemId::FunctionId(f) => ModuleDefId::from(f),
Expand Down Expand Up @@ -396,7 +396,7 @@ pub fn search_dependencies(
krate: CrateId,
query: &Query,
) -> FxHashSet<ItemInNs> {
let _p = tracing::span!(tracing::Level::INFO, "search_dependencies", ?query).entered();
let _p = tracing::info_span!("search_dependencies", ?query).entered();

let graph = db.crate_graph();

Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub struct ItemTree {

impl ItemTree {
pub(crate) fn file_item_tree_query(db: &dyn DefDatabase, file_id: HirFileId) -> Arc<ItemTree> {
let _p = tracing::span!(tracing::Level::INFO, "file_item_tree_query", ?file_id).entered();
let _p = tracing::info_span!("file_item_tree_query", ?file_id).entered();

let syntax = db.parse_or_expand(file_id);

Expand Down
10 changes: 5 additions & 5 deletions src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl LangItems {
db: &dyn DefDatabase,
krate: CrateId,
) -> Option<Arc<LangItems>> {
let _p = tracing::span!(tracing::Level::INFO, "crate_lang_items_query").entered();
let _p = tracing::info_span!("crate_lang_items_query").entered();

let mut lang_items = LangItems::default();

Expand Down Expand Up @@ -163,7 +163,7 @@ impl LangItems {
start_crate: CrateId,
item: LangItem,
) -> Option<LangItemTarget> {
let _p = tracing::span!(tracing::Level::INFO, "lang_item_query").entered();
let _p = tracing::info_span!("lang_item_query").entered();
if let Some(target) =
db.crate_lang_items(start_crate).and_then(|it| it.items.get(&item).copied())
{
Expand All @@ -183,7 +183,7 @@ impl LangItems {
) where
T: Into<AttrDefId> + Copy,
{
let _p = tracing::span!(tracing::Level::INFO, "collect_lang_item").entered();
let _p = tracing::info_span!("collect_lang_item").entered();
if let Some(lang_item) = lang_attr(db, item.into()) {
self.items.entry(lang_item).or_insert_with(|| constructor(item));
}
Expand All @@ -199,7 +199,7 @@ pub(crate) fn notable_traits_in_deps(
db: &dyn DefDatabase,
krate: CrateId,
) -> Arc<[Arc<[TraitId]>]> {
let _p = tracing::span!(tracing::Level::INFO, "notable_traits_in_deps", ?krate).entered();
let _p = tracing::info_span!("notable_traits_in_deps", ?krate).entered();
let crate_graph = db.crate_graph();

Arc::from_iter(
Expand All @@ -208,7 +208,7 @@ pub(crate) fn notable_traits_in_deps(
}

pub(crate) fn crate_notable_traits(db: &dyn DefDatabase, krate: CrateId) -> Option<Arc<[TraitId]>> {
let _p = tracing::span!(tracing::Level::INFO, "crate_notable_traits", ?krate).entered();
let _p = tracing::info_span!("crate_notable_traits", ?krate).entered();

let mut traits = Vec::new();

Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/nameres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ impl DefMap {
let crate_graph = db.crate_graph();
let krate = &crate_graph[crate_id];
let name = krate.display_name.as_deref().unwrap_or_default();
let _p = tracing::span!(tracing::Level::INFO, "crate_def_map_query", ?name).entered();
let _p = tracing::info_span!("crate_def_map_query", ?name).entered();

let module_data = ModuleData::new(
ModuleOrigin::CrateRoot { definition: krate.root_file_id },
Expand Down
16 changes: 8 additions & 8 deletions src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ struct DefCollector<'a> {

impl DefCollector<'_> {
fn seed_with_top_level(&mut self) {
let _p = tracing::span!(tracing::Level::INFO, "seed_with_top_level").entered();
let _p = tracing::info_span!("seed_with_top_level").entered();

let crate_graph = self.db.crate_graph();
let file_id = crate_graph[self.def_map.krate].root_file_id;
Expand Down Expand Up @@ -411,17 +411,17 @@ impl DefCollector<'_> {
}

fn resolution_loop(&mut self) {
let _p = tracing::span!(tracing::Level::INFO, "DefCollector::resolution_loop").entered();
let _p = tracing::info_span!("DefCollector::resolution_loop").entered();

// main name resolution fixed-point loop.
let mut i = 0;
'resolve_attr: loop {
let _p = tracing::span!(tracing::Level::INFO, "resolve_macros loop").entered();
let _p = tracing::info_span!("resolve_macros loop").entered();
'resolve_macros: loop {
self.db.unwind_if_cancelled();

{
let _p = tracing::span!(tracing::Level::INFO, "resolve_imports loop").entered();
let _p = tracing::info_span!("resolve_imports loop").entered();

'resolve_imports: loop {
if self.resolve_imports() == ReachedFixedPoint::Yes {
Expand All @@ -447,7 +447,7 @@ impl DefCollector<'_> {
}

fn collect(&mut self) {
let _p = tracing::span!(tracing::Level::INFO, "DefCollector::collect").entered();
let _p = tracing::info_span!("DefCollector::collect").entered();

self.resolution_loop();

Expand Down Expand Up @@ -795,7 +795,7 @@ impl DefCollector<'_> {
}

fn resolve_import(&self, module_id: LocalModuleId, import: &Import) -> PartialResolvedImport {
let _p = tracing::span!(tracing::Level::INFO, "resolve_import", import_path = %import.path.display(self.db.upcast()))
let _p = tracing::info_span!("resolve_import", import_path = %import.path.display(self.db.upcast()))
.entered();
tracing::debug!("resolving import: {:?} ({:?})", import, self.def_map.data.edition);
match import.source {
Expand Down Expand Up @@ -857,7 +857,7 @@ impl DefCollector<'_> {
}

fn record_resolved_import(&mut self, directive: &ImportDirective) {
let _p = tracing::span!(tracing::Level::INFO, "record_resolved_import").entered();
let _p = tracing::info_span!("record_resolved_import").entered();

let module_id = directive.module_id;
let import = &directive.import;
Expand Down Expand Up @@ -1422,7 +1422,7 @@ impl DefCollector<'_> {
fn finish(mut self) -> DefMap {
// Emit diagnostics for all remaining unexpanded macros.

let _p = tracing::span!(tracing::Level::INFO, "DefCollector::finish").entered();
let _p = tracing::info_span!("DefCollector::finish").entered();

for directive in &self.unresolved_macros {
match &directive.kind {
Expand Down
4 changes: 2 additions & 2 deletions src/tools/rust-analyzer/crates/hir-def/src/per_ns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl PerNs {
}

pub fn filter_visibility(self, mut f: impl FnMut(Visibility) -> bool) -> PerNs {
let _p = tracing::span!(tracing::Level::INFO, "PerNs::filter_visibility").entered();
let _p = tracing::info_span!("PerNs::filter_visibility").entered();
PerNs {
types: self.types.filter(|&(_, v, _)| f(v)),
values: self.values.filter(|&(_, v, _)| f(v)),
Expand Down Expand Up @@ -119,7 +119,7 @@ impl PerNs {
}

pub fn iter_items(self) -> impl Iterator<Item = (ItemInNs, Option<ImportOrExternCrate>)> {
let _p = tracing::span!(tracing::Level::INFO, "PerNs::iter_items").entered();
let _p = tracing::info_span!("PerNs::iter_items").entered();
self.types
.map(|it| (ItemInNs::Types(it.0), it.2))
.into_iter()
Expand Down
4 changes: 2 additions & 2 deletions src/tools/rust-analyzer/crates/hir-expand/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ fn parse_macro_expansion(
db: &dyn ExpandDatabase,
macro_file: MacroFileId,
) -> ExpandResult<(Parse<SyntaxNode>, Arc<ExpansionSpanMap>)> {
let _p = tracing::span!(tracing::Level::INFO, "parse_macro_expansion").entered();
let _p = tracing::info_span!("parse_macro_expansion").entered();
let loc = db.lookup_intern_macro_call(macro_file.macro_call_id);
let edition = loc.def.edition;
let expand_to = loc.expand_to();
Expand Down Expand Up @@ -588,7 +588,7 @@ fn macro_expand(
macro_call_id: MacroCallId,
loc: MacroCallLoc,
) -> ExpandResult<(CowArc<tt::Subtree>, MatchedArmIndex)> {
let _p = tracing::span!(tracing::Level::INFO, "macro_expand").entered();
let _p = tracing::info_span!("macro_expand").entered();

let (ExpandResult { value: (tt, matched_arm), err }, span) = match loc.def.kind {
MacroDefKind::ProcMacro(..) => {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-expand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ impl ExpansionInfo {
}

pub fn new(db: &dyn ExpandDatabase, macro_file: MacroFileId) -> ExpansionInfo {
let _p = tracing::span!(tracing::Level::INFO, "ExpansionInfo::new").entered();
let _p = tracing::info_span!("ExpansionInfo::new").entered();
let loc = db.lookup_intern_macro_call(macro_file.macro_call_id);

let arg_tt = loc.kind.arg(db);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub(crate) fn deref_by_trait(
table @ &mut InferenceTable { db, .. }: &mut InferenceTable<'_>,
ty: Ty,
) -> Option<Ty> {
let _p = tracing::span!(tracing::Level::INFO, "deref_by_trait").entered();
let _p = tracing::info_span!("deref_by_trait").entered();
if table.resolve_ty_shallow(&ty).inference_var(Interner).is_some() {
// don't try to deref unknown variables
return None;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/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_query").entered();
let _p = tracing::info_span!("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
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mod allow {
}

pub fn incorrect_case(db: &dyn HirDatabase, owner: ModuleDefId) -> Vec<IncorrectCase> {
let _p = tracing::span!(tracing::Level::INFO, "incorrect_case").entered();
let _p = tracing::info_span!("incorrect_case").entered();
let mut validator = DeclValidator::new(db);
validator.validate_item(owner);
validator.sink
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ impl BodyValidationDiagnostic {
owner: DefWithBodyId,
validate_lints: bool,
) -> Vec<BodyValidationDiagnostic> {
let _p =
tracing::span!(tracing::Level::INFO, "BodyValidationDiagnostic::collect").entered();
let _p = tracing::info_span!("BodyValidationDiagnostic::collect").entered();
let infer = db.infer(owner);
let body = db.body(owner);
let mut validator =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
};

pub fn missing_unsafe(db: &dyn HirDatabase, def: DefWithBodyId) -> Vec<ExprId> {
let _p = tracing::span!(tracing::Level::INFO, "missing_unsafe").entered();
let _p = tracing::info_span!("missing_unsafe").entered();

let mut res = Vec::new();
let is_unsafe = match def {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-ty/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub(crate) use closure::{CaptureKind, CapturedItem, CapturedItemWithoutTy};

/// The entry point of type inference.
pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> {
let _p = tracing::span!(tracing::Level::INFO, "infer_query").entered();
let _p = tracing::info_span!("infer_query").entered();
let resolver = def.resolver(db.upcast());
let body = db.body(def);
let mut ctx = InferenceContext::new(db, def, &body, resolver);
Expand Down
3 changes: 1 addition & 2 deletions src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,7 @@ impl<'a> InferenceTable<'a> {
}

pub(crate) fn resolve_obligations_as_possible(&mut self) {
let _span =
tracing::span!(tracing::Level::INFO, "resolve_obligations_as_possible").entered();
let _span = tracing::info_span!("resolve_obligations_as_possible").entered();
let mut changed = true;
let mut obligations = mem::take(&mut self.resolve_obligations_buffer);
while mem::take(&mut changed) {
Expand Down
4 changes: 2 additions & 2 deletions src/tools/rust-analyzer/crates/hir-ty/src/inhabitedness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
// FIXME: Turn this into a query, it can be quite slow
/// Checks whether a type is visibly uninhabited from a particular module.
pub(crate) fn is_ty_uninhabited_from(db: &dyn HirDatabase, ty: &Ty, target_mod: ModuleId) -> bool {
let _p = tracing::span!(tracing::Level::INFO, "is_ty_uninhabited_from", ?ty).entered();
let _p = tracing::info_span!("is_ty_uninhabited_from", ?ty).entered();
let mut uninhabited_from =
UninhabitedFrom { target_mod, db, max_depth: 500, recursive_ty: FxHashSet::default() };
let inhabitedness = ty.visit_with(&mut uninhabited_from, DebruijnIndex::INNERMOST);
Expand All @@ -30,7 +30,7 @@ pub(crate) fn is_enum_variant_uninhabited_from(
subst: &Substitution,
target_mod: ModuleId,
) -> bool {
let _p = tracing::span!(tracing::Level::INFO, "is_enum_variant_uninhabited_from").entered();
let _p = tracing::info_span!("is_enum_variant_uninhabited_from").entered();

let mut uninhabited_from =
UninhabitedFrom { target_mod, db, max_depth: 500, recursive_ty: FxHashSet::default() };
Expand Down
Loading

0 comments on commit 07034ff

Please sign in to comment.