diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index dab4d76857a..d5ed9aa380f 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -19,7 +19,6 @@ use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::Span; use rustc_target::spec::abi; use smallvec::{smallvec, SmallVec}; -use tracing::debug; use std::iter; @@ -117,6 +116,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> { self.owners[def_id] } + #[instrument(level = "debug", skip(self, c))] fn lower_crate(&mut self, c: &Crate) { debug_assert_eq!(self.resolver.local_def_id(CRATE_NODE_ID), CRATE_DEF_ID); @@ -127,6 +127,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> { }) } + #[instrument(level = "debug", skip(self))] fn lower_item(&mut self, item: &Item) { self.with_lctx(item.id, |lctx| hir::OwnerNode::Item(lctx.lower_item(item))) } @@ -485,6 +486,7 @@ impl<'hir> LoweringContext<'_, 'hir> { (ty, self.lower_const_body(span, body)) } + #[instrument(level = "debug", skip(self))] fn lower_use_tree( &mut self, tree: &UseTree, @@ -494,8 +496,6 @@ impl<'hir> LoweringContext<'_, 'hir> { ident: &mut Ident, attrs: Option<&'hir [Attribute]>, ) -> hir::ItemKind<'hir> { - debug!("lower_use_tree(tree={:?})", tree); - let path = &tree.prefix; let segments = prefix.segments.iter().chain(path.segments.iter()).cloned().collect(); @@ -1298,6 +1298,7 @@ impl<'hir> LoweringContext<'_, 'hir> { /// Return the pair of the lowered `generics` as `hir::Generics` and the evaluation of `f` with /// the carried impl trait definitions and bounds. + #[instrument(level = "debug", skip(self, f))] fn lower_generics( &mut self, generics: &Generics, diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 51e5c3384a7..a8a115fe38f 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -37,6 +37,9 @@ #![recursion_limit = "256"] #![allow(rustc::potential_query_instability)] +#[macro_use] +extern crate tracing; + use rustc_ast::visit; use rustc_ast::{self as ast, *}; use rustc_ast_pretty::pprust; @@ -63,7 +66,6 @@ use rustc_span::{Span, DUMMY_SP}; use smallvec::SmallVec; use std::collections::hash_map::Entry; -use tracing::{debug, trace}; macro_rules! arena_vec { ($this:expr; $($x:expr),*) => ( @@ -439,7 +441,7 @@ pub fn lower_crate<'a, 'hir>( arena.alloc(krate) } -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq, Debug)] enum ParamMode { /// Any path in a type context. Explicit, @@ -455,6 +457,7 @@ enum ParenthesizedGenericArgs { } impl<'a, 'hir> LoweringContext<'a, 'hir> { + #[instrument(level = "debug", skip(self, f))] fn with_hir_id_owner( &mut self, owner: NodeId, @@ -599,12 +602,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { self.lower_node_id(node_id) } + #[instrument(level = "trace", skip(self))] fn lower_res(&mut self, res: Res) -> Res { let res: Result = res.apply_id(|id| { let owner = self.current_hir_id_owner; let local_id = self.node_id_to_local_id.get(&id).copied().ok_or(())?; Ok(hir::HirId { owner, local_id }) }); + trace!(?res); + // We may fail to find a HirId when the Res points to a Local from an enclosing HIR owner. // This can happen when trying to lower the return type `x` in erroneous code like // async fn foo(x: u8) -> x {} @@ -851,6 +857,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { /// ``` /// /// returns a `hir::TypeBinding` representing `Item`. + #[instrument(level = "debug", skip(self))] fn lower_assoc_ty_constraint( &mut self, constraint: &AssocConstraint, @@ -1011,6 +1018,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { err.emit(); } + #[instrument(level = "debug", skip(self))] fn lower_generic_arg( &mut self, arg: &ast::GenericArg, @@ -1081,6 +1089,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } } + #[instrument(level = "debug", skip(self))] fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext) -> &'hir hir::Ty<'hir> { self.arena.alloc(self.lower_ty_direct(t, itctx)) } @@ -1737,6 +1746,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { ) } + #[instrument(level = "trace", skip(self))] fn lower_param_bound( &mut self, tpb: &GenericBound, @@ -1862,6 +1872,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { self.arena.alloc_from_iter(self.lower_generic_params_mut(params)) } + #[instrument(level = "trace", skip(self))] fn lower_generic_param(&mut self, param: &GenericParam) -> hir::GenericParam<'hir> { let (name, kind) = match param.kind { GenericParamKind::Lifetime => { diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index d56974b773d..ac63a075ac6 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -15,6 +15,7 @@ use smallvec::smallvec; use tracing::debug; impl<'a, 'hir> LoweringContext<'a, 'hir> { + #[instrument(level = "trace", skip(self))] pub(crate) fn lower_qpath( &mut self, id: NodeId, @@ -23,7 +24,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { param_mode: ParamMode, itctx: ImplTraitContext, ) -> hir::QPath<'hir> { - debug!("lower_qpath(id: {:?}, qself: {:?}, p: {:?})", id, qself, p); let qself_position = qself.as_ref().map(|q| q.position); let qself = qself.as_ref().map(|q| self.lower_ty(&q.ty, itctx));