Skip to content

Commit e3a738a

Browse files
committed
Add instrument and debug calls
1 parent 3c72788 commit e3a738a

File tree

8 files changed

+33
-15
lines changed

8 files changed

+33
-15
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
660660
/// actually used in the HIR, as that would trigger an assertion in the
661661
/// `HirIdValidator` later on, which makes sure that all `NodeId`s got mapped
662662
/// properly. Calling the method twice with the same `NodeId` is fine though.
663+
#[instrument(level = "debug", skip(self), ret)]
663664
fn lower_node_id(&mut self, ast_node_id: NodeId) -> hir::HirId {
664665
assert_ne!(ast_node_id, DUMMY_NODE_ID);
665666

@@ -693,6 +694,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
693694
}
694695

695696
/// Generate a new `HirId` without a backing `NodeId`.
697+
#[instrument(level = "debug", skip(self), ret)]
696698
fn next_id(&mut self) -> hir::HirId {
697699
let owner = self.current_hir_id_owner;
698700
let local_id = self.item_local_id_counter;
@@ -1381,7 +1383,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13811383
/// added explicitly in the HIR). But this includes all the lifetimes, and we only want to
13821384
/// capture the lifetimes that are referenced in the bounds. Therefore, we add *extra* lifetime parameters
13831385
/// for the lifetimes that get captured (`'x`, in our example above) and reference those.
1384-
#[instrument(level = "debug", skip(self))]
1386+
#[instrument(level = "debug", skip(self), ret)]
13851387
fn lower_opaque_impl_trait(
13861388
&mut self,
13871389
span: Span,
@@ -2143,6 +2145,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21432145
hir::MutTy { ty: self.lower_ty(&mt.ty, itctx), mutbl: mt.mutbl }
21442146
}
21452147

2148+
#[instrument(level = "debug", skip(self), ret)]
21462149
fn lower_param_bounds(
21472150
&mut self,
21482151
bounds: &[GenericBound],
@@ -2159,6 +2162,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21592162
bounds.iter().map(move |bound| self.lower_param_bound(bound, itctx))
21602163
}
21612164

2165+
#[instrument(level = "debug", skip(self), ret)]
21622166
fn lower_generic_and_bounds(
21632167
&mut self,
21642168
node_id: NodeId,

compiler/rustc_infer/src/infer/outlives/verify.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
5050
}
5151
}
5252

53+
#[instrument(level = "debug", skip(self))]
5354
fn param_bound(&self, param_ty: ty::ParamTy) -> VerifyBound<'tcx> {
54-
debug!("param_bound(param_ty={:?})", param_ty);
55-
5655
// Start with anything like `T: 'a` we can scrape from the
5756
// environment. If the environment contains something like
5857
// `for<'a> T: 'a`, then we know that `T` outlives everything.
5958
let declared_bounds_from_env = self.declared_generic_bounds_from_env(param_ty);
59+
debug!(?declared_bounds_from_env);
6060
let mut param_bounds = vec![];
6161
for declared_bound in declared_bounds_from_env {
6262
let bound_region = declared_bound.map_bound(|outlives| outlives.1);
@@ -65,13 +65,15 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
6565
param_bounds.push(VerifyBound::OutlivedBy(region));
6666
} else {
6767
// This is `for<'a> T: 'a`. This means that `T` outlives everything! All done here.
68+
debug!("found that {param_ty:?} outlives any lifetime, returning empty vector");
6869
return VerifyBound::AllBounds(vec![]);
6970
}
7071
}
7172

7273
// Add in the default bound of fn body that applies to all in
7374
// scope type parameters:
7475
if let Some(r) = self.implicit_region_bound {
76+
debug!("adding implicit region bound of {r:?}");
7577
param_bounds.push(VerifyBound::OutlivedBy(r));
7678
}
7779

compiler/rustc_middle/src/ty/generics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ impl<'tcx> GenericPredicates<'tcx> {
328328
}
329329
}
330330

331+
#[instrument(level = "debug", skip(self, tcx))]
331332
fn instantiate_into(
332333
&self,
333334
tcx: TyCtxt<'tcx>,

compiler/rustc_resolve/src/late/lifetimes.rs

+3
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
525525
}
526526
}
527527

528+
#[instrument(level = "debug", skip(self))]
528529
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
529530
match &item.kind {
530531
hir::ItemKind::Impl(hir::Impl { of_trait, .. }) => {
@@ -839,6 +840,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
839840
}
840841
}
841842

843+
#[instrument(level = "debug", skip(self))]
842844
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
843845
use self::hir::TraitItemKind::*;
844846
match trait_item.kind {
@@ -888,6 +890,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
888890
}
889891
}
890892

893+
#[instrument(level = "debug", skip(self))]
891894
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
892895
use self::hir::ImplItemKind::*;
893896
match impl_item.kind {

compiler/rustc_trait_selection/src/traits/wf.rs

+3
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ impl<'tcx> WfPredicates<'tcx> {
434434
}
435435

436436
/// Pushes all the predicates needed to validate that `ty` is WF into `out`.
437+
#[instrument(level = "debug", skip(self))]
437438
fn compute(&mut self, arg: GenericArg<'tcx>) {
438439
let mut walker = arg.walk();
439440
let param_env = self.param_env;
@@ -488,6 +489,8 @@ impl<'tcx> WfPredicates<'tcx> {
488489
}
489490
};
490491

492+
debug!("wf bounds for ty={:?} ty.kind={:#?}", ty, ty.kind());
493+
491494
match *ty.kind() {
492495
ty::Bool
493496
| ty::Char

compiler/rustc_typeck/src/astconv/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2695,6 +2695,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
26952695
result_ty
26962696
}
26972697

2698+
#[instrument(level = "debug", skip(self), ret)]
26982699
fn impl_trait_ty_to_ty(
26992700
&self,
27002701
def_id: DefId,
@@ -2743,9 +2744,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
27432744
});
27442745
debug!("impl_trait_ty_to_ty: substs={:?}", substs);
27452746

