Instrument important fns in AST lowering

This commit is contained in:
Santiago Pastorino 2022-05-20 15:52:56 -03:00
parent 7fe2c4b00d
commit a22aad32eb
No known key found for this signature in database
GPG Key ID: 8131A24E0C79EFAF
3 changed files with 18 additions and 6 deletions

View File

@ -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<T>(
&mut self,
generics: &Generics,

View File

@ -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<NodeId>) -> Res {
let res: Result<Res, ()> = 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 => {

View File

@ -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));