about summary refs log tree commit diff
path: root/compiler/rustc_pattern_analysis/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-02-25 16:18:45 +0000
committerbors <bors@rust-lang.org>2024-02-25 16:18:45 +0000
commit8c0b1fcd2914caaf1c3a1071028fb74b70c519e9 (patch)
tree2f87a275d744713395351771d943ebea39482a6a /compiler/rustc_pattern_analysis/src
parent34aab623ddccd54636a9f6e630cb29af443c4680 (diff)
parenta4423884c15acbe9d3027ddd9d008f79d583afeb (diff)
downloadrust-8c0b1fcd2914caaf1c3a1071028fb74b70c519e9.tar.gz
rust-8c0b1fcd2914caaf1c3a1071028fb74b70c519e9.zip
Auto merge of #121591 - matthiaskrgr:rollup-8wfhh3v, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #119590 (Stabilize `cfg_target_abi`)
 - #120805 (make non-PartialEq-typed consts as patterns a hard error)
 - #121060 (Add newtypes for bool fields/params/return types)
 - #121284 (Add test cases for inlining compiler-private items)
 - #121324 (pattern_analysis: factor out unspecialization)
 - #121409 (Prevent cycle in implied predicates computation)
 - #121513 (Fix sgx unit test compilation)
 - #121570 (Make most bootstrap step types !Copy)
 - #121586 (Don't use `unwrap()` in `ArrayIntoIter` lint when typeck fails)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_pattern_analysis/src')
-rw-r--r--compiler/rustc_pattern_analysis/src/usefulness.rs36
1 files changed, 21 insertions, 15 deletions
diff --git a/compiler/rustc_pattern_analysis/src/usefulness.rs b/compiler/rustc_pattern_analysis/src/usefulness.rs
index a24da448766..f672051be5a 100644
--- a/compiler/rustc_pattern_analysis/src/usefulness.rs
+++ b/compiler/rustc_pattern_analysis/src/usefulness.rs
@@ -1189,6 +1189,25 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
         }
         Ok(matrix)
     }
+
+    /// Recover row usefulness and intersection information from a processed specialized matrix.
+    /// `specialized` must come from `self.specialize_constructor`.
+    fn unspecialize(&mut self, specialized: Self) {
+        for child_row in specialized.rows() {
+            let parent_row_id = child_row.parent_row;
+            let parent_row = &mut self.rows[parent_row_id];
+            // A parent row is useful if any of its children is.
+            parent_row.useful |= child_row.useful;
+            for child_intersection in child_row.intersects.iter() {
+                // Convert the intersecting ids into ids for the parent matrix.
+                let parent_intersection = specialized.rows[child_intersection].parent_row;
+                // Note: self-intersection can happen with or-patterns.
+                if parent_intersection != parent_row_id {
+                    parent_row.intersects.insert(parent_intersection);
+                }
+            }
+        }
+    }
 }
 
 /// Pretty-printer for matrices of patterns, example:
@@ -1558,21 +1577,6 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
         // Accumulate the found witnesses.
         ret.extend(witnesses);
 
-        for child_row in spec_matrix.rows() {
-            let parent_row_id = child_row.parent_row;
-            let parent_row = &mut matrix.rows[parent_row_id];
-            // A parent row is useful if any of its children is.
-            parent_row.useful |= child_row.useful;
-            for child_intersection in child_row.intersects.iter() {
-                // Convert the intersecting ids into ids for the parent matrix.
-                let parent_intersection = spec_matrix.rows[child_intersection].parent_row;
-                // Note: self-intersection can happen with or-patterns.
-                if parent_intersection != parent_row_id {
-                    parent_row.intersects.insert(parent_intersection);
-                }
-            }
-        }
-
         // Detect ranges that overlap on their endpoints.
         if let Constructor::IntRange(overlap_range) = ctor {
             if overlap_range.is_singleton()
@@ -1582,6 +1586,8 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
                 collect_overlapping_range_endpoints(mcx, overlap_range, matrix, &spec_matrix);
             }
         }
+
+        matrix.unspecialize(spec_matrix);
     }
 
     // Record usefulness in the patterns.