Skip to content

Commit

Permalink
fix benchmarking in CI (#1147)
Browse files Browse the repository at this point in the history
It has been [failing in
CI](https://github.com/NomicFoundation/slang/actions/runs/11597323701/job/32290519984)
for a few days.
This fixes it by upgrading `RUST_STABLE_VERSION` and
`RUST_NIGHTLY_VERSION` to latest.
  • Loading branch information
OmarTawfik authored Nov 5, 2024
1 parent cfc62f2 commit a585708
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"rust-analyzer.imports.granularity.group": "module",
"rust-analyzer.imports.prefix": "crate",
"rust-analyzer.rustfmt.extraArgs": [
"+nightly-2024-06-17" // __RUST_NIGHTLY_VERSION_MARKER__ (keep in sync)
"+nightly-2024-09-01" // __RUST_NIGHTLY_VERSION_MARKER__ (keep in sync)
],
"rust-analyzer.server.path": "${workspaceFolder}/scripts/bin/rust-analyzer",
"search.exclude": {
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace.package]
version = "0.18.3"
rust-version = "1.79.0" # __RUST_STABLE_VERSION_MARKER__ (keep in sync)
rust-version = "1.82.0" # __RUST_STABLE_VERSION_MARKER__ (keep in sync)
edition = "2021"
publish = false

Expand Down
4 changes: 2 additions & 2 deletions bin/hermit.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ env = {

// Rust:
"RUST_BACKTRACE": "full",
"RUST_STABLE_VERSION": "1.79.0", // __RUST_STABLE_VERSION_MARKER__ (keep in sync)
"RUST_NIGHTLY_VERSION": "nightly-2024-06-17", // __RUST_NIGHTLY_VERSION_MARKER__ (keep in sync)
"RUST_STABLE_VERSION": "1.82.0", // __RUST_STABLE_VERSION_MARKER__ (keep in sync)
"RUST_NIGHTLY_VERSION": "nightly-2024-09-01", // __RUST_NIGHTLY_VERSION_MARKER__ (keep in sync)

// TypeScript:
"TS_NODE_PROJECT": "${HERMIT_ENV}/tsconfig.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,11 @@ impl SequenceHelper {
match &**node {
Node::Terminal(terminal) if terminal.kind.is_trivia() => Ok(acc),
Node::Terminal(terminal) => {
match acc {
None => Ok(Some(terminal.kind)),
Some(..) => {
debug_assert!(false, "Recovery skipped to multiple terminals: {acc:?}, {terminal:?}");
Err(())
}
if acc.is_none() {
Ok(Some(terminal.kind))
} else {
debug_assert!(false, "Recovery skipped to multiple terminals: {acc:?}, {terminal:?}");
Err(())
}
}
Node::Nonterminal(node) => {
Expand Down
17 changes: 5 additions & 12 deletions crates/infra/cli/src/commands/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ fn run_markdown_link_check() -> Result<()> {
}

fn run_markdown_lint() -> Result<()> {
let markdown_files = FileWalker::from_repo_root().find(["**/*.md"])?.map(|path| {
println!("{}", path.display());
path
});
let markdown_files = FileWalker::from_repo_root()
.find(["**/*.md"])?
.inspect(|path| println!("{}", path.display()));

let mut command = Command::new("markdownlint").flag("--dot");

Expand Down Expand Up @@ -124,10 +123,7 @@ fn run_rustfmt() {
fn run_shellcheck() -> Result<()> {
let bash_files = FileWalker::from_repo_root()
.find(["scripts/**"])?
.map(|path| {
println!("{}", path.display());
path
});
.inspect(|path| println!("{}", path.display()));

Command::new("shellcheck").run_xargs(bash_files);

Expand All @@ -147,10 +143,7 @@ fn run_yamllint() -> Result<()> {

let yaml_files = FileWalker::from_repo_root()
.find(["**/*.yml"])?
.map(|path| {
println!("{}", path.display());
path
});
.inspect(|path| println!("{}", path.display()));

PipEnv::run("yamllint")
.flag("--strict")
Expand Down
9 changes: 6 additions & 3 deletions crates/infra/utils/src/cargo/public_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub enum UserFacingCrate {

#[cfg(test)]
mod public_api_snapshots {
use anyhow::Result;
use anyhow::{Context, Result};
use rayon::iter::{ParallelBridge, ParallelIterator};
use strum::IntoEnumIterator;

Expand All @@ -22,6 +22,8 @@ mod public_api_snapshots {

#[test]
fn public_api_snapshots() {
assert!(env!("RUST_NIGHTLY_VERSION").ge(public_api::MINIMUM_NIGHTLY_RUST_VERSION));

UserFacingCrate::iter()
.filter(|&crate_name| has_library_target(crate_name))
.par_bridge()
Expand All @@ -37,11 +39,12 @@ mod public_api_snapshots {
.toolchain(env!("RUST_NIGHTLY_VERSION"))
.build()?;

let public_api = public_api::Builder::from_rustdoc_json(rustdoc_json)
let public_api = public_api::Builder::from_rustdoc_json(&rustdoc_json)
.omit_auto_derived_impls(false)
.omit_auto_trait_impls(true)
.omit_blanket_impls(true)
.build()?;
.build()
.with_context(|| format!("Failed to generate public API from {rustdoc_json:?}"))?;

let output_path = crate_dir.join("generated/public_api.txt");

Expand Down
3 changes: 3 additions & 0 deletions crates/metaslang/bindings/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ impl<'a, KT: KindTypes + 'static> Resolver<'a, KT> {
None => caller_context.clone(),
};

#[allow(clippy::mutable_key_type)]
let parents = Self::resolve_parents_all(resolution_context.clone());

let Some(mro) = c3::linearise(&resolution_context, &parents) else {
// linearisation failed
eprintln!("Linearisation of {resolution_context} failed");
Expand Down Expand Up @@ -208,6 +210,7 @@ impl<'a, KT: KindTypes + 'static> Resolver<'a, KT> {
}
}

#[allow(clippy::mutable_key_type)]
fn resolve_parents_all(
context: Definition<'a, KT>,
) -> HashMap<Definition<'a, KT>, Vec<Definition<'a, KT>>> {
Expand Down
18 changes: 0 additions & 18 deletions crates/metaslang/graph_builder/src/excerpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
use std::ops::Range;
use std::path::Path;

#[cfg(feature = "term-colors")]
use colored::Colorize;

//-----------------------------------------------------------------------------

/// Excerpts of source from either the target language file or the tsg rules file.
Expand Down Expand Up @@ -88,29 +85,14 @@ impl<'a> std::fmt::Display for Excerpt<'a> {

// coloring functions

#[cfg(feature = "term-colors")]
fn blue(str: &str) -> impl std::fmt::Display {
str.blue()
}
#[cfg(not(feature = "term-colors"))]
fn blue<'a>(str: &'a str) -> impl std::fmt::Display + 'a {
str
}

#[cfg(feature = "term-colors")]
fn green_bold(str: &str) -> impl std::fmt::Display {
str.green().bold()
}
#[cfg(not(feature = "term-colors"))]
fn green_bold<'a>(str: &'a str) -> impl std::fmt::Display + 'a {
str
}

#[cfg(feature = "term-colors")]
fn white_bold(str: &str) -> impl std::fmt::Display {
str.white().bold()
}
#[cfg(not(feature = "term-colors"))]
fn white_bold<'a>(str: &'a str) -> impl std::fmt::Display + 'a {
str
}

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

43 changes: 15 additions & 28 deletions crates/solidity/testing/perf/benches/iai/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#![allow(clippy::exit)]
#![allow(clippy::needless_pass_by_value)]
#![allow(clippy::unit_arg)]

mod dataset;
mod tests;
Expand All @@ -17,39 +16,27 @@ use iai_callgrind::{
LibraryBenchmarkConfig, Tool, ValgrindTool,
};
use slang_solidity::bindings::Bindings;
use slang_solidity::parser::ParseOutput;

use crate::dataset::SourceFile;
use crate::tests::definitions::Dependencies;
use crate::tests::parser::ParsedFile;

#[library_benchmark(setup = tests::parser::setup)]
fn parser(files: Vec<SourceFile>) {
black_box(tests::parser::run(files));
macro_rules! define_benchmark {
($name:ident, $payload:ty) => {
#[library_benchmark(setup = tests::$name::setup)]
fn $name(payload: $payload) {
black_box(tests::$name::run(payload));
}
};
}

#[library_benchmark(setup = tests::cursor::setup)]
fn cursor(files: Vec<ParsedFile>) {
black_box(tests::cursor::run(&files));
}

#[library_benchmark(setup = tests::query::setup)]
fn query(files: Vec<ParsedFile>) {
black_box(tests::query::run(&files));
}

#[library_benchmark]
fn init_bindings() {
black_box(tests::init_bindings::run());
}

#[library_benchmark(setup = tests::definitions::setup)]
fn definitions(dependencies: tests::definitions::Dependencies) {
black_box(tests::definitions::run(dependencies));
}

#[library_benchmark(setup = tests::references::setup)]
fn references(bindings: Bindings) {
black_box(tests::references::run(&bindings));
}
define_benchmark!(parser, Vec<SourceFile>);
define_benchmark!(cursor, Vec<ParsedFile>);
define_benchmark!(query, Vec<ParsedFile>);
define_benchmark!(init_bindings, ParseOutput);
define_benchmark!(definitions, Dependencies);
define_benchmark!(references, Bindings);

library_benchmark_group!(
name = benchmarks;
Expand Down
4 changes: 2 additions & 2 deletions crates/solidity/testing/perf/benches/iai/tests/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ pub fn setup() -> Vec<ParsedFile> {
super::parser::run(files)
}

pub fn run(files: &[ParsedFile]) {
pub fn run(files: Vec<ParsedFile>) {
let mut functions_count = 0;

for file in files {
for file in &files {
let mut cursor = file.tree.cursor_with_offset(TextIndex::ZERO);

while cursor.go_to_next_nonterminal_with_kind(NonterminalKind::FunctionDefinition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct Dependencies {
}

pub fn setup() -> Dependencies {
let bindings = super::init_bindings::run();
let bindings = super::init_bindings::run(super::init_bindings::setup());
let files = super::parser::run(super::parser::setup());

Dependencies { bindings, files }
Expand Down
21 changes: 13 additions & 8 deletions crates/solidity/testing/perf/benches/iai/tests/init_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@ use std::sync::Arc;

use metaslang_bindings::PathResolver;
use slang_solidity::bindings::{create_with_resolver, get_built_ins, Bindings};
use slang_solidity::parser::Parser;
use slang_solidity::parser::{ParseOutput, Parser};

use crate::dataset::SOLC_VERSION;

pub fn run() -> Bindings {
pub fn setup() -> ParseOutput {
let parser = Parser::create(SOLC_VERSION).unwrap();

let built_ins = parser.parse(Parser::ROOT_KIND, get_built_ins(&SOLC_VERSION));

assert!(built_ins.is_valid(), "built-ins parse without errors");

built_ins
}

pub fn run(built_ins: ParseOutput) -> Bindings {
let mut bindings = create_with_resolver(SOLC_VERSION, Arc::new(NoOpResolver {}));

let built_ins_parse_output = parser.parse(Parser::ROOT_KIND, get_built_ins(&SOLC_VERSION));
assert!(
built_ins_parse_output.is_valid(),
"built-ins parse without errors"
);
bindings.add_system_file("built_ins.sol", built_ins_parse_output.create_tree_cursor());
bindings.add_system_file("built_ins.sol", built_ins.create_tree_cursor());

bindings
}

Expand Down
4 changes: 2 additions & 2 deletions crates/solidity/testing/perf/benches/iai/tests/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn setup() -> Vec<ParsedFile> {
super::parser::run(files)
}

pub fn run(files: &[ParsedFile]) {
pub fn run(files: Vec<ParsedFile>) {
let mut functions_count = 0;

let queries = vec![Query::parse(
Expand All @@ -18,7 +18,7 @@ pub fn run(files: &[ParsedFile]) {
)
.unwrap()];

for file in files {
for file in &files {
let cursor = file.tree.cursor_with_offset(TextIndex::ZERO);

for query_match in cursor.query(queries.clone()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub fn setup() -> Bindings {
super::definitions::run(dependencies)
}

pub fn run(bindings: &Bindings) {
pub fn run(bindings: Bindings) {
let mut reference_count = 0_usize;
let mut resolved_references = 0_usize;

Expand Down

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

0 comments on commit a585708

Please sign in to comment.