region_infer: improved debug logging

This commit is contained in:
Niko Matsakis 2017-11-07 04:31:21 -05:00
parent 32f964cc98
commit d9e841e756

View File

@ -89,10 +89,12 @@ impl Region {
} }
} }
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Constraint { pub struct Constraint {
/// Where did this constraint arise? // NB. The ordering here is not significant for correctness, but
span: Span, // it is for conenience. Before we dump the constraints in the
// debugging logs, we sort them, and we'd like the "super region"
// to be first, etc. (In particular, span should remain last.)
/// The region SUP must outlive SUB... /// The region SUP must outlive SUB...
sup: RegionVid, sup: RegionVid,
@ -102,6 +104,9 @@ pub struct Constraint {
/// At this location. /// At this location.
point: Location, point: Location,
/// Where did this constraint arise?
span: Span,
} }
impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> { impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> {
@ -269,15 +274,23 @@ impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> {
let mut dfs = Dfs::new(mir); let mut dfs = Dfs::new(mir);
let mut error_regions = FxHashSet(); let mut error_regions = FxHashSet();
let mut errors = vec![]; let mut errors = vec![];
debug!("propagate_constraints()");
debug!("propagate_constraints: constraints={:#?}", {
let mut constraints: Vec<_> = self.constraints.iter().collect();
constraints.sort();
constraints
});
while changed { while changed {
changed = false; changed = false;
for constraint in &self.constraints { for constraint in &self.constraints {
debug!("constraint: {:?}", constraint); debug!("propagate_constraints: constraint={:?}", constraint);
let sub = &self.definitions[constraint.sub].value.clone(); let sub = &self.definitions[constraint.sub].value.clone();
let sup_def = &mut self.definitions[constraint.sup]; let sup_def = &mut self.definitions[constraint.sup];
debug!(" sub (before): {:?}", sub); debug!("propagate_constraints: sub (before): {:?}", sub);
debug!(" sup (before): {:?}", sup_def.value); debug!("propagate_constraints: sup (before): {:?}", sup_def.value);
if !sup_def.constant { if !sup_def.constant {
// If this is not a constant, then grow the value as needed to // If this is not a constant, then grow the value as needed to
@ -287,8 +300,8 @@ impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> {
changed = true; changed = true;
} }
debug!(" sup (after) : {:?}", sup_def.value); debug!("propagate_constraints: sup (after) : {:?}", sup_def.value);
debug!(" changed : {:?}", changed); debug!("propagate_constraints: changed : {:?}", changed);
} else { } else {
// If this is a constant, check whether it *would // If this is a constant, check whether it *would
// have* to grow in order for the constraint to be // have* to grow in order for the constraint to be
@ -304,7 +317,7 @@ impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> {
.difference(&sup_def.value.free_regions) .difference(&sup_def.value.free_regions)
.next() .next()
.unwrap(); .unwrap();
debug!(" new_region : {:?}", new_region); debug!("propagate_constraints: new_region : {:?}", new_region);
if error_regions.insert(constraint.sup) { if error_regions.insert(constraint.sup) {
errors.push((constraint.sup, constraint.span, new_region)); errors.push((constraint.sup, constraint.span, new_region));
} }
@ -406,3 +419,16 @@ impl<'tcx> RegionDefinition<'tcx> {
} }
} }
} }
impl fmt::Debug for Constraint {
fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(
formatter,
"({:?}: {:?} @ {:?}) due to {:?}",
self.sup,
self.sub,
self.point,
self.span
)
}
}