Skip to content
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

chore: add a clippy job in CI #267

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b30aa65
upgrade wasmparser & wasm-encoder to v0.211.0
lwshang Jun 25, 2024
2df4d06
fmt
lwshang Jun 25, 2024
96a546b
cleanup workflow yml
lwshang Jun 25, 2024
2a6023c
update testsuite and skip all proposals
lwshang Jun 27, 2024
58b33f6
proc-macro has dash now
lwshang Jun 27, 2024
443462d
fix for bulk.wast by refresh elements
lwshang Jun 28, 2024
8c38eb5
bump to 0.212.0 and follow the features in wasm-tools
lwshang Jun 28, 2024
5eee359
fix elem.wast which failed in gc pass
lwshang Jun 28, 2024
60444cb
handle RefNull
lwshang Jun 29, 2024
fc4c360
always use default features from wasmparser
lwshang Jun 29, 2024
704239d
overhaul spec-tests.rs
lwshang Jun 29, 2024
26afde9
enable multi-memory spec-tests
lwshang Jun 29, 2024
98ea980
fix wabt bin path
lwshang Jun 29, 2024
9fc633f
fix binaryen bin path
lwshang Jun 29, 2024
6c0a24f
no memory64
lwshang Jun 29, 2024
f1bedde
typo
lwshang Jun 29, 2024
a098696
separate RefType
lwshang Jun 29, 2024
0f93d3c
rename InitExpr -> ConstExpr
lwshang Jun 29, 2024
4f029f0
align Memory with wasm-tools
lwshang Jun 29, 2024
2d54251
TODO for operators
lwshang Jun 29, 2024
8272e87
apply clippy fix
lwshang Jun 29, 2024
f455d79
Revert "apply clippy fix"
lwshang Jun 29, 2024
c1302d3
Reapply "apply clippy fix"
lwshang Jun 29, 2024
dac96ca
list all unimplemented operators
lwshang Jul 2, 2024
e40af5f
comment
lwshang Jul 2, 2024
a4f5965
Update src/module/mod.rs
lwshang Jul 2, 2024
bac785f
Merge branch 'upgrade_dependencies' into clippy
lwshang Jul 2, 2024
f4709ac
clippy cont.
lwshang Jul 2, 2024
17ad0da
upgrade criterion and fix deprecated
lwshang Jul 2, 2024
08d335e
upgrade env_logger
lwshang Jul 2, 2024
f51b828
add clippy CI job
lwshang Jul 2, 2024
96c5762
format main.yml
lwshang Jul 2, 2024
3763487
Merge branch 'main' into clippy
lwshang Jul 2, 2024
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
131 changes: 70 additions & 61 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,49 @@ jobs:
matrix:
rust: [stable, beta, nightly]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install Rust
run: rustup update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
- name: Install wabt
run: |
set -e
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.35/wabt-1.0.35-ubuntu-20.04.tar.gz | tar xzf -
echo "`pwd`/wabt-1.0.35/bin" > $GITHUB_PATH
- name: Install binaryen
run: |
set -e
curl -L https://github.com/WebAssembly/binaryen/releases/download/version_117/binaryen-version_117-x86_64-linux.tar.gz | tar xzf -
echo "`pwd`/binaryen-version_117/bin" > $GITHUB_PATH
- run: cargo build --all
- run: cargo test --all
- run: cargo check --benches
- run: cargo test --features parallel
- run: cargo test --features parallel --manifest-path crates/tests/Cargo.toml
- uses: actions/checkout@v4
with:
submodules: true
- name: Install Rust
run: rustup update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
- name: Install wabt
run: |
set -e
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.35/wabt-1.0.35-ubuntu-20.04.tar.gz | tar xzf -
echo "`pwd`/wabt-1.0.35/bin" > $GITHUB_PATH
- name: Install binaryen
run: |
set -e
curl -L https://github.com/WebAssembly/binaryen/releases/download/version_117/binaryen-version_117-x86_64-linux.tar.gz | tar xzf -
echo "`pwd`/binaryen-version_117/bin" > $GITHUB_PATH
- run: cargo build --all
- run: cargo test --all
- run: cargo check --benches
- run: cargo test --features parallel
- run: cargo test --features parallel --manifest-path crates/tests/Cargo.toml

