diff --git a/src/runtime.rs b/src/runtime.rs index d47d519..51c8561 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 1cc3ba1..f924069 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 16d28e2..a37d6f6 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)", ], ) "#]];