Skip to content

Commit c35548e

Browse files
authored
Merge pull request #290 from posborne/add-clippy-to-ci
Add clippy to ci (and fixes)
2 parents 8473c4d + 01df9e3 commit c35548e

File tree

24 files changed

+113
-81
lines changed

24 files changed

+113
-81
lines changed

.github/workflows/sightglass.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ env:
1414
REVISION: "v38.0.3"
1515

1616
jobs:
17-
format:
17+
format-and-clippy:
1818
runs-on: ubuntu-latest
1919
steps:
2020
- uses: actions/checkout@v4
2121
with:
2222
submodules: true
2323
- run: rustup update
24-
- run: rustup component add rustfmt
24+
- run: rustup component add rustfmt clippy
2525
- run: cargo fmt --all -- --check
26+
- run: cargo clippy --all-targets --all-features -- -D warnings
2627

2728
test:
2829
runs-on: ${{ matrix.os }}

crates/analysis/src/effect_size.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn calculate<'a>(
1818
measurements: &[Measurement<'a>],
1919
) -> Result<Vec<EffectSize<'a>>> {
2020
anyhow::ensure!(
21-
0.0 <= significance_level && significance_level <= 1.0,
21+
(0.0..=1.0).contains(&significance_level),
2222
"The significance_level must be between 0.0 and 1.0. \
2323
Typical values are 0.05 and 0.01 (i.e. 95% and 99% confidence). \
2424
Found {}.",

crates/analysis/src/keys.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ pub struct Key<'a> {
9494
impl Key<'_> {
9595
/// Does the given measurement match this key?
9696
pub fn matches(&self, m: &Measurement) -> bool {
97-
self.arch.as_ref().map_or(true, |x| *x == m.arch)
98-
&& self.engine.as_ref().map_or(true, |x| *x == m.engine)
99-
&& self.wasm.as_ref().map_or(true, |x| *x == m.wasm)
100-
&& self.phase.as_ref().map_or(true, |x| *x == m.phase)
101-
&& self.event.as_ref().map_or(true, |x| *x == m.event)
97+
self.arch.as_ref().is_none_or(|x| *x == m.arch)
98+
&& self.engine.as_ref().is_none_or(|x| *x == m.engine)
99+
&& self.wasm.as_ref().is_none_or(|x| *x == m.wasm)
100+
&& self.phase.as_ref().is_none_or(|x| *x == m.phase)
101+
&& self.event.as_ref().is_none_or(|x| *x == m.event)
102102
}
103103
}
104104