fuzz_crate:
name: Fuzz Crate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable && rustup default stable
- name: Install wabt
run: |
set -e
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.35/wabt-1.0.35-ubuntu-20.04.tar.gz | tar xzf -
echo "`pwd`/wabt-1.0.35/bin" > $GITHUB_PATH
- name: Install binaryen
run: |
set -e
curl -L https://github.com/WebAssembly/binaryen/releases/download/version_117/binaryen-version_117-x86_64-linux.tar.gz | tar xzf -
echo "`pwd`/binaryen-version_117/bin" > $GITHUB_PATH
- name: Run fuzzer
run: cargo test -p walrus-fuzz-utils > fuzz.log || (tail -n 1000 fuzz.log && exit 1)
env:
# 300 seconds = 5 minutes.
WALRUS_FUZZ_TIMEOUT: 300
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable && rustup default stable
- name: Install wabt
run: |
set -e
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.35/wabt-1.0.35-ubuntu-20.04.tar.gz | tar xzf -
echo "`pwd`/wabt-1.0.35/bin" > $GITHUB_PATH
- name: Install binaryen
run: |
set -e
curl -L https://github.com/WebAssembly/binaryen/releases/download/version_117/binaryen-version_117-x86_64-linux.tar.gz | tar xzf -
echo "`pwd`/binaryen-version_117/bin" > $GITHUB_PATH
- name: Run fuzzer
run: cargo test -p walrus-fuzz-utils > fuzz.log || (tail -n 1000 fuzz.log && exit 1)
env:
# 300 seconds = 5 minutes.
WALRUS_FUZZ_TIMEOUT: 300

fuzz:
name: Fuzz
Expand All @@ -60,29 +60,38 @@ jobs:
matrix:
test: [watgen, wasm-opt-ttf, raw]
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update nightly && rustup default nightly
- run: cargo install cargo-fuzz
- name: Install wabt
run: |
set -e
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.35/wabt-1.0.35-ubuntu-20.04.tar.gz | tar xzf -
echo "`pwd`/wabt-1.0.35/bin" > $GITHUB_PATH
- name: Install binaryen
run: |
set -e
curl -L https://github.com/WebAssembly/binaryen/releases/download/version_117/binaryen-version_117-x86_64-linux.tar.gz | tar xzf -
echo "`pwd`/binaryen-version_117/bin" > $GITHUB_PATH
- name: Run fuzzer
run: |
cargo fuzz run ${{ matrix.test }} -- -max_total_time=300 -rss_limit_mb=4096 > fuzz.log 2>&1 || (tail -n 1000 fuzz.log && exit 1)
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update nightly && rustup default nightly
- run: cargo install cargo-fuzz
- name: Install wabt
run: |
set -e
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.35/wabt-1.0.35-ubuntu-20.04.tar.gz | tar xzf -
echo "`pwd`/wabt-1.0.35/bin" > $GITHUB_PATH
- name: Install binaryen
run: |
set -e
curl -L https://github.com/WebAssembly/binaryen/releases/download/version_117/binaryen-version_117-x86_64-linux.tar.gz | tar xzf -
echo "`pwd`/binaryen-version_117/bin" > $GITHUB_PATH
- name: Run fuzzer
run: |
cargo fuzz run ${{ matrix.test }} -- -max_total_time=300 -rss_limit_mb=4096 > fuzz.log 2>&1 || (tail -n 1000 fuzz.log && exit 1)

rustfmt:
name: Rustfmt
fmt:
name: fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable && rustup default stable && rustup component add rustfmt
- run: cargo fmt -- --check
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable && rustup default stable && rustup component add rustfmt
- run: cargo fmt -- --check

clippy:
name: clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable && rustup default stable && rustup component add clippy
- run: cargo clippy --tests --benches -- -D warnings
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ gimli = "0.26.0"
parallel = ['rayon', 'id-arena/rayon']

[dev-dependencies]
env_logger = "0.8.1"
criterion = "0.3.0"
env_logger = "0.11.0"
criterion = "0.5.0"

