Skip to content

Commit

Permalink
fix: FIx mbe bench tests being iteration order dependent
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Oct 21, 2024
1 parent e9da1dc commit 2adc6c3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/tools/rust-analyzer/crates/mbe/src/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use intern::Symbol;
use rustc_hash::FxHashMap;
use span::{Edition, Span};
use stdx::itertools::Itertools;
use syntax::{
ast::{self, HasName},
AstNode,
Expand All @@ -27,9 +28,10 @@ fn benchmark_parse_macro_rules() {
let hash: usize = {
let _pt = bench("mbe parse macro rules");
rules
.values()
.map(|it| {
DeclarativeMacro::parse_macro_rules(it, |_| span::Edition::CURRENT).rules.len()
.into_iter()
.sorted_by_key(|(id, _)| id.clone())
.map(|(_, it)| {
DeclarativeMacro::parse_macro_rules(&it, |_| span::Edition::CURRENT).rules.len()
})
.sum()
};
Expand All @@ -55,12 +57,13 @@ fn benchmark_expand_macro_rules() {
})
.sum()
};
assert_eq!(hash, 76353);
assert_eq!(hash, 65720);
}

fn macro_rules_fixtures() -> FxHashMap<String, DeclarativeMacro> {
macro_rules_fixtures_tt()
.into_iter()
.sorted_by_key(|(id, _)| id.clone())
.map(|(id, tt)| (id, DeclarativeMacro::parse_macro_rules(&tt, |_| span::Edition::CURRENT)))
.collect()
}
Expand Down Expand Up @@ -93,7 +96,7 @@ fn invocation_fixtures(
let mut seed = 123456789;
let mut res = Vec::new();

for (name, it) in rules {
for (name, it) in rules.iter().sorted_by_key(|&(id, _)| id) {
for rule in it.rules.iter() {
// Generate twice
for _ in 0..2 {
Expand Down

0 comments on commit 2adc6c3

Please sign in to comment.