Skip to content

Commit 30d76ac

Browse files
committed
Add match-stress benchmark.
This combines the two existing `match-stress-*` benchmarks. They will be removed soon.
1 parent bc1f2fc commit 30d76ac

File tree

16 files changed

+18612
-2
lines changed

16 files changed

+18612
-2
lines changed

collector/benchmarks/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ compiler in interesting ways.
8181
- **deep-vector**: A test containing a single large vector of zeroes, which
8282
caused [poor performance](https://github.com/rust-lang/rust/issues/20936) in
8383
the past.
84-
- **derive**: A large amount of simple structs with a `#[derive]` attribute for common built-in traits such as Copy and Debug.
85-
- **externs**: A large amount of extern functions has caused [slowdowns in the past](https://github.com/rust-lang/rust/pull/78448).
84+
- **derive**: A large number of simple structs with a `#[derive]` attribute for common built-in traits such as Copy and Debug.
85+
- **externs**: A large number of extern functions has caused [slowdowns in the past](https://github.com/rust-lang/rust/pull/78448).
8686
- **issue-46449**: A small program that caused [poor
8787
performance](https://github.com/rust-lang/rust/issues/46449) in the past.
8888
- **issue-58319**: A small program that caused [poor
@@ -95,6 +95,11 @@ compiler in interesting ways.
9595
- **many-assoc-items**: Contains a struct with many associated items, which
9696
caused [quadratic behavior](https://github.com/rust-lang/rust/issues/68957)
9797
in the past.
98+
- **match-stress**: Contains examples
99+
(one involving [a huge enum](https://github.com/rust-lang/rust/issues/7462),
100+
one involving
101+
[`exhaustive_patterns`](https://github.com/rust-lang/rust/pull/79394)) of
102+
`match` code that caused bad performance in the past.
98103
- **match-stress-enum**: Contains a match against a huge enum, which used to
99104
have [quadratic runtime](https://github.com/rust-lang/rust/issues/7462).
100105
- **match-stress-exhaustive_patterns**: Contains code extracted from the `syn`

collector/benchmarks/match-stress/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "match-stress"
3+
version = "0.1.0"
4+
5+
[workspace]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"touch_file": "src/lib.rs",
3+
"category": "secondary"
4+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
use super::*;
2+
use delimited::Delimited;
3+
4+
ast_enum! {
5+
/// Distinguishes between Attributes that decorate items and Attributes that
6+
/// are contained as statements within items. These two cases need to be
7+
/// distinguished for pretty-printing.
8+
pub enum AttrStyle {
9+
/// Attribute of the form `#[...]`.
10+
Outer,
11+
12+
/// Attribute of the form `#![...]`.
13+
Inner(tokens::Bang),
14+
}
15+
}
16+
17+
ast_enum_of_structs! {
18+
/// A compile-time attribute item.
19+
///
20+
/// E.g. `#[test]`, `#[derive(..)]` or `#[feature = "foo"]`
21+
pub enum MetaItem {
22+
/// Term meta item.
23+
///
24+
/// E.g. `test` as in `#[test]`
25+
pub Term(Ident),
26+
27+
/// List meta item.
28+
///
29+
/// E.g. `derive(..)` as in `#[derive(..)]`
30+
pub List(MetaItemList {
31+
/// Name of this attribute.
32+
///
33+
/// E.g. `derive` in `#[derive(..)]`
34+
pub ident: Ident,
35+
36+
pub paren_token: tokens::Paren,
37+
38+
/// Arguments to this attribute
39+
///
40+
/// E.g. `..` in `#[derive(..)]`
41+
pub nested: Delimited,
42+
}),
43+
44+
/// Name-value meta item.
45+
///
46+
/// E.g. `feature = "foo"` as in `#[feature = "foo"]`
47+
pub NameValue(MetaNameValue {
48+
/// Name of this attribute.
49+
///
50+
/// E.g. `feature` in `#[feature = "foo"]`
51+
pub ident: Ident,
52+
53+
pub eq_token: tokens::Eq,
54+
55+
/// Arguments to this attribute
56+
///
57+
/// E.g. `"foo"` in `#[feature = "foo"]`
58+
pub lit: Lit,
59+
}),
60+
}
61+
}
62+
63+
ast_enum_of_structs! {
64+
/// Possible values inside of compile-time attribute lists.
65+
///
66+
/// E.g. the '..' in `#[name(..)]`.
67+
pub enum NestedMetaItem {
68+
/// A full `MetaItem`.
69+
///
70+
/// E.g. `Copy` in `#[derive(Copy)]` would be a `MetaItem::Term(Ident::from("Copy"))`.
71+
pub MetaItem(MetaItem),
72+
73+
/// A Rust literal.
74+
///
75+
/// E.g. `"name"` in `#[rename("name")]`.
76+
pub Literal(Lit),
77+
}
78+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
use super::*;
2+
use delimited::Delimited;
3+
4+
ast_struct! {
5+
/// An enum variant.
6+
pub struct Variant {
7+
/// Name of the variant.
8+
pub ident: Ident,
9+
10+
/// Attributes tagged on the variant.
11+
pub attrs: Vec<u64>,
12+
13+
/// Type of variant.
14+
pub data: VariantData,
15+
16+
/// Explicit discriminant, e.g. `Foo = 1`
17+
pub discriminant: Option<Expr>,
18+
19+
pub eq_token: Option<tokens::Eq>,
20+
}
21+
}
22+
23+
ast_enum! {
24+
/// Data stored within an enum variant or struct.
25+
pub enum VariantData {
26+
/// Struct variant, e.g. `Point { x: f64, y: f64 }`.
27+
Struct(Delimited, tokens::Brace),
28+
29+
/// Tuple variant, e.g. `Some(T)`.
30+
Tuple(Delimited, tokens::Paren),
31+
32+
/// Unit variant, e.g. `None`.
33+
Unit,
34+
}
35+
}
36+
37+
ast_struct! {
38+
/// A field of a struct or enum variant.
39+
pub struct Field {
40+
/// Name of the field, if any.
41+
///
42+
/// Fields of tuple structs have no names.
43+
pub ident: Option<Ident>,
44+
45+
/// Visibility of the field.
46+
pub vis: Visibility,
47+
48+
/// Attributes tagged on the field.
49+
pub attrs: Vec<u64>,
50+
51+
/// Type of the field.
52+
pub ty: Ty,
53+
54+
pub colon_token: Option<tokens::Colon>,
55+
}
56+
}
57+
58+
ast_enum_of_structs! {
59+
/// Visibility level of an item.
60+
pub enum Visibility {
61+
/// Public, i.e. `pub`.
62+
pub Public(VisPublic {
63+
pub pub_token: tokens::Pub,
64+
}),
65+
66+
/// Crate-visible, i.e. `pub(crate)`.
67+
pub Crate(VisCrate {
68+
pub pub_token: tokens::Pub,
69+
pub paren_token: tokens::Paren,
70+
pub crate_token: tokens::Crate,
71+
}),
72+
73+
/// Restricted, e.g. `pub(self)` or `pub(super)` or `pub(in some::module)`.
74+
pub Restricted(VisRestricted {
75+
pub pub_token: tokens::Pub,
76+
pub paren_token: tokens::Paren,
77+
pub in_token: Option<tokens::In>,
78+
pub path: Box<u64>,
79+
}),
80+
81+
/// Inherited, i.e. private.
82+
pub Inherited(VisInherited {}),
83+
}
84+
}

0 commit comments

Comments
 (0)