[workspace]
members = [
Expand Down
26 changes: 12 additions & 14 deletions benches/benches.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
use criterion::{black_box, criterion_group, criterion_main, Benchmark, Criterion};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use walrus::Module;

fn criterion_benchmark(c: &mut Criterion) {
c.bench(
"round-trip-with-gc",
Benchmark::new("dodrio-todomvc.wasm", |b| {
let input_wasm = include_bytes!("./fixtures/dodrio-todomvc.wasm");
b.iter(|| {
let input_wasm = black_box(input_wasm);
let mut module = Module::from_buffer(input_wasm).unwrap();
walrus::passes::gc::run(&mut module);
let output_wasm = module.emit_wasm();
black_box(output_wasm);
});
}),
);
let mut group = c.benchmark_group("round-trip-with-gc");
group.bench_function("dodrio-todomvc.wasm", |b| {
let input_wasm = include_bytes!("./fixtures/dodrio-todomvc.wasm");
b.iter(|| {
let input_wasm = black_box(input_wasm);
let mut module = Module::from_buffer(input_wasm).unwrap();
walrus::passes::gc::run(&mut module);
let output_wasm = module.emit_wasm();
black_box(output_wasm);
});
});
}

criterion_group!(benches, criterion_benchmark);
Expand Down
11 changes: 6 additions & 5 deletions crates/fuzz-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ where
.join("..") // pop `crates`
.join("target")
.join("walrus-fuzz");
fs::create_dir_all(&dir).expect(&format!("should create directory: {:?}", dir));
fs::create_dir_all(&dir).unwrap_or_else(|_| panic!("should create directory: {:?}", dir));

let scratch = tempfile::NamedTempFile::new_in(dir).expect("should create temp file OK");

Expand Down Expand Up @@ -99,20 +99,20 @@ where
}

fn interp(&self, wasm: &[u8]) -> Result<String> {
fs::write(self.scratch.path(), &wasm).context("failed to write to scratch file")?;
fs::write(self.scratch.path(), wasm).context("failed to write to scratch file")?;
wasm_interp(self.scratch.path())
}

fn round_trip_through_walrus(&self, wasm: &[u8]) -> Result<Vec<u8>> {
let mut module =
walrus::Module::from_buffer(&wasm).context("walrus failed to parse the wasm buffer")?;
walrus::Module::from_buffer(wasm).context("walrus failed to parse the wasm buffer")?;
walrus::passes::gc::run(&mut module);
let buf = module.emit_wasm();
Ok(buf)
}

fn test_wat(&self, wat: &str) -> Result<()> {
let wasm = self.wat2wasm(&wat)?;
let wasm = self.wat2wasm(wat)?;
let expected = self.interp(&wasm)?;

let walrus_wasm = self.round_trip_through_walrus(&wasm)?;
Expand Down Expand Up @@ -160,6 +160,7 @@ where
Ok(()) => {
// We reduced fuel as far as we could, so return the last
// failing test case.
#[allow(clippy::question_mark)]
if failing.is_err() {
return failing;
}
Expand Down Expand Up @@ -313,7 +314,7 @@ impl<R: Rng> WatGen<R> {
self.wat.push_str(&operator.to_string());

for op in immediates.into_iter() {
self.wat.push_str(" ");
self.wat.push(' ');
self.wat.push_str(op.as_ref());
}

Expand Down
18 changes: 9 additions & 9 deletions crates/macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Parse for WalrusFieldOpts {
if attr == "skip_visit" {
return Ok(Attr::SkipVisit);
}
return Err(Error::new(attr.span(), "unexpected attribute"));
Err(Error::new(attr.span(), "unexpected attribute"))
}
}
}
Expand Down Expand Up @@ -144,7 +144,7 @@ impl Parse for WalrusVariantOpts {
if attr == "skip_builder" {
return Ok(Attr::SkipBuilder);
}
return Err(Error::new(attr.span(), "unexpected attribute"));
Err(Error::new(attr.span(), "unexpected attribute"))
}
}
}
Expand All @@ -166,7 +166,7 @@ fn walrus_attrs(attrs: &mut Vec<syn::Attribute>) -> TokenStream {
ret.extend(group);
ret.extend(quote! { , });
}
return ret.into();
ret.into()
}