2746-
let ty = tcx.mk_opaque(def_id, substs);
2747-
debug!("impl_trait_ty_to_ty: {}", ty);
2748-
ty
2747+
tcx.mk_opaque(def_id, substs)
27492748
}
27502749

27512750
pub fn ty_of_arg(&self, ty: &hir::Ty<'_>, expected_ty: Option<Ty<'tcx>>) -> Ty<'tcx> {

compiler/rustc_typeck/src/collect.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ fn get_new_lifetime_name<'tcx>(
573573

574574
/// Returns the predicates defined on `item_def_id` of the form
575575
/// `X: Foo` where `X` is the type parameter `def_id`.
576+
#[instrument(level = "trace", skip(tcx))]
576577
fn type_param_predicates(
577578
tcx: TyCtxt<'_>,
578579
(item_def_id, def_id, assoc_name): (DefId, LocalDefId, Ident),
@@ -679,7 +680,7 @@ impl<'tcx> ItemCtxt<'tcx> {
679680
assoc_name: Option<Ident>,
680681
) -> Vec<(ty::Predicate<'tcx>, Span)> {
681682
let param_def_id = self.tcx.hir().local_def_id(param_id).to_def_id();
682-
debug!(?param_def_id);
683+
trace!(?param_def_id);
683684
ast_generics
684685
.predicates
685686
.iter()
@@ -708,9 +709,8 @@ impl<'tcx> ItemCtxt<'tcx> {
708709
.collect()
709710
}
710711

712+
#[instrument(level = "trace", skip(self))]
711713
fn bound_defines_assoc_item(&self, b: &hir::GenericBound<'_>, assoc_name: Ident) -> bool {
712-
debug!("bound_defines_assoc_item(b={:?}, assoc_name={:?})", b, assoc_name);
713-
714714
match b {
715715
hir::GenericBound::Trait(poly_trait_ref, _) => {
716716
let trait_ref = &poly_trait_ref.trait_ref;
@@ -2105,11 +2105,10 @@ fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicates<'_> {
21052105

21062106
/// Returns a list of user-specified type predicates for the definition with ID `def_id`.
21072107
/// N.B., this does not include any implied/inferred constraints.
2108+
#[instrument(level = "trace", skip(tcx), ret)]
21082109
fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicates<'_> {
21092110
use rustc_hir::*;
21102111

2111-
debug!("explicit_predicates_of(def_id={:?})", def_id);
2112-
21132112
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
21142113
let node = tcx.hir().get(hir_id);
21152114

@@ -2224,6 +2223,9 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
22242223
+ has_own_self as u32
22252224
+ early_bound_lifetimes_from_generics(tcx, ast_generics).count() as u32;
22262225

2226+
trace!(?predicates);
2227+
trace!(?ast_generics);
2228+
22272229
// Collect the predicates that were written inline by the user on each
22282230
// type parameter (e.g., `<T: Foo>`).
22292231
for param in ast_generics.params {
@@ -2244,7 +2246,9 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
22442246
Some((param.hir_id, ast_generics.predicates)),
22452247
param.span,
22462248
);
2249+
trace!(?bounds);
22472250
predicates.extend(bounds.predicates(tcx, param_ty));
2251+
trace!(?predicates);
22482252
}
22492253
GenericParamKind::Const { .. } => {
22502254
// Bounds on const parameters are currently not possible.
@@ -2253,6 +2257,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
22532257
}
22542258
}
22552259

2260+
trace!(?predicates);
22562261
// Add in the bounds that appear in the where-clause.
22572262
for predicate in ast_generics.predicates {
22582263
match predicate {
@@ -2338,12 +2343,10 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
23382343
);
23392344
}
23402345

2341-
let result = ty::GenericPredicates {
2346+
ty::GenericPredicates {
23422347
parent: generics.parent,
23432348
predicates: tcx.arena.alloc_from_iter(predicates),
2344-
};
2345-
debug!("explicit_predicates_of(def_id={:?}) = {:?}", def_id, result);
2346-
result
2349+
}
23472350
}
23482351

23492352
fn const_evaluatable_predicates_of<'tcx>(

compiler/rustc_typeck/src/collect/item_bounds.rs

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ fn associated_type_bounds<'tcx>(
5353
/// impl trait it isn't possible to write a suitable predicate on the
5454
/// containing function and for type-alias impl trait we don't have a backwards
5555
/// compatibility issue.
56+
#[instrument(level = "trace", skip(tcx), ret)]
5657
fn opaque_type_bounds<'tcx>(
5758
tcx: TyCtxt<'tcx>,
5859
opaque_def_id: DefId,
@@ -67,6 +68,8 @@ fn opaque_type_bounds<'tcx>(
6768
let mut bounds = <dyn AstConv<'_>>::compute_bounds(&icx, item_ty, ast_bounds);
6869
// Opaque types are implicitly sized unless a `?Sized` bound is found
6970
<dyn AstConv<'_>>::add_implicitly_sized(&icx, &mut bounds, ast_bounds, None, span);
71+
debug!(?bounds);
72+
7073
tcx.arena.alloc_from_iter(bounds.predicates(tcx, item_ty))
7174
})
7275
}

0 commit comments

Comments
 (0)