Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/mbe/src/benchmark.rs')
-rw-r--r--crates/mbe/src/benchmark.rs35
1 files changed, 16 insertions, 19 deletions
diff --git a/crates/mbe/src/benchmark.rs b/crates/mbe/src/benchmark.rs
index b185556b5c..603fee7306 100644
--- a/crates/mbe/src/benchmark.rs
+++ b/crates/mbe/src/benchmark.rs
@@ -2,7 +2,6 @@
use intern::Symbol;
use rustc_hash::FxHashMap;
-use span::{Edition, Span};
use stdx::itertools::Itertools;
use syntax::{
AstNode,
@@ -16,7 +15,7 @@ use syntax_bridge::{
use test_utils::{bench, bench_fixture, skip_slow_tests};
use crate::{
- DeclarativeMacro,
+ DeclarativeMacro, MacroCallStyle,
parser::{MetaVarKind, Op, RepeatKind, Separator},
};
@@ -44,17 +43,18 @@ fn benchmark_expand_macro_rules() {
if skip_slow_tests() {
return;
}
+ let db = salsa::DatabaseImpl::default();
let rules = macro_rules_fixtures();
- let invocations = invocation_fixtures(&rules);
+ let invocations = invocation_fixtures(&db, &rules);
let hash: usize = {
let _pt = bench("mbe expand macro rules");
invocations
.into_iter()
.map(|(id, tt)| {
- let res = rules[&id].expand(&tt, |_| (), DUMMY, Edition::CURRENT);
+ let res = rules[&id].expand(&db, &tt, |_| (), MacroCallStyle::FnLike, DUMMY);
assert!(res.err.is_none());
- res.value.0.0.len()
+ res.value.0.as_token_trees().len()
})
.sum()
};
@@ -69,7 +69,7 @@ fn macro_rules_fixtures() -> FxHashMap<String, DeclarativeMacro> {
.collect()
}
-fn macro_rules_fixtures_tt() -> FxHashMap<String, tt::TopSubtree<Span>> {
+fn macro_rules_fixtures_tt() -> FxHashMap<String, tt::TopSubtree> {
let fixture = bench_fixture::numerous_macro_rules();
let source_file = ast::SourceFile::parse(&fixture, span::Edition::CURRENT).ok().unwrap();
@@ -92,8 +92,9 @@ fn macro_rules_fixtures_tt() -> FxHashMap<String, tt::TopSubtree<Span>> {
/// Generate random invocation fixtures from rules
fn invocation_fixtures(
+ db: &dyn salsa::Database,
rules: &FxHashMap<String, DeclarativeMacro>,
-) -> Vec<(String, tt::TopSubtree<Span>)> {
+) -> Vec<(String, tt::TopSubtree)> {
let mut seed = 123456789;
let mut res = Vec::new();
@@ -123,7 +124,8 @@ fn invocation_fixtures(
}
let subtree = builder.build();
- if it.expand(&subtree, |_| (), DUMMY, Edition::CURRENT).err.is_none() {
+ if it.expand(db, &subtree, |_| (), MacroCallStyle::FnLike, DUMMY).err.is_none()
+ {
res.push((name.clone(), subtree));
break;
}
@@ -137,7 +139,7 @@ fn invocation_fixtures(
}
return res;
- fn collect_from_op(op: &Op, builder: &mut tt::TopSubtreeBuilder<Span>, seed: &mut usize) {
+ fn collect_from_op(op: &Op, builder: &mut tt::TopSubtreeBuilder, seed: &mut usize) {
return match op {
Op::Var { kind, .. } => match kind.as_ref() {
Some(MetaVarKind::Ident) => builder.push(make_ident("foo")),
@@ -223,25 +225,20 @@ fn invocation_fixtures(
*seed = usize::wrapping_add(usize::wrapping_mul(*seed, a), c);
*seed
}
- fn make_ident(ident: &str) -> tt::Leaf<Span> {
+ fn make_ident(ident: &str) -> tt::Leaf {
tt::Leaf::Ident(tt::Ident {
span: DUMMY,
sym: Symbol::intern(ident),
is_raw: tt::IdentIsRaw::No,
})
}
- fn make_punct(char: char) -> tt::Leaf<Span> {
+ fn make_punct(char: char) -> tt::Leaf {
tt::Leaf::Punct(tt::Punct { span: DUMMY, char, spacing: tt::Spacing::Alone })
}
- fn make_literal(lit: &str) -> tt::Leaf<Span> {
- tt::Leaf::Literal(tt::Literal {
- span: DUMMY,
- symbol: Symbol::intern(lit),
- kind: tt::LitKind::Str,
- suffix: None,
- })
+ fn make_literal(lit: &str) -> tt::Leaf {
+ tt::Leaf::Literal(tt::Literal::new_no_suffix(lit, DUMMY, tt::LitKind::Str))
}
- fn make_subtree(kind: tt::DelimiterKind, builder: &mut tt::TopSubtreeBuilder<Span>) {
+ fn make_subtree(kind: tt::DelimiterKind, builder: &mut tt::TopSubtreeBuilder) {
builder.open(kind, DUMMY);
builder.close(DUMMY);
}