about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src/transitive_relation
diff options
context:
space:
mode:
authorSparrowLii <liyuan179@huawei.com>2022-07-25 11:06:22 +0800
committerSparrowLii <liyuan179@huawei.com>2022-08-22 18:08:46 +0800
commit5d9e4d07fcbd526435b28f2fccb7d9888a2377b6 (patch)
treecd3eff3a6efcf8046fcd5cb6218ed4aad9782738 /compiler/rustc_data_structures/src/transitive_relation
parenta9bb589cd678e034d194193fa892942315b10e2a (diff)
downloadrust-5d9e4d07fcbd526435b28f2fccb7d9888a2377b6.tar.gz
rust-5d9e4d07fcbd526435b28f2fccb7d9888a2377b6.zip
get rid of `RefCell` in `TransitiveRelation`
Diffstat (limited to 'compiler/rustc_data_structures/src/transitive_relation')
-rw-r--r--compiler/rustc_data_structures/src/transitive_relation/tests.rs48
1 files changed, 32 insertions, 16 deletions
diff --git a/compiler/rustc_data_structures/src/transitive_relation/tests.rs b/compiler/rustc_data_structures/src/transitive_relation/tests.rs
index e1f4c7ee073..e756c546e41 100644
--- a/compiler/rustc_data_structures/src/transitive_relation/tests.rs
+++ b/compiler/rustc_data_structures/src/transitive_relation/tests.rs
@@ -10,9 +10,10 @@ impl<T: Eq + Hash + Copy> TransitiveRelation<T> {
 
 #[test]
 fn test_one_step() {
-    let mut relation = TransitiveRelation::default();
+    let mut relation = TransitiveRelationBuilder::default();
     relation.add("a", "b");
     relation.add("a", "c");
+    let relation = relation.freeze();
     assert!(relation.contains("a", "c"));
     assert!(relation.contains("a", "b"));
     assert!(!relation.contains("b", "a"));
@@ -21,7 +22,7 @@ fn test_one_step() {
 
 #[test]
 fn test_many_steps() {
-    let mut relation = TransitiveRelation::default();
+    let mut relation = TransitiveRelationBuilder::default();
     relation.add("a", "b");
     relation.add("a", "c");
     relation.add("a", "f");
@@ -31,6 +32,7 @@ fn test_many_steps() {
     relation.add("b", "e");
 
     relation.add("e", "g");
+    let relation = relation.freeze();
 
     assert!(relation.contains("a", "b"));
     assert!(relation.contains("a", "c"));
@@ -51,9 +53,10 @@ fn mubs_triangle() {
     //      ^
     //      |
     //      b
-    let mut relation = TransitiveRelation::default();
+    let mut relation = TransitiveRelationBuilder::default();
     relation.add("a", "tcx");
     relation.add("b", "tcx");
+    let relation = relation.freeze();
     assert_eq!(relation.minimal_upper_bounds("a", "b"), vec!["tcx"]);
     assert_eq!(relation.parents("a"), vec!["tcx"]);
     assert_eq!(relation.parents("b"), vec!["tcx"]);
@@ -72,7 +75,7 @@ fn mubs_best_choice1() {
     // need the second pare down call to get the right result (after
     // intersection, we have [1, 2], but 2 -> 1).
 
-    let mut relation = TransitiveRelation::default();
+    let mut relation = TransitiveRelationBuilder::default();
     relation.add("0", "1");
     relation.add("0", "2");
 
@@ -80,6 +83,7 @@ fn mubs_best_choice1() {
 
     relation.add("3", "1");
     relation.add("3", "2");
+    let relation = relation.freeze();
 
     assert_eq!(relation.minimal_upper_bounds("0", "3"), vec!["2"]);
     assert_eq!(relation.parents("0"), vec!["2"]);
@@ -99,7 +103,7 @@ fn mubs_best_choice2() {
     // Like the preceding test, but in this case intersection is [2,
     // 1], and hence we rely on the first pare down call.
 
-    let mut relation = TransitiveRelation::default();
+    let mut relation = TransitiveRelationBuilder::default();
     relation.add("0", "1");
     relation.add("0", "2");
 
@@ -107,6 +111,7 @@ fn mubs_best_choice2() {
 
     relation.add("3", "1");
     relation.add("3", "2");
+    let relation = relation.freeze();
 
     assert_eq!(relation.minimal_upper_bounds("0", "3"), vec!["1"]);
     assert_eq!(relation.parents("0"), vec!["1"]);
@@ -118,12 +123,13 @@ fn mubs_best_choice2() {
 fn mubs_no_best_choice() {
     // in this case, the intersection yields [1, 2], and the "pare
     // down" calls find nothing to remove.
-    let mut relation = TransitiveRelation::default();
+    let mut relation = TransitiveRelationBuilder::default();
     relation.add("0", "1");
     relation.add("0", "2");
 
     relation.add("3", "1");
     relation.add("3", "2");
+    let relation = relation.freeze();
 
     assert_eq!(relation.minimal_upper_bounds("0", "3"), vec!["1", "2"]);
     assert_eq!(relation.parents("0"), vec!["1", "2"]);
@@ -135,7 +141,7 @@ fn mubs_best_choice_scc() {
     // in this case, 1 and 2 form a cycle; we pick arbitrarily (but
     // consistently).
 
-    let mut relation = TransitiveRelation::default();
+    let mut relation = TransitiveRelationBuilder::default();
     relation.add("0", "1");
     relation.add("0", "2");
 
@@ -144,6 +150,7 @@ fn mubs_best_choice_scc() {
 
     relation.add("3", "1");
     relation.add("3", "2");
+    let relation = relation.freeze();
 
     assert_eq!(relation.minimal_upper_bounds("0", "3"), vec!["1"]);
     assert_eq!(relation.parents("0"), vec!["1"]);
@@ -157,13 +164,14 @@ fn pdub_crisscross() {
     //   /\       |
     // b -> b1 ---+
 
-    let mut relation = TransitiveRelation::default();
+    let mut relation = TransitiveRelationBuilder::default();
     relation.add("a", "a1");
     relation.add("a", "b1");
     relation.add("b", "a1");
     relation.add("b", "b1");
     relation.add("a1", "x");
     relation.add("b1", "x");
+    let relation = relation.freeze();
 
     assert_eq!(relation.minimal_upper_bounds("a", "b"), vec!["a1", "b1"]);
     assert_eq!(relation.postdom_upper_bound("a", "b"), Some("x"));
@@ -179,7 +187,7 @@ fn pdub_crisscross_more() {
     //   /\    /\             |
     // b -> b1 -> b2 ---------+
 
-    let mut relation = TransitiveRelation::default();
+    let mut relation = TransitiveRelationBuilder::default();
     relation.add("a", "a1");
     relation.add("a", "b1");
     relation.add("b", "a1");
@@ -194,6 +202,7 @@ fn pdub_crisscross_more() {
 
     relation.add("a3", "x");
     relation.add("b2", "x");
+    let relation = relation.freeze();
 
     assert_eq!(relation.minimal_upper_bounds("a", "b"), vec!["a1", "b1"]);
     assert_eq!(relation.minimal_upper_bounds("a1", "b1"), vec!["a2", "b2"]);
@@ -210,11 +219,12 @@ fn pdub_lub() {
     //            |
     // b -> b1 ---+
 
-    let mut relation = TransitiveRelation::default();
+    let mut relation = TransitiveRelationBuilder::default();
     relation.add("a", "a1");
     relation.add("b", "b1");
     relation.add("a1", "x");
     relation.add("b1", "x");
+    let relation = relation.freeze();
 
     assert_eq!(relation.minimal_upper_bounds("a", "b"), vec!["x"]);
     assert_eq!(relation.postdom_upper_bound("a", "b"), Some("x"));
@@ -233,10 +243,11 @@ fn mubs_intermediate_node_on_one_side_only() {
     //           b
 
     // "digraph { a -> c -> d; b -> d; }",
-    let mut relation = TransitiveRelation::default();
+    let mut relation = TransitiveRelationBuilder::default();
     relation.add("a", "c");
     relation.add("c", "d");
     relation.add("b", "d");
+    let relation = relation.freeze();
 
     assert_eq!(relation.minimal_upper_bounds("a", "b"), vec!["d"]);
 }
@@ -252,12 +263,13 @@ fn mubs_scc_1() {
     //           b
 
     // "digraph { a -> c -> d; d -> c; a -> d; b -> d; }",
-    let mut relation = TransitiveRelation::default();
+    let mut relation = TransitiveRelationBuilder::default();
     relation.add("a", "c");
     relation.add("c", "d");
     relation.add("d", "c");
     relation.add("a", "d");
     relation.add("b", "d");
+    let relation = relation.freeze();
 
     assert_eq!(relation.minimal_upper_bounds("a", "b"), vec!["c"]);
 }
@@ -272,12 +284,13 @@ fn mubs_scc_2() {
     //      +--- b
 
     // "digraph { a -> c -> d; d -> c; b -> d; b -> c; }",
-    let mut relation = TransitiveRelation::default();
+    let mut relation = TransitiveRelationBuilder::default();
     relation.add("a", "c");
     relation.add("c", "d");
     relation.add("d", "c");
     relation.add("b", "d");
     relation.add("b", "c");
+    let relation = relation.freeze();
 
     assert_eq!(relation.minimal_upper_bounds("a", "b"), vec!["c"]);
 }
@@ -292,13 +305,14 @@ fn mubs_scc_3() {
     //           b ---+
 
     // "digraph { a -> c -> d -> e -> c; b -> d; b -> e; }",
-    let mut relation = TransitiveRelation::default();
+    let mut relation = TransitiveRelationBuilder::default();
     relation.add("a", "c");
     relation.add("c", "d");
     relation.add("d", "e");
     relation.add("e", "c");
     relation.add("b", "d");
     relation.add("b", "e");
+    let relation = relation.freeze();
 
     assert_eq!(relation.minimal_upper_bounds("a", "b"), vec!["c"]);
 }
@@ -314,13 +328,14 @@ fn mubs_scc_4() {
     //           b ---+
 
     // "digraph { a -> c -> d -> e -> c; a -> d; b -> e; }"
-    let mut relation = TransitiveRelation::default();
+    let mut relation = TransitiveRelationBuilder::default();
     relation.add("a", "c");
     relation.add("c", "d");
     relation.add("d", "e");
     relation.add("e", "c");
     relation.add("a", "d");
     relation.add("b", "e");
+    let relation = relation.freeze();
 
     assert_eq!(relation.minimal_upper_bounds("a", "b"), vec!["c"]);
 }
@@ -352,10 +367,11 @@ fn parent() {
         (1, /*->*/ 3),
     ];
 
-    let mut relation = TransitiveRelation::default();
+    let mut relation = TransitiveRelationBuilder::default();
     for (a, b) in pairs {
         relation.add(a, b);
     }
+    let relation = relation.freeze();
 
     let p = relation.postdom_parent(3);
     assert_eq!(p, Some(0));