]> git.lizzy.rs Git - rust.git/commitdiff
region_infer: improved debug logging
authorNiko Matsakis <niko@alum.mit.edu>
Tue, 7 Nov 2017 09:31:21 +0000 (04:31 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Thu, 16 Nov 2017 10:57:47 +0000 (05:57 -0500)
src/librustc_mir/transform/nll/region_infer.rs

index 24821529bade0f983d153a2bbb0315eb969cf154..566a3b23ff13869e3dca5cd3488c1f1d965016b7 100644 (file)
@@ -89,10 +89,12 @@ fn contains_point(&self, point: Location) -> bool {
     }
 }
 
-#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
+#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
 pub struct Constraint {
-    /// Where did this constraint arise?
-    span: Span,
+    // NB. The ordering here is not significant for correctness, but
+    // 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...
     sup: RegionVid,
@@ -102,6 +104,9 @@ pub struct Constraint {
 
     /// At this location.
     point: Location,
+
+    /// Where did this constraint arise?
+    span: Span,
 }
 
 impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> {
@@ -269,15 +274,23 @@ fn propagate_constraints(&mut self, mir: &Mir<'tcx>) -> Vec<(RegionVid, Span, Re
         let mut dfs = Dfs::new(mir);
         let mut error_regions = FxHashSet();
         let mut errors = vec![];
+
+        debug!("propagate_constraints()");
+        debug!("propagate_constraints: constraints={:#?}", {
+            let mut constraints: Vec<_> = self.constraints.iter().collect();
+            constraints.sort();
+            constraints
+        });
+
         while changed {
             changed = false;
             for constraint in &self.constraints {
-                debug!("constraint: {:?}", constraint);
+                debug!("propagate_constraints: constraint={:?}", constraint);
                 let sub = &self.definitions[constraint.sub].value.clone();
                 let sup_def = &mut self.definitions[constraint.sup];
 
-                debug!("    sub (before): {:?}", sub);
-                debug!("    sup (before): {:?}", sup_def.value);
+                debug!("propagate_constraints:    sub (before): {:?}", sub);
+                debug!("propagate_constraints:    sup (before): {:?}", sup_def.value);
 
                 if !sup_def.constant {
                     // If this is not a constant, then grow the value as needed to
@@ -287,8 +300,8 @@ fn propagate_constraints(&mut self, mir: &Mir<'tcx>) -> Vec<(RegionVid, Span, Re
                         changed = true;
                     }
 
-                    debug!("    sup (after) : {:?}", sup_def.value);
-                    debug!("    changed     : {:?}", changed);
+                    debug!("propagate_constraints:    sup (after) : {:?}", sup_def.value);
+                    debug!("propagate_constraints:    changed     : {:?}", changed);
                 } else {
                     // If this is a constant, check whether it *would
                     // have* to grow in order for the constraint to be
@@ -304,7 +317,7 @@ fn propagate_constraints(&mut self, mir: &Mir<'tcx>) -> Vec<(RegionVid, Span, Re
                             .difference(&sup_def.value.free_regions)
                             .next()
                             .unwrap();
-                        debug!("    new_region : {:?}", new_region);
+                        debug!("propagate_constraints:    new_region : {:?}", new_region);
                         if error_regions.insert(constraint.sup) {
                             errors.push((constraint.sup, constraint.span, new_region));
                         }
@@ -406,3 +419,16 @@ fn new(origin: RegionVariableOrigin) -> Self {
         }
     }
 }
+
+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
+        )
+    }
+}