Skip to content

Commit b8d2560

Browse files
committed
Use tracing spans in rustc_trait_selection
1 parent 7b06cb1 commit b8d2560

File tree

5 files changed

+166
-290
lines changed

5 files changed

+166
-290
lines changed

compiler/rustc_trait_selection/src/traits/fulfill.rs

+13-20
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
120120
&mut self,
121121
selcx: &mut SelectionContext<'a, 'tcx>,
122122
) -> Result<(), Vec<FulfillmentError<'tcx>>> {
123-
debug!("select(obligation-forest-size={})", self.predicates.len());
123+
let span = debug_span!("select", obligation_forest_size = ?self.predicates.len());
124+
let _enter = span.enter();
124125

125126
let mut errors = Vec::new();
126127

@@ -173,7 +174,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
173174
projection_ty: ty::ProjectionTy<'tcx>,
174175
cause: ObligationCause<'tcx>,
175176
) -> Ty<'tcx> {
176-
debug!("normalize_projection_type(projection_ty={:?})", projection_ty);
177+
debug!(?projection_ty, "normalize_projection_type");
177178

178179
debug_assert!(!projection_ty.has_escaping_bound_vars());
179180

@@ -191,7 +192,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
191192
);
192193
self.register_predicate_obligations(infcx, obligations);
193194

194-
debug!("normalize_projection_type: result={:?}", normalized_ty);
195+
debug!(?normalized_ty);
195196

196197
normalized_ty
197198
}
@@ -205,7 +206,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
205206
// debug output much nicer to read and so on.
206207
let obligation = infcx.resolve_vars_if_possible(&obligation);
207208

208-
debug!("register_predicate_obligation(obligation={:?})", obligation);
209+
debug!(?obligation, "register_predicate_obligation");
209210

210211
assert!(!infcx.is_in_snapshot() || self.usable_in_snapshot);
211212

@@ -342,7 +343,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
342343
self.selcx.infcx().resolve_vars_if_possible(&obligation.predicate);
343344
}
344345

345-
debug!("process_obligation: obligation = {:?} cause = {:?}", obligation, obligation.cause);
346+
debug!(?obligation, ?obligation.cause, "process_obligation");
346347

347348
let infcx = self.selcx.infcx();
348349

@@ -509,7 +510,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
509510
}
510511

511512
ty::PredicateAtom::ConstEquate(c1, c2) => {
512-
debug!("equating consts: c1={:?} c2={:?}", c1, c2);
513+
debug!(?c1, ?c2, "equating consts");
513514
if self.selcx.tcx().features().const_evaluatable_checked {
514515
// FIXME: we probably should only try to unify abstract constants
515516
// if the constants depend on generic parameters.
@@ -601,6 +602,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
601602
}
602603
}
603604

605+
#[instrument(level = "debug", skip(self, obligation, stalled_on))]
604606
fn process_trait_obligation(
605607
&mut self,
606608
obligation: &PredicateObligation<'tcx>,
@@ -613,26 +615,20 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
613615
// FIXME: consider caching errors too.
614616
if infcx.predicate_must_hold_considering_regions(obligation) {
615617
debug!(
616-
"selecting trait `{:?}` at depth {} evaluated to holds",
617-
obligation.predicate, obligation.recursion_depth
618+
"selecting trait at depth {} evaluated to holds",
619+
obligation.recursion_depth
618620
);
619621
return ProcessResult::Changed(vec![]);
620622
}
621623
}
622624

623625
match self.selcx.select(&trait_obligation) {
624626
Ok(Some(impl_source)) => {
625-
debug!(
626-
"selecting trait `{:?}` at depth {} yielded Ok(Some)",
627-
trait_obligation.predicate, obligation.recursion_depth
628-
);
627+
debug!("selecting trait at depth {} yielded Ok(Some)", obligation.recursion_depth);
629628
ProcessResult::Changed(mk_pending(impl_source.nested_obligations()))
630629
}
631630
Ok(None) => {
632-
debug!(
633-
"selecting trait `{:?}` at depth {} yielded Ok(None)",
634-
trait_obligation.predicate, obligation.recursion_depth
635-
);
631+
debug!("selecting trait at depth {} yielded Ok(None)", obligation.recursion_depth);
636632

637633
// This is a bit subtle: for the most part, the
638634
// only reason we can fail to make progress on
@@ -652,10 +648,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
652648
ProcessResult::Unchanged
653649
}
654650
Err(selection_err) => {
655-
info!(
656-
"selecting trait `{:?}` at depth {} yielded Err",
657-
trait_obligation.predicate, obligation.recursion_depth
658-
);
651+
info!("selecting trait at depth {} yielded Err", obligation.recursion_depth);
659652

660653
ProcessResult::Error(CodeSelectionError(selection_err))
661654
}

0 commit comments

Comments
 (0)