Skip to content

Add match-stress benchmark. #1208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions collector/benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ compiler in interesting ways.
- **deep-vector**: A test containing a single large vector of zeroes, which
caused [poor performance](https://github.com/rust-lang/rust/issues/20936) in
the past.
- **derive**: A large amount of simple structs with a `#[derive]` attribute for common built-in traits such as Copy and Debug.
- **externs**: A large amount of extern functions has caused [slowdowns in the past](https://github.com/rust-lang/rust/pull/78448).
- **derive**: A large number of simple structs with a `#[derive]` attribute for common built-in traits such as Copy and Debug.
- **externs**: A large number of extern functions has caused [slowdowns in the past](https://github.com/rust-lang/rust/pull/78448).
- **issue-46449**: A small program that caused [poor
performance](https://github.com/rust-lang/rust/issues/46449) in the past.
- **issue-58319**: A small program that caused [poor
Expand All @@ -95,6 +95,11 @@ compiler in interesting ways.
- **many-assoc-items**: Contains a struct with many associated items, which
caused [quadratic behavior](https://github.com/rust-lang/rust/issues/68957)
in the past.
- **match-stress**: Contains examples
(one involving [a huge enum](https://github.com/rust-lang/rust/issues/7462),
one involving
[`exhaustive_patterns`](https://github.com/rust-lang/rust/pull/79394)) of
`match` code that caused bad performance in the past.
- **match-stress-enum**: Contains a match against a huge enum, which used to
have [quadratic runtime](https://github.com/rust-lang/rust/issues/7462).
- **match-stress-exhaustive_patterns**: Contains code extracted from the `syn`
Expand Down
7 changes: 7 additions & 0 deletions collector/benchmarks/match-stress/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions collector/benchmarks/match-stress/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "match-stress"
version = "0.1.0"

[workspace]
4 changes: 4 additions & 0 deletions collector/benchmarks/match-stress/perf-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"touch_file": "src/lib.rs",
"category": "secondary"
}
78 changes: 78 additions & 0 deletions collector/benchmarks/match-stress/src/attr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
use super::*;
use delimited::Delimited;

ast_enum! {
/// Distinguishes between Attributes that decorate items and Attributes that
/// are contained as statements within items. These two cases need to be
/// distinguished for pretty-printing.
pub enum AttrStyle {
/// Attribute of the form `#[...]`.
Outer,

/// Attribute of the form `#![...]`.
Inner(tokens::Bang),
}
}

ast_enum_of_structs! {
/// A compile-time attribute item.
///
/// E.g. `#[test]`, `#[derive(..)]` or `#[feature = "foo"]`
pub enum MetaItem {
/// Term meta item.
///
/// E.g. `test` as in `#[test]`
pub Term(Ident),

/// List meta item.
///
/// E.g. `derive(..)` as in `#[derive(..)]`
pub List(MetaItemList {
/// Name of this attribute.
///
/// E.g. `derive` in `#[derive(..)]`
pub ident: Ident,

pub paren_token: tokens::Paren,

/// Arguments to this attribute
///
/// E.g. `..` in `#[derive(..)]`
pub nested: Delimited,
}),

/// Name-value meta item.
///
/// E.g. `feature = "foo"` as in `#[feature = "foo"]`
pub NameValue(MetaNameValue {
/// Name of this attribute.
///
/// E.g. `feature` in `#[feature = "foo"]`
pub ident: Ident,

pub eq_token: tokens::Eq,

/// Arguments to this attribute
///
/// E.g. `"foo"` in `#[feature = "foo"]`
pub lit: Lit,
}),
}
}

ast_enum_of_structs! {
/// Possible values inside of compile-time attribute lists.
///
/// E.g. the '..' in `#[name(..)]`.
pub enum NestedMetaItem {
/// A full `MetaItem`.
///
/// E.g. `Copy` in `#[derive(Copy)]` would be a `MetaItem::Term(Ident::from("Copy"))`.
pub MetaItem(MetaItem),

/// A Rust literal.
///
/// E.g. `"name"` in `#[rename("name")]`.
pub Literal(Lit),
}
}
84 changes: 84 additions & 0 deletions collector/benchmarks/match-stress/src/data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use super::*;
use delimited::Delimited;

ast_struct! {
/// An enum variant.
pub struct Variant {
/// Name of the variant.
pub ident: Ident,

/// Attributes tagged on the variant.
pub attrs: Vec<u64>,

/// Type of variant.
pub data: VariantData,

/// Explicit discriminant, e.g. `Foo = 1`
pub discriminant: Option<Expr>,

pub eq_token: Option<tokens::Eq>,
}
}

ast_enum! {
/// Data stored within an enum variant or struct.
pub enum VariantData {
/// Struct variant, e.g. `Point { x: f64, y: f64 }`.
Struct(Delimited, tokens::Brace),

/// Tuple variant, e.g. `Some(T)`.
Tuple(Delimited, tokens::Paren),

/// Unit variant, e.g. `None`.
Unit,
}
}

ast_struct! {
/// A field of a struct or enum variant.
pub struct Field {
/// Name of the field, if any.
///
/// Fields of tuple structs have no names.
pub ident: Option<Ident>,

/// Visibility of the field.
pub vis: Visibility,

/// Attributes tagged on the field.
pub attrs: Vec<u64>,

/// Type of the field.
pub ty: Ty,

pub colon_token: Option<tokens::Colon>,
}
}

ast_enum_of_structs! {
/// Visibility level of an item.
pub enum Visibility {
/// Public, i.e. `pub`.
pub Public(VisPublic {
pub pub_token: tokens::Pub,
}),

/// Crate-visible, i.e. `pub(crate)`.
pub Crate(VisCrate {
pub pub_token: tokens::Pub,
pub paren_token: tokens::Paren,
pub crate_token: tokens::Crate,
}),

/// Restricted, e.g. `pub(self)` or `pub(super)` or `pub(in some::module)`.
pub Restricted(VisRestricted {
pub pub_token: tokens::Pub,
pub paren_token: tokens::Paren,
pub in_token: Option<tokens::In>,
pub path: Box<u64>,
}),

/// Inherited, i.e. private.
pub Inherited(VisInherited {}),
}
}
Loading