Skip to content

Commit 8f8092c

Browse files
committed
Auto merge of #89048 - oli-obk:in_tracing_we_trust, r=jackh726
Add more tracing instrumentation I changed or added all this while working on a branch and pulled it out so we can merge it on its own.
2 parents 1d71ba8 + 9b5aa06 commit 8f8092c

File tree

39 files changed

+252
-323
lines changed

39 files changed

+252
-323
lines changed

Diff for: compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ impl TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
327327
}
328328
}
329329

330+
#[instrument(skip(fulfill_cx, infcx), level = "debug")]
330331
fn try_extract_error_from_fulfill_cx<'tcx>(
331332
mut fulfill_cx: Box<dyn TraitEngine<'tcx> + 'tcx>,
332333
infcx: &InferCtxt<'_, 'tcx>,
@@ -341,7 +342,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
341342
let _errors = fulfill_cx.select_all_or_error(infcx).err().unwrap_or_else(Vec::new);
342343

343344
let (sub_region, cause) = infcx.with_region_constraints(|region_constraints| {
344-
debug!(?region_constraints);
345+
debug!("{:#?}", region_constraints);
345346
region_constraints.constraints.iter().find_map(|(constraint, cause)| {
346347
match *constraint {
347348
Constraint::RegSubReg(sub, sup) if sup == placeholder_region && sup != sub => {
@@ -356,7 +357,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
356357
})
357358
})?;
358359

359-
debug!(?sub_region, ?cause);
360+
debug!(?sub_region, "cause = {:#?}", cause);
360361
let nice_error = match (error_region, sub_region) {
361362
(Some(error_region), &ty::ReVar(vid)) => NiceRegionError::new(
362363
infcx,

Diff for: compiler/rustc_borrowck/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ fn mir_borrowck<'tcx>(
144144
/// If `return_body_with_facts` is true, then return the body with non-erased
145145
/// region ids on which the borrow checking was performed together with Polonius
146146
/// facts.
147+
#[instrument(skip(infcx, input_body, input_promoted), level = "debug")]
147148
fn do_mir_borrowck<'a, 'tcx>(
148149
infcx: &InferCtxt<'a, 'tcx>,
149150
input_body: &Body<'tcx>,
@@ -152,7 +153,7 @@ fn do_mir_borrowck<'a, 'tcx>(
152153
) -> (BorrowCheckResult<'tcx>, Option<Box<BodyWithBorrowckFacts<'tcx>>>) {
153154
let def = input_body.source.with_opt_param().as_local().unwrap();
154155

155-
debug!("do_mir_borrowck(def = {:?})", def);
156+
debug!(?def);
156157

157158
let tcx = infcx.tcx;
158159
let param_env = tcx.param_env(def.did);

Diff for: compiler/rustc_borrowck/src/nll.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ crate struct NllOutput<'tcx> {
5454
/// Rewrites the regions in the MIR to use NLL variables, also scraping out the set of universal
5555
/// regions (e.g., region parameters) declared on the function. That set will need to be given to
5656
/// `compute_regions`.
57+
#[instrument(skip(infcx, param_env, body, promoted), level = "debug")]
5758
pub(crate) fn replace_regions_in_mir<'cx, 'tcx>(
5859
infcx: &InferCtxt<'cx, 'tcx>,
5960
param_env: ty::ParamEnv<'tcx>,
@@ -62,7 +63,7 @@ pub(crate) fn replace_regions_in_mir<'cx, 'tcx>(
6263
) -> UniversalRegions<'tcx> {
6364
let def = body.source.with_opt_param().as_local().unwrap();
6465

65-
debug!("replace_regions_in_mir(def={:?})", def);
66+
debug!(?def);
6667

6768
// Compute named region information. This also renumbers the inputs/outputs.
6869
let universal_regions = UniversalRegions::new(infcx, def, param_env);

Diff for: compiler/rustc_borrowck/src/region_infer/mod.rs

+26-45
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
552552
/// Performs region inference and report errors if we see any
553553
/// unsatisfiable constraints. If this is a closure, returns the
554554
/// region requirements to propagate to our creator, if any.
555+
#[instrument(skip(self, infcx, body, polonius_output), level = "debug")]
555556
pub(super) fn solve(
556557
&mut self,
557558
infcx: &InferCtxt<'_, 'tcx>,
@@ -607,10 +608,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
607608
/// for each region variable until all the constraints are
608609
/// satisfied. Note that some values may grow **too** large to be
609610
/// feasible, but we check this later.
611+
#[instrument(skip(self, _body), level = "debug")]
610612
fn propagate_constraints(&mut self, _body: &Body<'tcx>) {
611-
debug!("propagate_constraints()");
612-
613-
debug!("propagate_constraints: constraints={:#?}", {
613+
debug!("constraints={:#?}", {
614614
let mut constraints: Vec<_> = self.constraints.outlives().iter().collect();
615615
constraints.sort();
616616
constraints
@@ -637,12 +637,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
637637
/// computed, by unioning the values of its successors.
638638
/// Assumes that all successors have been computed already
639639
/// (which is assured by iterating over SCCs in dependency order).
640+
#[instrument(skip(self), level = "debug")]
640641
fn compute_value_for_scc(&mut self, scc_a: ConstraintSccIndex) {
641642
let constraint_sccs = self.constraint_sccs.clone();
642643

643644
// Walk each SCC `B` such that `A: B`...
644645
for &scc_b in constraint_sccs.successors(scc_a) {
645-
debug!("propagate_constraint_sccs: scc_a = {:?} scc_b = {:?}", scc_a, scc_b);
646+
debug!(?scc_b);
646647

647648
// ...and add elements from `B` into `A`. One complication
648649
// arises because of universes: If `B` contains something
@@ -663,11 +664,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
663664
self.apply_member_constraint(scc_a, m_c_i, member_constraints.choice_regions(m_c_i));
664665
}
665666

666-
debug!(
667-
"propagate_constraint_sccs: scc_a = {:?} has value {:?}",
668-
scc_a,
669-
self.scc_values.region_value_str(scc_a),
670-
);
667+
debug!(value = ?self.scc_values.region_value_str(scc_a));
671668
}
672669

673670
/// Invoked for each `R0 member of [R1..Rn]` constraint.
@@ -681,14 +678,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
681678
/// is considered a *lower bound*. If possible, we will modify
682679
/// the constraint to set it equal to one of the option regions.
683680
/// If we make any changes, returns true, else false.
681+
#[instrument(skip(self, member_constraint_index), level = "debug")]
684682
fn apply_member_constraint(
685683
&mut self,
686684
scc: ConstraintSccIndex,
687685
member_constraint_index: NllMemberConstraintIndex,
688686
choice_regions: &[ty::RegionVid],
689687
) -> bool {
690-
debug!("apply_member_constraint(scc={:?}, choice_regions={:#?})", scc, choice_regions,);
691-
692688
// Create a mutable vector of the options. We'll try to winnow
693689
// them down.
694690
let mut choice_regions: Vec<ty::RegionVid> = choice_regions.to_vec();
@@ -714,7 +710,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
714710
.universal_regions_outlived_by(scc)
715711
.all(|lb| self.universal_region_relations.outlives(o_r, lb))
716712
});
717-
debug!("apply_member_constraint: after lb, choice_regions={:?}", choice_regions);
713+
debug!(?choice_regions, "after lb");
718714

719715
// Now find all the *upper bounds* -- that is, each UB is a
720716
// free region that must outlive the member region `R0` (`UB:
@@ -723,10 +719,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
723719
let rev_scc_graph = self.reverse_scc_graph();
724720
let universal_region_relations = &self.universal_region_relations;
725721
for ub in rev_scc_graph.upper_bounds(scc) {
726-
debug!("apply_member_constraint: ub={:?}", ub);
722+
debug!(?ub);
727723
choice_regions.retain(|&o_r| universal_region_relations.outlives(ub, o_r));
728724
}
729-
debug!("apply_member_constraint: after ub, choice_regions={:?}", choice_regions);
725+
debug!(?choice_regions, "after ub");
730726

731727
// If we ruled everything out, we're done.
732728
if choice_regions.is_empty() {
@@ -735,7 +731,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
735731

736732
// Otherwise, we need to find the minimum remaining choice, if
737733
// any, and take that.
738-
debug!("apply_member_constraint: choice_regions remaining are {:#?}", choice_regions);
734+
debug!("choice_regions remaining are {:#?}", choice_regions);
739735
let min = |r1: ty::RegionVid, r2: ty::RegionVid| -> Option<ty::RegionVid> {
740736
let r1_outlives_r2 = self.universal_region_relations.outlives(r1, r2);
741737
let r2_outlives_r1 = self.universal_region_relations.outlives(r2, r1);
@@ -748,27 +744,18 @@ impl<'tcx> RegionInferenceContext<'tcx> {
748744
};
749745
let mut min_choice = choice_regions[0];
750746
for &other_option in &choice_regions[1..] {
751-
debug!(
752-
"apply_member_constraint: min_choice={:?} other_option={:?}",
753-
min_choice, other_option,
754-
);
747+
debug!(?min_choice, ?other_option,);
755748
match min(min_choice, other_option) {
756749
Some(m) => min_choice = m,
757750
None => {
758-
debug!(
759-
"apply_member_constraint: {:?} and {:?} are incomparable; no min choice",
760-
min_choice, other_option,
761-
);
751+
debug!(?min_choice, ?other_option, "incomparable; no min choice",);
762752
return false;
763753
}
764754
}
765755
}
766756

767757
let min_choice_scc = self.constraint_sccs.scc(min_choice);
768-
debug!(
769-
"apply_member_constraint: min_choice={:?} best_choice_scc={:?}",
770-
min_choice, min_choice_scc,
771-
);
758+
debug!(?min_choice, ?min_choice_scc);
772759
if self.scc_values.add_region(scc, min_choice_scc) {
773760
self.member_constraints_applied.push(AppliedMemberConstraint {
774761
member_region_scc: scc,
@@ -1091,8 +1078,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
10911078
/// include the CFG anyhow.
10921079
/// - For each `end('x)` element in `'r`, compute the mutual LUB, yielding
10931080
/// a result `'y`.
1081+
#[instrument(skip(self), level = "debug")]
10941082
pub(crate) fn universal_upper_bound(&self, r: RegionVid) -> RegionVid {
1095-
debug!("universal_upper_bound(r={:?}={})", r, self.region_value_str(r));
1083+
debug!(r = %self.region_value_str(r));
10961084

10971085
// Find the smallest universal region that contains all other
10981086
// universal regions within `region`.
@@ -1102,7 +1090,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11021090
lub = self.universal_region_relations.postdom_upper_bound(lub, ur);
11031091
}
11041092

1105-
debug!("universal_upper_bound: r={:?} lub={:?}", r, lub);
1093+
debug!(?lub);
11061094

11071095
lub
11081096
}
@@ -1262,9 +1250,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
12621250
}
12631251

12641252
// Evaluate whether `sup_region: sub_region`.
1253+
#[instrument(skip(self), level = "debug")]
12651254
fn eval_outlives(&self, sup_region: RegionVid, sub_region: RegionVid) -> bool {
1266-
debug!("eval_outlives({:?}: {:?})", sup_region, sub_region);
1267-
12681255
debug!(
12691256
"eval_outlives: sup_region's value = {:?} universal={:?}",
12701257
self.region_value_str(sup_region),
@@ -1467,15 +1454,17 @@ impl<'tcx> RegionInferenceContext<'tcx> {
14671454
///
14681455
/// Things that are to be propagated are accumulated into the
14691456
/// `outlives_requirements` vector.
1457+
#[instrument(
1458+
skip(self, body, propagated_outlives_requirements, errors_buffer),
1459+
level = "debug"
1460+
)]
14701461
fn check_universal_region(
14711462
&self,
14721463
body: &Body<'tcx>,
14731464
longer_fr: RegionVid,
14741465
propagated_outlives_requirements: &mut Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
14751466
errors_buffer: &mut RegionErrors<'tcx>,
14761467
) {
1477-
debug!("check_universal_region(fr={:?})", longer_fr);
1478-
14791468
let longer_fr_scc = self.constraint_sccs.scc(longer_fr);
14801469

14811470
// Because this free region must be in the ROOT universe, we
@@ -1880,21 +1869,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
18801869
}
18811870

18821871
/// Finds some region R such that `fr1: R` and `R` is live at `elem`.
1872+
#[instrument(skip(self), level = "trace")]
18831873
crate fn find_sub_region_live_at(&self, fr1: RegionVid, elem: Location) -> RegionVid {
1884-
debug!("find_sub_region_live_at(fr1={:?}, elem={:?})", fr1, elem);
1885-
debug!("find_sub_region_live_at: {:?} is in scc {:?}", fr1, self.constraint_sccs.scc(fr1));
1886-
debug!(
1887-
"find_sub_region_live_at: {:?} is in universe {:?}",
1888-
fr1,
1889-
self.scc_universes[self.constraint_sccs.scc(fr1)]
1890-
);
1874+
trace!(scc = ?self.constraint_sccs.scc(fr1));
1875+
trace!(universe = ?self.scc_universes[self.constraint_sccs.scc(fr1)]);
18911876
self.find_constraint_paths_between_regions(fr1, |r| {
18921877
// First look for some `r` such that `fr1: r` and `r` is live at `elem`
1893-
debug!(
1894-
"find_sub_region_live_at: liveness_constraints for {:?} are {:?}",
1895-
r,
1896-
self.liveness_constraints.region_value_str(r),
1897-
);
1878+
trace!(?r, liveness_constraints=?self.liveness_constraints.region_value_str(r));
18981879
self.liveness_constraints.contains(r, elem)
18991880
})
19001881
.or_else(|| {

Diff for: compiler/rustc_borrowck/src/renumber.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
77

88
/// Replaces all free regions appearing in the MIR with fresh
99
/// inference variables, returning the number of variables created.
10+
#[instrument(skip(infcx, body, promoted), level = "debug")]
1011
pub fn renumber_mir<'tcx>(
1112
infcx: &InferCtxt<'_, 'tcx>,
1213
body: &mut Body<'tcx>,
1314
promoted: &mut IndexVec<Promoted, Body<'tcx>>,
1415
) {
15-
debug!("renumber_mir()");
16-
debug!("renumber_mir: body.arg_count={:?}", body.arg_count);
16+
debug!(?body.arg_count);
1717

1818
let mut visitor = NllVisitor { infcx };
1919

@@ -26,12 +26,11 @@ pub fn renumber_mir<'tcx>(
2626

2727
/// Replaces all regions appearing in `value` with fresh inference
2828
/// variables.
29+
#[instrument(skip(infcx), level = "debug")]
2930
pub fn renumber_regions<'tcx, T>(infcx: &InferCtxt<'_, 'tcx>, value: T) -> T
3031
where
3132
T: TypeFoldable<'tcx>,
3233
{
33-
debug!("renumber_regions(value={:?})", value);
34-
3534
infcx.tcx.fold_regions(value, &mut false, |_region, _depth| {
3635
let origin = NllRegionVariableOrigin::Existential { from_forall: false };
3736
infcx.next_nll_region_var(origin)
@@ -56,12 +55,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
5655
self.infcx.tcx
5756
}
5857

58+
#[instrument(skip(self), level = "debug")]
5959
fn visit_ty(&mut self, ty: &mut Ty<'tcx>, ty_context: TyContext) {
60-
debug!("visit_ty(ty={:?}, ty_context={:?})", ty, ty_context);
61-
6260
*ty = self.renumber_regions(ty);
6361

64-
debug!("visit_ty: ty={:?}", ty);
62+
debug!(?ty);
6563
}
6664

6765
fn process_projection_elem(
@@ -80,21 +78,19 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
8078
None
8179
}
8280

81+
#[instrument(skip(self), level = "debug")]
8382
fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, location: Location) {
84-
debug!("visit_substs(substs={:?}, location={:?})", substs, location);
85-
8683
*substs = self.renumber_regions(*substs);
8784

88-
debug!("visit_substs: substs={:?}", substs);
85+
debug!(?substs);
8986
}
9087

88+
#[instrument(skip(self), level = "debug")]
9189
fn visit_region(&mut self, region: &mut ty::Region<'tcx>, location: Location) {
92-
debug!("visit_region(region={:?}, location={:?})", region, location);
93-
9490
let old_region = *region;
9591
*region = self.renumber_regions(&old_region);
9692

97-
debug!("visit_region: region={:?}", region);
93+
debug!(?region);
9894
}
9995

10096
fn visit_const(&mut self, constant: &mut &'tcx ty::Const<'tcx>, _location: Location) {

Diff for: compiler/rustc_borrowck/src/type_check/canonical.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
2424
/// **Any `rustc_infer::infer` operations that might generate region
2525
/// constraints should occur within this method so that those
2626
/// constraints can be properly localized!**
27+
#[instrument(skip(self, category, op), level = "trace")]
2728
pub(super) fn fully_perform_op<R, Op>(
2829
&mut self,
2930
locations: Locations,
@@ -131,14 +132,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
131132
}
132133
}
133134

135+
#[instrument(skip(self), level = "debug")]
134136
pub(super) fn prove_predicate(
135137
&mut self,
136138
predicate: ty::Predicate<'tcx>,
137139
locations: Locations,
138140
category: ConstraintCategory,
139141
) {
140-
debug!("prove_predicate(predicate={:?}, location={:?})", predicate, locations,);
141-
142142
let param_env = self.param_env;
143143
self.fully_perform_op(
144144
locations,
@@ -150,11 +150,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
150150
})
151151
}
152152

153+
#[instrument(skip(self), level = "debug")]
153154
pub(super) fn normalize<T>(&mut self, value: T, location: impl NormalizeLocation) -> T
154155
where
155156
T: type_op::normalize::Normalizable<'tcx> + fmt::Display + Copy + 'tcx,
156157
{
157-
debug!("normalize(value={:?}, location={:?})", value, location);
158158
let param_env = self.param_env;
159159
self.fully_perform_op(
160160
location.to_locations(),

Diff for: compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
5353
}
5454
}
5555

56+
#[instrument(skip(self), level = "debug")]
5657
pub(super) fn convert_all(&mut self, query_constraints: &QueryRegionConstraints<'tcx>) {
57-
debug!("convert_all(query_constraints={:#?})", query_constraints);
58-
5958
let QueryRegionConstraints { outlives, member_constraints } = query_constraints;
6059

6160
// Annoying: to invoke `self.to_region_vid`, we need access to

0 commit comments

Comments
 (0)