Skip to content

Commit 7e62953

Browse files
committed
shuffle based on defpathhash
1 parent a7bbac8 commit 7e62953

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3809,6 +3809,8 @@ name = "rustc_hir_analysis"
38093809
version = "0.0.0"
38103810
dependencies = [
38113811
"itertools",
3812+
"rand 0.9.1",
3813+
"rand_xoshiro",
38123814
"rustc_abi",
38133815
"rustc_arena",
38143816
"rustc_ast",

compiler/rustc_hir_analysis/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ doctest = false
1010
[dependencies]
1111
# tidy-alphabetical-start
1212
itertools = "0.12"
13+
rand = { version = "0.9.0", default-features = false }
14+
rand_xoshiro = { version = "0.7.0" }
1315
rustc_abi = { path = "../rustc_abi" }
1416
rustc_arena = { path = "../rustc_arena" }
1517
rustc_ast = { path = "../rustc_ast" }
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use rand::SeedableRng;
2+
use rand::seq::SliceRandom;
13
use rustc_hir::def_id::{DefIdMap, LocalDefId};
24
use rustc_hir::{DistributedSlice, ItemKind};
35
use rustc_middle::ty::TyCtxt;
@@ -6,16 +8,29 @@ pub(super) fn distributed_slice_elements<'tcx>(
68
tcx: TyCtxt<'tcx>,
79
_: (),
810
) -> DefIdMap<Vec<LocalDefId>> {
9-
let mut res = DefIdMap::<Vec<LocalDefId>>::default();
11+
let mut slice_elements = DefIdMap::<Vec<LocalDefId>>::default();
1012

1113
for i in tcx.hir_free_items() {
1214
let addition_def_id = i.owner_id.def_id;
1315
if let ItemKind::Const(.., DistributedSlice::Addition(declaration_def_id)) =
1416
tcx.hir_expect_item(addition_def_id).kind
1517
{
16-
res.entry(declaration_def_id.to_def_id()).or_default().push(addition_def_id);
18+
slice_elements.entry(declaration_def_id.to_def_id()).or_default().push(addition_def_id);
1719
}
1820
}
1921

22+
let mut res = DefIdMap::<Vec<LocalDefId>>::default();
23+
24+
for (key, mut registered_values) in
25+
tcx.with_stable_hashing_context(|hcx| slice_elements.into_sorted(&hcx, true))
26+
{
27+
// shuffle seeded by the defpathhash of the registry
28+
let item_seed = tcx.def_path_hash(key).0.to_smaller_hash();
29+
let mut rng = rand_xoshiro::Xoshiro128StarStar::seed_from_u64(item_seed.as_u64());
30+
registered_values.as_mut_slice().shuffle(&mut rng);
31+
32+
res.insert(key, registered_values);
33+
}
34+
2035
res
2136
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
["mrow", "mew"]
1+
["mew", "mrow"]

0 commit comments

Comments
 (0)