Skip to content

Commit

Permalink
re-order enums in grammar (#1074)
Browse files Browse the repository at this point in the history
To achieve two goals:

- We attempt variants that can be identified using the first token,
before trying variants that will fail after multiple ones are scanned
correctly, and wasting time on expensive backtracking.
- We attempt more correct/idiomatic variants first, before attempting
deprecated/less common variants.

This resulted in the following improvements to perf metrics:

<a
href="https://bencher.dev/perf/slang?key=true&reports_per_page=4&branches_per_page=8&testbeds_per_page=8&benchmarks_per_page=8&plots_per_page=8&reports_page=1&branches_page=1&testbeds_page=1&benchmarks_page=1&plots_page=1&branches=f658ee3c-6d7a-45eb-89f6-03070b74ec7b&testbeds=3b5cd476-1960-445e-a626-4bc112d566b4&benchmarks=8f3fd136-0816-481d-8819-abda60d7631f&measures=66e3fa8c-953e-406f-bfd6-6d38c9044aee&start_time=1720137600000&end_time=1724112000000&clear=true&tab=benchmarks"><img
src="https://api.bencher.dev/v0/projects/slang/perf/img?branches=f658ee3c-6d7a-45eb-89f6-03070b74ec7b&testbeds=3b5cd476-1960-445e-a626-4bc112d566b4&benchmarks=8f3fd136-0816-481d-8819-abda60d7631f&measures=66e3fa8c-953e-406f-bfd6-6d38c9044aee&start_time=1720137600000&end_time=1724112000000"
title="Slang" alt="Slang - Bencher" /></a>

<a
href="https://bencher.dev/perf/slang?key=true&reports_per_page=4&branches_per_page=8&testbeds_per_page=8&benchmarks_per_page=8&plots_per_page=8&reports_page=1&branches_page=1&testbeds_page=1&benchmarks_page=1&plots_page=1&branches=f658ee3c-6d7a-45eb-89f6-03070b74ec7b&testbeds=3b5cd476-1960-445e-a626-4bc112d566b4&benchmarks=8f3fd136-0816-481d-8819-abda60d7631f&measures=6d072304-d057-4560-a194-9ec92d4a4697&start_time=1720137600000&end_time=1724112000000&clear=true&tab=benchmarks"><img
src="https://api.bencher.dev/v0/projects/slang/perf/img?branches=f658ee3c-6d7a-45eb-89f6-03070b74ec7b&testbeds=3b5cd476-1960-445e-a626-4bc112d566b4&benchmarks=8f3fd136-0816-481d-8819-abda60d7631f&measures=6d072304-d057-4560-a194-9ec92d4a4697&start_time=1720137600000&end_time=1724112000000"
title="Slang" alt="Slang - Bencher" /></a>

<a
href="https://bencher.dev/perf/slang?key=true&reports_per_page=4&branches_per_page=8&testbeds_per_page=8&benchmarks_per_page=8&plots_per_page=8&reports_page=1&branches_page=1&testbeds_page=1&benchmarks_page=1&plots_page=1&branches=f658ee3c-6d7a-45eb-89f6-03070b74ec7b&testbeds=3b5cd476-1960-445e-a626-4bc112d566b4&benchmarks=8f3fd136-0816-481d-8819-abda60d7631f&measures=0890137e-c82f-4c68-bd4a-9c035fc9c54d&start_time=1720137600000&end_time=1724112000000&clear=true&tab=benchmarks"><img
src="https://api.bencher.dev/v0/projects/slang/perf/img?branches=f658ee3c-6d7a-45eb-89f6-03070b74ec7b&testbeds=3b5cd476-1960-445e-a626-4bc112d566b4&benchmarks=8f3fd136-0816-481d-8819-abda60d7631f&measures=0890137e-c82f-4c68-bd4a-9c035fc9c54d&start_time=1720137600000&end_time=1724112000000"
title="Slang" alt="Slang - Bencher" /></a>
  • Loading branch information
OmarTawfik authored Aug 16, 2024
1 parent 56ef627 commit 05dd100
Show file tree
Hide file tree
Showing 28 changed files with 272 additions and 302 deletions.
40 changes: 19 additions & 21 deletions crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ codegen_language_macros::compile!(Language(
reference = FunctionDefinition,
enabled = From("0.7.1")
),
EnumVariant(
reference = ConstantDefinition,
enabled = From("0.7.4")
),
EnumVariant(reference = ErrorDefinition, enabled = From("0.8.4")),
EnumVariant(
reference = UserDefinedValueTypeDefinition,
enabled = From("0.8.8")
),
EnumVariant(reference = UsingDirective, enabled = From("0.8.13")),
EnumVariant(reference = EventDefinition, enabled = From("0.8.22"))
EnumVariant(reference = EventDefinition, enabled = From("0.8.22")),
EnumVariant(
reference = ConstantDefinition,
enabled = From("0.7.4")
)
]
)
]
Expand Down Expand Up @@ -2142,12 +2142,12 @@ codegen_language_macros::compile!(Language(
EnumVariant(reference = StructDefinition),
EnumVariant(reference = EnumDefinition),
EnumVariant(reference = EventDefinition),
EnumVariant(reference = StateVariableDefinition),
EnumVariant(reference = ErrorDefinition, enabled = From("0.8.4")),
EnumVariant(
reference = UserDefinedValueTypeDefinition,
enabled = From("0.8.8")
)
),
EnumVariant(reference = StateVariableDefinition)
]
)
]
Expand Down Expand Up @@ -2835,11 +2835,6 @@ codegen_language_macros::compile!(Language(
Enum(
name = Statement,
variants = [
// Simple statements
EnumVariant(reference = ExpressionStatement),
EnumVariant(reference = VariableDeclarationStatement),
EnumVariant(reference = TupleDeconstructionStatement),
// Control statements
EnumVariant(reference = IfStatement),
EnumVariant(reference = ForStatement),
EnumVariant(reference = WhileStatement),
Expand All @@ -2853,7 +2848,10 @@ codegen_language_macros::compile!(Language(
EnumVariant(reference = RevertStatement, enabled = From("0.8.4")),
EnumVariant(reference = AssemblyStatement),
EnumVariant(reference = Block),
EnumVariant(reference = UncheckedBlock, enabled = From("0.8.0"))
EnumVariant(reference = UncheckedBlock, enabled = From("0.8.0")),
EnumVariant(reference = TupleDeconstructionStatement),
EnumVariant(reference = VariableDeclarationStatement),
EnumVariant(reference = ExpressionStatement)
]
),
Struct(
Expand Down Expand Up @@ -3028,9 +3026,9 @@ codegen_language_macros::compile!(Language(
Enum(
name = ForStatementInitialization,
variants = [
EnumVariant(reference = ExpressionStatement),
EnumVariant(reference = VariableDeclarationStatement),
EnumVariant(reference = TupleDeconstructionStatement),
EnumVariant(reference = VariableDeclarationStatement),
EnumVariant(reference = ExpressionStatement),
EnumVariant(reference = Semicolon)
]
),
Expand Down Expand Up @@ -4163,8 +4161,6 @@ codegen_language_macros::compile!(Language(
variants = [
EnumVariant(reference = YulBlock),
EnumVariant(reference = YulFunctionDefinition),
EnumVariant(reference = YulVariableDeclarationStatement),
EnumVariant(reference = YulVariableAssignmentStatement),
EnumVariant(
reference = YulStackAssignmentStatement,
enabled = Till("0.5.0")
Expand All @@ -4176,6 +4172,8 @@ codegen_language_macros::compile!(Language(
EnumVariant(reference = YulBreakStatement),
EnumVariant(reference = YulContinueStatement),
EnumVariant(reference = YulLabel, enabled = Till("0.5.0")),
EnumVariant(reference = YulVariableDeclarationStatement),
EnumVariant(reference = YulVariableAssignmentStatement),
EnumVariant(reference = YulExpression)
]
),
Expand Down Expand Up @@ -4245,8 +4243,8 @@ codegen_language_macros::compile!(Language(
Enum(
name = YulAssignmentOperator,
variants = [
EnumVariant(reference = YulColonAndEqual, enabled = Till("0.5.5")),
EnumVariant(reference = ColonEqual)
EnumVariant(reference = ColonEqual),
EnumVariant(reference = YulColonAndEqual, enabled = Till("0.5.5"))
]
),
Struct(
Expand All @@ -4266,8 +4264,8 @@ codegen_language_macros::compile!(Language(
name = YulStackAssignmentOperator,
enabled = Till("0.5.0"),
variants = [
EnumVariant(reference = YulEqualAndColon),
EnumVariant(reference = EqualColon)
EnumVariant(reference = EqualColon),
EnumVariant(reference = YulEqualAndColon)
]
),
Struct(
Expand Down

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

Loading

0 comments on commit 05dd100

Please sign in to comment.