Skip to content

Commit 1443de7

Browse files
committed
More tracing instrumentation
1 parent dda2a0e commit 1443de7

File tree

39 files changed

+252
-323
lines changed

39 files changed

+252
-323
lines changed

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ impl TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
299299
}
300300
}
301301

302+
#[instrument(skip(fulfill_cx, infcx), level = "debug")]
302303
fn try_extract_error_from_fulfill_cx<'tcx>(
303304
mut fulfill_cx: Box<dyn TraitEngine<'tcx> + 'tcx>,
304305
infcx: &InferCtxt<'_, 'tcx>,
@@ -313,7 +314,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
313314
let _errors = fulfill_cx.select_all_or_error(infcx).err().unwrap_or_else(Vec::new);
314315

315316
let (sub_region, cause) = infcx.with_region_constraints(|region_constraints| {
316-
debug!(?region_constraints);
317+
debug!("{:#?}", region_constraints);
317318
region_constraints.constraints.iter().find_map(|(constraint, cause)| {
318319
match *constraint {
319320
Constraint::RegSubReg(sub, sup) if sup == placeholder_region && sup != sub => {
@@ -328,7 +329,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
328329
})
329330
})?;
330331

331-
debug!(?sub_region, ?cause);
332+
debug!(?sub_region, "cause = {:#?}", cause);
332333
let nice_error = match (error_region, sub_region) {
333334
(Some(error_region), &ty::ReVar(vid)) => NiceRegionError::new(
334335
infcx,

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

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

compiler/rustc_borrowck/src/region_infer/mod.rs

+26-45
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
549549
/// Performs region inference and report errors if we see any
550550
/// unsatisfiable constraints. If this is a closure, returns the
551551
/// region requirements to propagate to our creator, if any.
552+
#[instrument(skip(self, infcx, body, polonius_output), level = "debug")]
552553
pub(super) fn solve(
553554
&mut self,
554555
infcx: &InferCtxt<'_, 'tcx>,
@@ -604,10 +605,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
604605
/// for each region variable until all the constraints are
605606
/// satisfied. Note that some values may grow **too** large to be
606607
/// feasible, but we check this later.
608+
#[instrument(skip(self, _body), level = "debug")]
607609
fn propagate_constraints(&mut self, _body: &Body<'tcx>) {
608-
debug!("propagate_constraints()");
609-
610-
debug!("propagate_constraints: constraints={:#?}", {
610+
debug!("constraints={:#?}", {
611611
let mut constraints: Vec<_> = self.constraints.outlives().iter().collect();
612612
constraints.sort();
613613
constraints
@@ -634,12 +634,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
634634
/// computed, by unioning the values of its successors.
635635
/// Assumes that all successors have been computed already
636636
/// (which is assured by iterating over SCCs in dependency order).
637+
#[instrument(skip(self), level = "debug")]
637638
fn compute_value_for_scc(&mut self, scc_a: ConstraintSccIndex) {
638639
let constraint_sccs = self.constraint_sccs.clone();
639640

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

644645
// ...and add elements from `B` into `A`. One complication
645646
// arises because of universes: If `B` contains something
@@ -660,11 +661,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
660661
self.apply_member_constraint(scc_a, m_c_i, member_constraints.choice_regions(m_c_i));
661662
}
662663

663-
debug!(
664-
"propagate_constraint_sccs: scc_a = {:?} has value {:?}",
665-
scc_a,
666-
self.scc_values.region_value_str(scc_a),
667-
);
664+
debug!(value = ?self.scc_values.region_value_str(scc_a));
668665
}
669666

670667
/// Invoked for each `R0 member of [R1..Rn]` constraint.
@@ -678,14 +675,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
678675
/// is considered a *lower bound*. If possible, we will modify
679676
/// the constraint to set it equal to one of the option regions.
680677
/// If we make any changes, returns true, else false.
678+
#[instrument(skip(self, member_constraint_index), level = "debug")]
681679
fn apply_member_constraint(
682680
&mut self,
683681
scc: ConstraintSccIndex,
684682
member_constraint_index: NllMemberConstraintIndex,
685683
choice_regions: &[ty::RegionVid],
686684
) -> bool {
687-
debug!("apply_member_constraint(scc={:?}, choice_regions={:#?})", scc, choice_regions,);
688-
689685
// Create a mutable vector of the options. We'll try to winnow
690686
// them down.
691687
let mut choice_regions: Vec<ty::RegionVid> = choice_regions.to_vec();
@@ -711,7 +707,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
711707
.universal_regions_outlived_by(scc)
712708
.all(|lb| self.universal_region_relations.outlives(o_r, lb))
713709
});
714-
debug!("apply_member_constraint: after lb, choice_regions={:?}", choice_regions);
710+
debug!(?choice_regions, "after lb");
715711

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

728724
// If we ruled everything out, we're done.
729725
if choice_regions.is_empty() {
@@ -732,7 +728,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
732728

733729
// Otherwise, we need to find the minimum remaining choice, if
734730
// any, and take that.
735-
debug!("apply_member_constraint: choice_regions remaining are {:#?}", choice_regions);
731+
debug!("choice_regions remaining are {:#?}", choice_regions);
736732
let min = |r1: ty::RegionVid, r2: ty::RegionVid| -> Option<ty::RegionVid> {
737733
let r1_outlives_r2 = self.universal_region_relations.outlives(r1, r2);
738734
let r2_outlives_r1 = self.universal_region_relations.outlives(r2, r1);
@@ -745,27 +741,18 @@ impl<'tcx> RegionInferenceContext<'tcx> {
745741
};
746742
let mut min_choice = choice_regions[0];
747743
for &other_option in &choice_regions[1..] {
748-
debug!(
749-
"apply_member_constraint: min_choice={:?} other_option={:?}",
750-
min_choice, other_option,
751-
);
744+
debug!(?min_choice, ?other_option,);
752745
match min(min_choice, other_option) {
753746
Some(m) => min_choice = m,
754747
None => {
755-
debug!(
756-
"apply_member_constraint: {:?} and {:?} are incomparable; no min choice",
757-
min_choice, other_option,
758-
);
748+
debug!(?min_choice, ?other_option, "incomparable; no min choice",);
759749
return false;
760750
}
761751
}
762752
}
763753

764754
let min_choice_scc = self.constraint_sccs.scc(min_choice);
765-
debug!(
766-
"apply_member_constraint: min_choice={:?} best_choice_scc={:?}",
767-
min_choice, min_choice_scc,
768-
);
755+
debug!(?min_choice, ?min_choice_scc);
769756
if self.scc_values.add_region(scc, min_choice_scc) {
770757
self.member_constraints_applied.push(AppliedMemberConstraint {
771758
member_region_scc: scc,
@@ -1088,8 +1075,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
10881075
/// include the CFG anyhow.
10891076
/// - For each `end('x)` element in `'r`, compute the mutual LUB, yielding
10901077
/// a result `'y`.
1078+
#[instrument(skip(self), level = "debug")]
10911079
pub(crate) fn universal_upper_bound(&self, r: RegionVid) -> RegionVid {
1092-
debug!("universal_upper_bound(r={:?}={})", r, self.region_value_str(r));
1080+
debug!(r = %self.region_value_str(r));
10931081

10941082
// Find the smallest universal region that contains all other
10951083
// universal regions within `region`.
@@ -1099,7 +1087,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
10991087
lub = self.universal_region_relations.postdom_upper_bound(lub, ur);
11001088
}
11011089

1102-
debug!("universal_upper_bound: r={:?} lub={:?}", r, lub);
1090+
debug!(?lub);
11031091

11041092
lub
11051093
}
@@ -1259,9 +1247,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
12591247
}
12601248

12611249
// Evaluate whether `sup_region: sub_region`.
1250+
#[instrument(skip(self), level = "debug")]
12621251
fn eval_outlives(&self, sup_region: RegionVid, sub_region: RegionVid) -> bool {
1263-
debug!("eval_outlives({:?}: {:?})", sup_region, sub_region);
1264-
12651252
debug!(
12661253
"eval_outlives: sup_region's value = {:?} universal={:?}",
12671254
self.region_value_str(sup_region),
@@ -1464,15 +1451,17 @@ impl<'tcx> RegionInferenceContext<'tcx> {
14641451
///
14651452
/// Things that are to be propagated are accumulated into the
14661453
/// `outlives_requirements` vector.
1454+
#[instrument(
1455+
skip(self, body, propagated_outlives_requirements, errors_buffer),
1456+
level = "debug"
1457+
)]
14671458
fn check_universal_region(
14681459
&self,
14691460
body: &Body<'tcx>,
14701461
longer_fr: RegionVid,
14711462
propagated_outlives_requirements: &mut Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
14721463
errors_buffer: &mut RegionErrors<'tcx>,
14731464
) {
1474-
debug!("check_universal_region(fr={:?})", longer_fr);
1475-
14761465
let longer_fr_scc = self.constraint_sccs.scc(longer_fr);
14771466

14781467
// Because this free region must be in the ROOT universe, we
@@ -1877,21 +1866,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
18771866
}
18781867

18791868
/// Finds some region R such that `fr1: R` and `R` is live at `elem`.
1869+
#[instrument(skip(self), level = "trace")]
18801870
crate fn find_sub_region_live_at(&self, fr1: RegionVid, elem: Location) -> RegionVid {
1881-
debug!("find_sub_region_live_at(fr1={:?}, elem={:?})", fr1, elem);
1882-
debug!("find_sub_region_live_at: {:?} is in scc {:?}", fr1, self.constraint_sccs.scc(fr1));
1883-
debug!(
1884-
"find_sub_region_live_at: {:?} is in universe {:?}",
1885-
fr1,
1886-
self.scc_universes[self.constraint_sccs.scc(fr1)]
1887-
);
1871+
trace!(scc = ?self.constraint_sccs.scc(fr1));
1872+
trace!(universe = ?self.scc_universes[self.constraint_sccs.scc(fr1)]);
18881873
self.find_constraint_paths_between_regions(fr1, |r| {
18891874
// First look for some `r` such that `fr1: r` and `r` is live at `elem`
1890-
debug!(
1891-
"find_sub_region_live_at: liveness_constraints for {:?} are {:?}",
1892-
r,
1893-
self.liveness_constraints.region_value_str(r),
1894-
);
1875+
trace!(?r, liveness_constraints=?self.liveness_constraints.region_value_str(r));
18951876
self.liveness_constraints.contains(r, elem)
18961877
})
18971878
.or_else(|| {

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) {

compiler/rustc_borrowck/src/type_check/canonical.rs

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

127+
#[instrument(skip(self), level = "debug")]
126128
pub(super) fn prove_predicate(
127129
&mut self,
128130
predicate: ty::Predicate<'tcx>,
129131
locations: Locations,
130132
category: ConstraintCategory,
131133
) {
132-
debug!("prove_predicate(predicate={:?}, location={:?})", predicate, locations,);
133-
134134
let param_env = self.param_env;
135135
self.fully_perform_op(
136136
locations,
@@ -142,11 +142,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
142142
})
143143
}
144144

145+
#[instrument(skip(self), level = "debug")]
145146
pub(super) fn normalize<T>(&mut self, value: T, location: impl NormalizeLocation) -> T
146147
where
147148
T: type_op::normalize::Normalizable<'tcx> + fmt::Display + Copy + 'tcx,
148149
{
149-
debug!("normalize(value={:?}, location={:?})", value, location);
150150
let param_env = self.param_env;
151151
self.fully_perform_op(
152152
location.to_locations(),

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)