Skip to content

Commit eee912e

Browse files
committed
region_infer: improved debug logging
1 parent 01866a0 commit eee912e

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

src/librustc_mir/transform/nll/region_infer.rs

+35-9
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,12 @@ impl Region {
8989
}
9090
}
9191

92-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
92+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
9393
pub struct Constraint {
94-
/// Where did this constraint arise?
95-
span: Span,
94+
// NB. The ordering here is not significant for correctness, but
95+
// it is for conenience. Before we dump the constraints in the
96+
// debugging logs, we sort them, and we'd like the "super region"
97+
// to be first, etc. (In particular, span should remain last.)
9698

9799
/// The region SUP must outlive SUB...
98100
sup: RegionVid,
@@ -102,6 +104,9 @@ pub struct Constraint {
102104

103105
/// At this location.
104106
point: Location,
107+
108+
/// Where did this constraint arise?
109+
span: Span,
105110
}
106111

107112
impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> {
@@ -269,15 +274,23 @@ impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> {
269274
let mut dfs = Dfs::new(mir);
270275
let mut error_regions = FxHashSet();
271276
let mut errors = vec![];
277+
278+
debug!("propagate_constraints()");
279+
debug!("propagate_constraints: constraints={:#?}", {
280+
let mut constraints: Vec<_> = self.constraints.iter().collect();
281+
constraints.sort();
282+
constraints
283+
});
284+
272285
while changed {
273286
changed = false;
274287
for constraint in &self.constraints {
275-
debug!("constraint: {:?}", constraint);
288+
debug!("propagate_constraints: constraint={:?}", constraint);
276289
let sub = &self.definitions[constraint.sub].value.clone();
277290
let sup_def = &mut self.definitions[constraint.sup];
278291

279-
debug!(" sub (before): {:?}", sub);
280-
debug!(" sup (before): {:?}", sup_def.value);
292+
debug!("propagate_constraints: sub (before): {:?}", sub);
293+
debug!("propagate_constraints: sup (before): {:?}", sup_def.value);
281294

282295
if !sup_def.constant {
283296
// If this is not a constant, then grow the value as needed to
@@ -287,8 +300,8 @@ impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> {
287300
changed = true;
288301
}
289302

290-
debug!(" sup (after) : {:?}", sup_def.value);
291-
debug!(" changed : {:?}", changed);
303+
debug!("propagate_constraints: sup (after) : {:?}", sup_def.value);
304+
debug!("propagate_constraints: changed : {:?}", changed);
292305
} else {
293306
// If this is a constant, check whether it *would
294307
// have* to grow in order for the constraint to be
@@ -304,7 +317,7 @@ impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> {
304317
.difference(&sup_def.value.free_regions)
305318
.next()
306319
.unwrap();
307-
debug!(" new_region : {:?}", new_region);
320+
debug!("propagate_constraints: new_region : {:?}", new_region);
308321
if error_regions.insert(constraint.sup) {
309322
errors.push((constraint.sup, constraint.span, new_region));
310323
}
@@ -406,3 +419,16 @@ impl<'tcx> RegionDefinition<'tcx> {
406419
}
407420
}
408421
}
422+
423+
impl fmt::Debug for Constraint {
424+
fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
425+
write!(
426+
formatter,
427+
"({:?}: {:?} @ {:?}) due to {:?}",
428+
self.sup,
429+
self.sub,
430+
self.point,
431+
self.span
432+
)
433+
}
434+
}

0 commit comments

Comments
 (0)