Skip to content

Commit

Permalink
CI: more clippy checks and build tool revamps (#250)
Browse files Browse the repository at this point in the history
Add clippy checks of the following crates in CI.
- [x] mpcs
- [x] ceno_emul

---------

Co-authored-by: Yuncong Zhang <[email protected]>
Co-authored-by: sm.wu <[email protected]>
  • Loading branch information
3 people authored Sep 26, 2024
1 parent 9651e16 commit 21606d9
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: make
args: fmt-check-selected-packages
args: fmt

- name: Run clippy
uses: actions-rs/cargo@v1
env:
TARGET: ${{ matrix.target }}
with:
command: make
args: clippy-check-selected-packages
args: clippy

37 changes: 30 additions & 7 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,50 @@
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
CORE = { script = ["grep ^cpu\\scores /proc/cpuinfo | uniq | awk '{print $4}'"] }
RAYON_NUM_THREADS = "${CORE}"
CUR_TARGET = { script = [
'''
if [ -z "${TARGET}" ]; then
TARGET=$(rustc -vV | grep "host" | awk '{print $2}')
echo "${TARGET}"
else
echo "${TARGET}"
fi
'''
]}
TASK_RUN = { script = [
'''
#!/bin/bash
exclude_projects=" singer-pro ceno_rt " # NOTE:keep leading and end with one space
if echo "$exclude_projects" | grep -q -E "( )${CARGO_MAKE_CRATE_NAME}( )"; then
echo "false"
else
echo "true"
fi
'''
]}

[tasks.tests]
condition = { env_true = ["TASK_RUN"] }
command = "cargo"
args = ["test", "--lib", "--release", "--target", "${TARGET}", "--workspace", "--exclude", "singer-pro", "--exclude", "ceno_rt"]
args = ["test", "--lib", "--release", "--target", "${CUR_TARGET}", "-p", "${CARGO_MAKE_CRATE_NAME}"]

[tasks.fmt-check]
[tasks.fmt-all-check]
command = "cargo"
args = ["fmt", "--all", "--", "--check"]

[tasks.fmt]
[tasks.fmt-all]
command = "cargo"
args = ["fmt", "--all"]

[tasks.clippy]
[tasks.clippy-all]
command = "cargo"
args = ["clippy", "--all-features", "--all-targets", "--", "-D", "warnings"]

[tasks.fmt-check-selected-packages]
[tasks.fmt]
command = "cargo"
args = ["fmt", "-p", "ceno_zkvm", "--", "--check"]

[tasks.clippy-check-selected-packages]
[tasks.clippy]
command = "cargo"
args = ["clippy", "-p", "ceno_zkvm", "--target", "${TARGET}", "--", "-D", "warnings"]
args = ["clippy", "-p", "ceno_zkvm", "-p", "mpcs", "-p", "ceno_emul", "-p", "ceno_rt", "--target", "${CUR_TARGET}", "--", "-D", "warnings"]
1 change: 1 addition & 0 deletions ceno_emul/src/rv32im.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ impl DecodedInstruction {

#[cfg(test)]
#[test]
#[allow(clippy::identity_op)]
fn test_decode_imm() {
for (i, expected) in [
// Example of I-type: ADDI.
Expand Down
1 change: 1 addition & 0 deletions ceno_emul/tests/test_vm_trace.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::unusual_byte_groupings)]
use anyhow::Result;
use std::collections::HashMap;

Expand Down
3 changes: 3 additions & 0 deletions ceno_rt/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ impl IOWriter {
}
}

// TODO docs on why design mut_from_ref
// or justify this convention by citing from other place
#[allow(clippy::mut_from_ref)]
pub fn alloc<T>(&self, count: usize) -> &mut [T] {
let byte_len = count * size_of::<T>();
let word_len = byte_len.div_ceil(WORD_SIZE);
Expand Down
1 change: 1 addition & 0 deletions ceno_rt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mod panic_handler {
}
}

#[allow(asm_sub_register)]
pub fn halt(exit_code: u32) -> ! {
unsafe {
asm!(
Expand Down
8 changes: 7 additions & 1 deletion mpcs/src/sum_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ impl<'a, E: ExtensionField> VirtualPolynomial<'a, E> {
}
}

pub type SumCheckProverOutput<E, SC> = (
Vec<E>,
Vec<E>,
SumcheckProof<E, <SC as SumCheck<E>>::RoundMessage>,
);

pub trait SumCheck<E: ExtensionField>: Clone + Debug
where
E::BaseField: Serialize + DeserializeOwned,
Expand All @@ -57,7 +63,7 @@ where
virtual_poly: VirtualPolynomial<E>,
sum: E,
transcript: &mut Transcript<E>,
) -> Result<(Vec<E>, Vec<E>, SumcheckProof<E, Self::RoundMessage>), Error>;
) -> Result<SumCheckProverOutput<E, Self>, Error>;

fn verify(
vp: &Self::VerifierParam,
Expand Down

0 comments on commit 21606d9

Please sign in to comment.