Skip to content

Commit 9e7d082

Browse files
committed
Don't require test::Coverage to implement Ord
This derive was an artifact of test-only method `Cache::all` wanting to automatically sort its output to hide HashMap iteration order. We can achieve an equivalent result by requiring the caller to provide a projection function that returns results that _are_ sortable.
1 parent ba2142a commit 9e7d082

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,7 @@ test!(AssemblyLlvm {
15821582

15831583
/// Runs the coverage test suite at `tests/coverage` in some or all of the
15841584
/// coverage test modes.
1585-
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1585+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
15861586
pub struct Coverage {
15871587
pub compiler: Compiler,
15881588
pub target: TargetSelection,

src/bootstrap/src/core/builder/tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,7 @@ fn test_test_coverage() {
345345
let config = configure_with_args(cmd, &[], &[TEST_TRIPLE_1]);
346346
let mut cache = run_build(&config.paths.clone(), config);
347347

348-
let modes =
349-
cache.all::<test::Coverage>().iter().map(|(step, ())| step.mode).collect::<Vec<_>>();
348+
let modes = cache.inspect_all_steps_of_type::<test::Coverage, _>(|step, ()| step.mode);
350349
assert_eq!(modes, expected);
351350
}
352351
}

src/bootstrap/src/utils/cache.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,18 @@ impl Cache {
270270

271271
#[cfg(test)]
272272
impl Cache {
273-
pub fn all<S: Ord + Step>(&mut self) -> Vec<(S, S::Output)> {
274-
let cache = self.cache.get_mut();
275-
let type_id = TypeId::of::<S>();
276-
let mut v = cache
277-
.remove(&type_id)
278-
.map(|b| b.downcast::<HashMap<S, S::Output>>().expect("correct type"))
279-
.map(|m| m.into_iter().collect::<Vec<_>>())
273+
pub(crate) fn inspect_all_steps_of_type<S: Step, T: Ord>(
274+
&self,
275+
map_fn: impl Fn(&S, &S::Output) -> T,
276+
) -> Vec<T> {
277+
let cache = self.cache.borrow();
278+
let mut values = cache
279+
.get(&TypeId::of::<S>())
280+
.map(|any| any.downcast_ref::<HashMap<S, S::Output>>().expect("correct type"))
281+
.map(|m| m.iter().map(|(step, output)| map_fn(step, output)).collect::<Vec<_>>())
280282
.unwrap_or_default();
281-
v.sort_by_key(|(s, _)| s.clone());
282-
v
283+
values.sort();
284+
values
283285
}
284286

285287
pub fn contains<S: Step>(&self) -> bool {

0 commit comments

Comments
 (0)