fn create_types(attrs: &[syn::Attribute], variants: &[WalrusVariant]) -> impl quote::ToTokens {
Expand Down Expand Up @@ -328,10 +328,10 @@ fn create_types(attrs: &[syn::Attribute], variants: &[WalrusVariant]) -> impl qu
}
}

fn visit_fields<'a>(
variant: &'a WalrusVariant,
fn visit_fields(
variant: &WalrusVariant,
allow_skip: bool,
) -> impl Iterator<Item = (syn::Ident, proc_macro2::TokenStream, bool)> + 'a {
) -> impl Iterator<Item = (syn::Ident, proc_macro2::TokenStream, bool)> + '_ {
return variant
.syn
.fields
Expand Down Expand Up @@ -439,7 +439,7 @@ fn create_visit(variants: &[WalrusVariant]) -> impl quote::ToTokens {
}
});

let doc = format!("Visit `{}`.", name.to_string());
let doc = format!("Visit `{}`.", name);
visitor_trait_methods.push(quote! {
#[doc=#doc]
#[inline]
Expand Down Expand Up @@ -723,13 +723,13 @@ fn create_builder(variants: &[WalrusVariant]) -> impl quote::ToTokens {

let doc = format!(
"Push a new `{}` instruction onto this builder's block.",
name.to_string()
name
);
let at_doc = format!(
"Splice a new `{}` instruction into this builder's block at the given index.\n\n\
# Panics\n\n\
Panics if `position > self.instrs.len()`.",
name.to_string()
name
);

let arg_names = &arg_names;
Expand Down
2 changes: 1 addition & 1 deletion crates/tests-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ where
cmd.arg(input);
cmd.arg("-o");
cmd.arg(tmp.path());
cmd.args(&[
cmd.args([
"--enable-threads",
"--enable-bulk-memory",
// "--enable-reference-types",
Expand Down
26 changes: 12 additions & 14 deletions crates/tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ impl FileCheck {
let mut iter = contents.lines().map(str::trim);
while let Some(line) = iter.next() {
if line.starts_with("(; CHECK-ALL:") {
if patterns.len() != 0 {
if !patterns.is_empty() {
panic!("CHECK cannot be used with CHECK-ALL");
}
let mut pattern = Vec::new();
while let Some(line) = iter.next() {
for line in iter.by_ref() {
if line == ";)" {
break;
}
Expand All @@ -94,19 +94,17 @@ impl FileCheck {
}
return FileCheck::Exhaustive(pattern, path.to_path_buf());
}

if line.starts_with(";; CHECK:") {
let p = line[";; CHECK:".len()..].to_string();
patterns.push(vec![p]);
if let Some(p) = line.strip_prefix(";; CHECK:") {
patterns.push(vec![p.to_string()]);
}
if line.starts_with(";; NEXT:") {
let p = patterns
if let Some(p) = line.strip_prefix(";; NEXT:") {
let v = patterns
.last_mut()
.expect("NEXT should never come before CHECK");
p.push(line[";; NEXT:".len()..].to_string());
v.push(p.to_string());
}
}
if patterns.len() == 0 {
if patterns.is_empty() {
FileCheck::None(path.to_path_buf())
} else {
FileCheck::Patterns(patterns)
Expand All @@ -125,7 +123,7 @@ impl FileCheck {

'inner: while let Some(pos) = output_lines[start..]
.iter()
.position(|l| matches(*l, first_line))
.position(|l| matches(l, first_line))
{
start = pos + 1;
if output_lines[pos..].len() + 1 < pattern.len() {
Expand Down Expand Up @@ -155,11 +153,11 @@ impl FileCheck {
}
}
FileCheck::None(_) => {
println!("");
println!();
println!("no test assertions were found in this file, but");
println!("you can rerun tests with `WALRUS_BLESS=1` to");
println!("automatically add assertions to this file");
println!("");
println!();
panic!("no tests to run")
}
}
Expand Down Expand Up @@ -210,7 +208,7 @@ fn update_output(path: &Path, output: &str) {
new_output.push_str(" ");
new_output.push_str(line.trim_end());
}
new_output.push_str("\n");
new_output.push('\n');
}
let new = format!(
"{}\n\n(; CHECK-ALL:\n{}\n;)\n",
Expand Down
Loading