From a5395665cef6013af9730280225097b914825f22 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 24 Jul 2024 10:10:37 +0000 Subject: [PATCH] order cycles by debug_name first We used to sort just by the ingredient index, but since those are now added dynamically, that can be fairly unstable in some of the tests. We now sort by the "debug name" of the ingredient first, which is more reliably stable. --- src/runtime.rs | 7 ++++++- src/storage.rs | 5 +++++ tests/cycles.rs | 6 +++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/runtime.rs b/src/runtime.rs index d47d5193..51c8561d 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -281,7 +281,12 @@ impl Runtime { // (at least for this execution, not necessarily across executions), // no matter where it started on the stack. Find the minimum // key and rotate it to the front. - let min = v.iter().min().unwrap(); + let min = v + .iter() + .map(|key| (key.ingredient_index.debug_name(db), key)) + .min() + .unwrap() + .1; let index = v.iter().position(|p| p == min).unwrap(); v.rotate_left(index); diff --git a/src/storage.rs b/src/storage.rs index 1cc3ba1f..f924069b 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -201,6 +201,11 @@ impl IngredientIndex { pub fn successor(self, index: usize) -> Self { IngredientIndex(self.0 + 1 + index as u32) } + + /// Return the "debug name" of this ingredient (e.g., the name of the tracked struct it represents) + pub(crate) fn debug_name(self, db: &dyn Database) -> &'static str { + db.lookup_ingredient(self).debug_name() + } } /// The "storage" struct stores all the data for the jars. diff --git a/tests/cycles.rs b/tests/cycles.rs index 16d28e20..a37d6f6c 100644 --- a/tests/cycles.rs +++ b/tests/cycles.rs @@ -220,8 +220,8 @@ fn inner_cycle() { assert!(err.is_err()); let expected = expect![[r#" [ - "cycle_b(0)", "cycle_a(0)", + "cycle_b(0)", ] "#]]; expected.assert_debug_eq(&err.unwrap_err().cycle); @@ -328,8 +328,8 @@ fn cycle_mixed_1() { let expected = expect![[r#" [ - "cycle_c(0)", "cycle_b(0)", + "cycle_c(0)", ] "#]]; expected.assert_debug_eq(&cycle_c(db, abc).unwrap_err().cycle); @@ -379,8 +379,8 @@ fn cycle_deterministic_order() { "cycle_b(0)", ], [ - "cycle_b(0)", "cycle_a(0)", + "cycle_b(0)", ], ) "#]];