Skip to content

Commit

Permalink
re-organize perf benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarTawfik committed Jan 2, 2025
1 parent 68bf29c commit 3c4fb33
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 131 deletions.
20 changes: 5 additions & 15 deletions crates/solidity/testing/perf/benches/iai/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,14 @@ use iai_callgrind::{
library_benchmark, library_benchmark_group, main, Direction, FlamegraphConfig,
LibraryBenchmarkConfig, Tool, ValgrindTool,
};
use slang_solidity::bindings::BindingGraphBuilder;
use solidity_testing_perf::dataset::SourceFile;
use solidity_testing_perf::tests::definitions::Dependencies;
use solidity_testing_perf::tests::bindings_resolve::BuiltBindingGraph;
use solidity_testing_perf::tests::parser::ParsedFile;

mod __dependencies_used_in_lib__ {
use {infra_utils as _, metaslang_bindings as _, semver as _};
use {infra_utils as _, metaslang_bindings as _, semver as _, slang_solidity as _};
}

macro_rules! define_benchmark {
($name:ident) => {
#[library_benchmark]
fn $name() {
black_box(solidity_testing_perf::tests::$name::run());
}
};
}
macro_rules! define_payload_benchmark {
($name:ident, $payload:ty) => {
#[library_benchmark(setup = solidity_testing_perf::tests::$name::setup)]
Expand All @@ -43,15 +34,14 @@ macro_rules! define_payload_benchmark {
define_payload_benchmark!(parser, Vec<SourceFile>);
define_payload_benchmark!(cursor, Vec<ParsedFile>);
define_payload_benchmark!(query, Vec<ParsedFile>);
define_benchmark!(init_bindings);
define_payload_benchmark!(definitions, Dependencies);
define_payload_benchmark!(references, BindingGraphBuilder);
define_payload_benchmark!(bindings_build, Vec<ParsedFile>);
define_payload_benchmark!(bindings_resolve, BuiltBindingGraph);

library_benchmark_group!(
name = benchmarks;

// __SLANG_INFRA_BENCHMARKS_LIST__ (keep in sync)
benchmarks = parser, cursor, query, init_bindings, definitions, references
benchmarks = parser, cursor, query, bindings_build, bindings_resolve,
);

main!(
Expand Down
13 changes: 2 additions & 11 deletions crates/solidity/testing/perf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ mod __dependencies_used_in_benches__ {

#[cfg(test)]
mod unit_tests {
macro_rules! define_test {
($name:ident) => {
#[test]
fn $name() {
crate::tests::$name::run();
}
};
}
macro_rules! define_payload_test {
($name:ident) => {
#[test]
Expand All @@ -35,7 +27,6 @@ mod unit_tests {
define_payload_test!(parser);
define_payload_test!(cursor);
define_payload_test!(query);
define_test!(init_bindings);
define_payload_test!(definitions);
define_payload_test!(references);
define_payload_test!(bindings_build);
define_payload_test!(bindings_resolve);
}
40 changes: 40 additions & 0 deletions crates/solidity/testing/perf/src/tests/bindings_build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use std::rc::Rc;

use infra_utils::paths::PathExtensions;
use metaslang_bindings::PathResolver;
use slang_solidity::bindings::{create_with_resolver, BindingGraph};
use slang_solidity::cst::{Cursor, KindTypes};

use crate::dataset::SOLC_VERSION;
use crate::tests::parser::ParsedFile;

pub fn setup() -> Vec<ParsedFile> {
super::parser::run(super::parser::setup())
}

pub fn run(files: Vec<ParsedFile>) -> Rc<BindingGraph> {
let mut bindings_graph_builder =
create_with_resolver(SOLC_VERSION, Rc::new(Resolver {})).unwrap();

for file in files {
bindings_graph_builder.add_user_file(
file.path.unwrap_str(),
file.parse_output.create_tree_cursor(),
);
}

bindings_graph_builder.build()
}

struct Resolver;

impl PathResolver<KindTypes> for Resolver {
fn resolve_path(&self, _context_path: &str, path_to_resolve: &Cursor) -> Option<String> {
let path = path_to_resolve.node().unparse();
let path = path
.strip_prefix(|c| matches!(c, '"' | '\''))?
.strip_suffix(|c| matches!(c, '"' | '\''))?;

Some(path.to_owned())
}
}
55 changes: 55 additions & 0 deletions crates/solidity/testing/perf/src/tests/bindings_resolve.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use std::rc::Rc;

use slang_solidity::bindings::BindingGraph;
use slang_solidity::cst::{NonterminalKind, TerminalKind};

use crate::tests::parser::ParsedFile;

pub struct BuiltBindingGraph {
files: Vec<ParsedFile>,
binding_graph: Rc<BindingGraph>,
}

pub fn setup() -> BuiltBindingGraph {
let files = super::bindings_build::setup();
let binding_graph = super::bindings_build::run(files.clone());

BuiltBindingGraph {
files,
binding_graph,
}
}

pub fn run(dependencies: BuiltBindingGraph) {
let BuiltBindingGraph {
files,
binding_graph,
} = dependencies;

for file in files {
let mut cursor = file.parse_output.create_tree_cursor();

while cursor.go_to_next_terminal_with_kinds(&[
TerminalKind::Identifier,
TerminalKind::YulIdentifier,
]) {
if matches!(
cursor.ancestors().next(),
Some(ancestor) if ancestor.kind == NonterminalKind::ExperimentalFeature
) {
// ignore identifiers in `pragma experimental` directives, as they are unbound feature names:
continue;
}

if binding_graph.definition_at(&cursor).is_none()
&& binding_graph.reference_at(&cursor).is_none()
{
panic!(
"Unbound identifier: '{value}' at '{range:?}'.",
value = cursor.node().unparse(),
range = cursor.text_range()
);
}
}
}
}
37 changes: 0 additions & 37 deletions crates/solidity/testing/perf/src/tests/definitions.rs

This file was deleted.

24 changes: 0 additions & 24 deletions crates/solidity/testing/perf/src/tests/init_bindings.rs

This file was deleted.

5 changes: 2 additions & 3 deletions crates/solidity/testing/perf/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub mod bindings_build;
pub mod bindings_resolve;
pub mod cursor;
pub mod definitions;
pub mod init_bindings;
pub mod parser;
pub mod query;
pub mod references;
1 change: 1 addition & 0 deletions crates/solidity/testing/perf/src/tests/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use slang_solidity::parser::{ParseOutput, Parser};

use crate::dataset::{SourceFile, SOLC_VERSION};

#[derive(Clone)]
pub struct ParsedFile {
pub path: PathBuf,

Expand Down
41 changes: 0 additions & 41 deletions crates/solidity/testing/perf/src/tests/references.rs

This file was deleted.

0 comments on commit 3c4fb33

Please sign in to comment.