crates/analysis/src/summarize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::io::Write;
66
/// Summarize measurements grouped by: architecture, engine, benchmark file, phase and event.
77
pub fn calculate<'a>(measurements: &[Measurement<'a>]) -> Vec<Summary<'a>> {
88
let mut summaries = Vec::new();
9-
for k in KeyBuilder::all().keys(&measurements) {
9+
for k in KeyBuilder::all().keys(measurements) {
1010
let mut grouped_counts: Vec<_> = measurements
1111
.iter()
1212
.filter(|m| k.matches(m))

crates/build/src/wasm.rs

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use std::{
1212
};
1313
use thiserror::Error;
1414
use wasmparser::{Import, Payload, TypeRef};
15-
use wasmprinter;
1615

1716
pub struct WasmBenchmark(PathBuf);
1817

@@ -30,31 +29,33 @@ impl WasmBenchmark {
3029
pub fn is_valid(&self) -> Result<(), ValidationError> {
3130
// Check that the file actually exists.
3231
if !self.0.exists() {
33-
return ValidationErrorKind::DoesNotExist.with(&self);
32+
return ValidationErrorKind::DoesNotExist.with(self);
3433
}
3534

3635
// Check that the contents are readable.
3736
let bytes = match fs::read(&self.0) {
3837
Ok(b) => b,
3938
Err(_) => {
40-
return ValidationErrorKind::Unreadable.with(&self);
39+
return ValidationErrorKind::Unreadable.with(self);
4140
}
4241
};
4342

4443
// Check that it contains valid Wasm.
45-
let mut features = wasmparser::WasmFeatures::default();
46-
features.simd = true;
44+
let features = wasmparser::WasmFeatures {
45+
simd: true,
46+
..Default::default()
47+
};
4748
let mut validator = wasmparser::Validator::new_with_features(features);
48-
if let Err(_) = validator.validate_all(&bytes) {
49-
return ValidationErrorKind::InvalidWasm.with(&self);
49+
if validator.validate_all(&bytes).is_err() {
50+
return ValidationErrorKind::InvalidWasm.with(self);
5051
}
5152

5253
// Check that it has the expected imports/exports.
5354
if !has_import_function(&bytes, "bench", "start").unwrap() {
54-
return ValidationErrorKind::MissingImport("bench.end").with(&self);
55+
return ValidationErrorKind::MissingImport("bench.start").with(self);
5556
}
5657
if !has_import_function(&bytes, "bench", "end").unwrap() {
57-
return ValidationErrorKind::MissingImport("bench.end").with(&self);
58+
return ValidationErrorKind::MissingImport("bench.end").with(self);
5859
}
5960

6061
Ok(())
@@ -80,7 +81,7 @@ impl WasmBenchmark {
8081
));
8182
let mut file = File::create(&wat)?;
8283
file.write_all(wasmprinter::print_file(&self.0)?.as_bytes())?;
83-
file.write(&['\n' as u8])?; // Append a newline on the end.
84+
file.write_all(b"\n")?; // Append a newline on the end.
8485
Ok(wat)
8586
}
8687
}
@@ -91,9 +92,9 @@ impl AsRef<Path> for WasmBenchmark {
9192
}
9293
}
9394

94-
impl Into<PathBuf> for WasmBenchmark {
95-
fn into(self) -> PathBuf {
96-
self.0
95+
impl From<WasmBenchmark> for PathBuf {
96+
fn from(val: WasmBenchmark) -> Self {
97+
val.0
9798
}
9899
}
99100

@@ -134,25 +135,20 @@ impl Display for WasmBenchmark {
134135

135136
fn has_import_function(bytes: &[u8], expected_module: &str, expected_field: &str) -> Result<bool> {
136137
let parser = wasmparser::Parser::new(0);
137-
for payload in parser.parse_all(&bytes) {
138-
match payload? {
139-
Payload::ImportSection(imports) => {
140-
for import in imports {
141-
match import? {
142-
Import {
143-
module,
144-
name: field,
145-
ty: TypeRef::Func(_),
146-
} => {
147-
if module == expected_module && field == expected_field {
148-
return Ok(true);
149-
}
150-
}
151-
_ => {}
138+
for payload in parser.parse_all(bytes) {
139+
if let Payload::ImportSection(imports) = payload? {
140+
for import in imports {
141+
if let Import {
142+
module,
143+
name: field,
144+
ty: TypeRef::Func(_),
145+
} = import?
146+
{
147+
if module == expected_module && field == expected_field {
148+
return Ok(true);
152149
}
153150
}
154151
}
155-
_ => {}
156152
}
157153
}
158154
Ok(false)

crates/cli/src/benchmark.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct BenchmarkCommand {
2525
/// The path to the file(s) to benchmark. This accepts one or more:
2626
///
2727
/// - `*.wasm` files: individual benchmarks that meet the requirements
28-
/// outlined in `benchmarks/README.md`
28+
/// outlined in `benchmarks/README.md`
2929
///
3030
/// - `*.suite` files: a file containing a newline-delimited list of
3131
/// benchmarks to execute. A `*.suite` file may contain `#`-prefixed line
@@ -180,7 +180,7 @@ impl BenchmarkCommand {
180180
log::info!("Using working directory: {}", working_dir.display());
181181

182182
// Read the Wasm bytes.
183-
let bytes = fs::read(&wasm_file).context("Attempting to read Wasm bytes")?;
183+
let bytes = fs::read(wasm_file).context("Attempting to read Wasm bytes")?;
184184
log::debug!("Wasm benchmark size: {} bytes", bytes.len());
185185

186186
let wasm_hash = {
@@ -296,11 +296,11 @@ impl BenchmarkCommand {
296296
.with_context(|| "expected the benchmark file to have an extension")?
297297
.to_str()
298298
.with_context(|| "expected the benchmark file to have a printable name")?;
299-
let mut stdout_expected = wasm_file_dir.join(format!("{}.stdout.expected", benchmark_name));
299+
let mut stdout_expected = wasm_file_dir.join(format!("{benchmark_name}.stdout.expected"));
300300
if !stdout_expected.exists() {
301301
stdout_expected = wasm_file_dir.join("default.stdout.expected");
302302
}
303-
let mut stderr_expected = wasm_file_dir.join(format!("{}.stderr.expected", benchmark_name));
303+
let mut stderr_expected = wasm_file_dir.join(format!("{benchmark_name}.stderr.expected"));
304304
if !stderr_expected.exists() {
305305
stderr_expected = wasm_file_dir.join("default.stderr.expected");
306306
}
@@ -365,8 +365,7 @@ impl BenchmarkCommand {
365365
.args(
366366
self.measures
367367
.iter()
368-
.map(|m| ["--measure".to_string(), m.to_string()])
369-
.flatten(),
368+
.flat_map(|m| ["--measure".to_string(), m.to_string()]),
370369
)
371370
.arg("--raw")
372371
.arg("--output-format")
@@ -387,7 +386,7 @@ impl BenchmarkCommand {
387386
}
388387

389388
if let Some(flags) = &self.engine_flags {
390-
command.arg(format!("--engine-flags={}", flags));
389+
command.arg(format!("--engine-flags={flags}"));
391390
}
392391

393392
command.arg("--").arg(&wasm);
@@ -500,7 +499,7 @@ pub fn check_engine_path(engine: &str) -> Result<PathBuf> {
500499
/// `stderr`) is the same as the `expected` output.
501500
fn compare_output_file(wasm: &Path, actual: &Path, expected: &Path) -> Result<()> {
502501
if expected.exists() {
503-
let expected_data = std::fs::read_to_string(&expected)
502+
let expected_data = std::fs::read_to_string(expected)
504503
.with_context(|| format!("failed to read `{}`", expected.display()))?;
505504
let stdout_actual_data = std::fs::read_to_string(actual)
506505
.with_context(|| format!("failed to read `{}`", actual.display()))?;
@@ -540,7 +539,7 @@ mod tests {
540539
display_summaries(&measurements, &mut output)?;
541540

542541
let actual = String::from_utf8(output)?;
543-
eprintln!("=== Actual ===\n{}", actual);
542+
eprintln!("=== Actual ===\n{actual}");
544543

545544
let expected = r#"
546545
compilation
@@ -574,7 +573,7 @@ execution
574573
[3556483 3729210.70 4349778] /tmp/old_backend_2.so
575574
[3639688 4025470.30 5782529] /tmp/old_backend_3.so
576575
"#;
577-
eprintln!("=== Expected ===\n{}", expected);
576+
eprintln!("=== Expected ===\n{expected}");
578577

579578
assert_eq!(actual.trim(), expected.trim());
580579
Ok(())
@@ -589,7 +588,7 @@ execution
589588
display_effect_size(&measurements, 0.05, &mut output)?;
590589

591590
let actual = String::from_utf8(output)?;
592-
eprintln!("=== Actual ===\n{}", actual);
591+
eprintln!("=== Actual ===\n{actual}");
593592

594593
let expected = r#"
595594
compilation :: cycles :: benchmarks/pulldown-cmark/benchmark.wasm
@@ -642,7 +641,7 @@ instantiation :: nanoseconds :: benchmarks/pulldown-cmark/benchmark.wasm
642641
[65929 71540.70 112190] new_backend.so
643642
[61849 69023.59 115015] old_backend.so
644643
"#;
645-
eprintln!("=== Expected ===\n{}", expected);
644+
eprintln!("=== Expected ===\n{expected}");
646645

647646
assert_eq!(actual.trim(), expected.trim());
648647
Ok(())

crates/cli/tests/all/benchmark.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn benchmark_json() {
8181
.assert();
8282

8383
let stdout = std::str::from_utf8(&assert.get_output().stdout).unwrap();
84-
eprintln!("=== stdout ===\n{}\n===========", stdout);
84+
eprintln!("=== stdout ===\n{stdout}\n===========");
8585
assert!(serde_json::from_str::<serde_json::Value>(stdout).is_ok());
8686

8787
assert
@@ -109,7 +109,7 @@ fn benchmark_csv() {
109109
.assert();
110110

111111
let stdout = std::str::from_utf8(&assert.get_output().stdout).unwrap();
112-
eprintln!("=== stdout ===\n{}\n===========", stdout);
112+
eprintln!("=== stdout ===\n{stdout}\n===========");
113113
let mut reader = csv::Reader::from_reader(stdout.as_bytes());
114114
for measurement in reader.deserialize::<Measurement<'_>>() {
115115
drop(measurement.unwrap());
@@ -174,12 +174,12 @@ fn benchmark_effect_size() -> anyhow::Result<()> {
174174
.assert()
175175
.success()
176176
.stdout(
177-
predicate::str::contains(&format!("compilation :: cycles :: {}", benchmark("noop")))
178-
.and(predicate::str::contains(&format!(
177+
predicate::str::contains(format!("compilation :: cycles :: {}", benchmark("noop")))
178+
.and(predicate::str::contains(format!(
179179
"instantiation :: cycles :: {}",
180180
benchmark("noop")
181181
)))
182-
.and(predicate::str::contains(&format!(
182+
.and(predicate::str::contains(format!(
183183
"execution :: cycles :: {}",
184184
benchmark("noop")
185185
)))

crates/cli/tests/all/fingerprint.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn fingerprint_machine() {
1414
.assert();
1515

1616
let stdout = std::str::from_utf8(&assert.get_output().stdout).unwrap();
17-
eprintln!("=== stdout ===\n{}\n===========", stdout);
17+
eprintln!("=== stdout ===\n{stdout}\n===========");
1818
assert!(serde_json::from_str::<Machine>(stdout).is_ok());
1919
}
2020

@@ -30,7 +30,7 @@ fn fingerprint_benchmark() {
3030
.assert();
3131

3232
let stdout = std::str::from_utf8(&assert.get_output().stdout).unwrap();
33-
eprintln!("=== stdout ===\n{}\n===========", stdout);
33+
eprintln!("=== stdout ===\n{stdout}\n===========");
3434
let mut reader = csv::Reader::from_reader(stdout.as_bytes());
3535
for measurement in reader.deserialize::<Benchmark>() {
3636
drop(measurement.unwrap());
@@ -58,7 +58,7 @@ fn fingerprint_engine() {
5858
.assert();
5959

6060
let stdout = std::str::from_utf8(&assert.get_output().stdout).unwrap();
61-
eprintln!("=== stdout ===\n{}\n===========", stdout);
61+
eprintln!("=== stdout ===\n{stdout}\n===========");
6262
let mut reader = csv::Reader::from_reader(stdout.as_bytes());
6363
for measurement in reader.deserialize::<Benchmark>() {
6464
drop(measurement.unwrap());
@@ -73,7 +73,7 @@ fn fingerprint_engine() {
7373
.and(contains(r#""id":"wasmtime-"#))
7474
.and(contains(r#""name":"wasmtime""#))
7575
.and(contains(r#""datetime":"20"#))
76-
.and(contains(format!(r#""path":"{}""#, escaped_engine_path)))
76+
.and(contains(format!(r#""path":"{escaped_engine_path}""#)))
7777
.and(contains(r#""buildinfo":"NAME=wasmtime"#))
7878
.and(ends_with("}")),
7979
)

crates/cli/tests/all/upload.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn upload_dryrun() {
2222

2323
// Gather up the logged output from stderr.
2424
let stderr = std::str::from_utf8(&assert.get_output().stderr).unwrap();
25-
eprintln!("=== stderr ===\n{}\n===========", stderr);
25+
eprintln!("=== stderr ===\n{stderr}\n===========");
2626

2727
// Gather the fingerprints of the system under test.
2828
let engine = sightglass_fingerprint::Engine::fingerprint(test_engine()).unwrap();

crates/cli/tests/all/util.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ pub fn test_engine() -> PathBuf {
2424
BUILD_WASMTIME.call_once(|| {
2525
if engine_path.is_file() {
2626
// Use the already built engine library.
27-
return;
2827
} else {
2928
// Use this instead of `eprintln!` to avoid `cargo test`'s stdio
3029
// capturing.
@@ -67,5 +66,5 @@ pub fn sightglass_cli_benchmark() -> Command {
6766

6867
/// Get the benchmark path for the benchmark with the given name.
6968
pub fn benchmark(benchmark_name: &str) -> String {
70-
format!("../../benchmarks/{}/benchmark.wasm", benchmark_name).into()
69+
format!("../../benchmarks/{benchmark_name}/benchmark.wasm")
7170
}

0 commit comments

Comments
 (0)