Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
moodlezoup committed Nov 22, 2024
1 parent 8dacbdd commit 137bcf1
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 35 deletions.
7 changes: 3 additions & 4 deletions common/src/rv_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ impl RV32IM {
}
}

#[allow(clippy::too_long_first_doc_paragraph)]
/// Represented as a "peripheral device" in the RISC-V emulator, this captures
/// all reads from the reserved memory address space for program inputs and all writes
/// to the reserved memory address space for program outputs.
Expand Down Expand Up @@ -706,7 +707,7 @@ impl MemoryLayout {
let panic = output_end;
let termination = panic + 4;

let layout = Self {
Self {
max_input_size,
max_output_size,
input_start,
Expand All @@ -715,8 +716,6 @@ impl MemoryLayout {
output_end,
panic,
termination,
};

layout
}
}
}
5 changes: 3 additions & 2 deletions examples/memory-ops/guest/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg_attr(feature = "guest", no_std)]
#![allow(unused_assignments, asm_sub_register)]

#[jolt::provable]
fn memory_ops() -> (i32, u32, i32, u32) {
Expand All @@ -12,7 +13,7 @@ fn memory_ops() -> (i32, u32, i32, u32) {
asm!(
"sb {value}, 0({ptr})",
ptr = in(reg) ptr,
value = in(reg) 0x12u8,
value = in(reg) 0x12,
);

// Load Byte Signed (LB instruction)
Expand All @@ -35,7 +36,7 @@ fn memory_ops() -> (i32, u32, i32, u32) {
asm!(
"sh {value}, 2({ptr})",
ptr = in(reg) ptr,
value = in(reg) 0x3456u16,
value = in(reg) 0x3456,
);

// Load Halfword Signed (LH instruction)
Expand Down
2 changes: 2 additions & 0 deletions jolt-core/src/jolt/vm/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ pub struct BytecodeStuff<T: CanonicalSerialize + CanonicalDeserialize> {
}

/// Note –– F: JoltField bound is not enforced.
///
/// See issue #112792 <https://github.com/rust-lang/rust/issues/112792>.
/// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break
/// `alloy_sol_types`.
pub type BytecodePolynomials<F: JoltField> = BytecodeStuff<DensePolynomial<F>>;
/// Note –– F: JoltField bound is not enforced.
///
/// See issue #112792 <https://github.com/rust-lang/rust/issues/112792>.
/// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break
/// `alloy_sol_types`.
Expand Down
3 changes: 3 additions & 0 deletions jolt-core/src/jolt/vm/instruction_lookups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,19 @@ pub struct InstructionLookupStuff<T: CanonicalSerialize + CanonicalDeserialize>
}

/// Note –– F: JoltField bound is not enforced.
///
/// See issue #112792 <https://github.com/rust-lang/rust/issues/112792>.
/// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break
/// `alloy_sol_types`.
pub type InstructionLookupPolynomials<F: JoltField> = InstructionLookupStuff<DensePolynomial<F>>;
/// Note –– F: JoltField bound is not enforced.
///
/// See issue #112792 <https://github.com/rust-lang/rust/issues/112792>.
/// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break
/// `alloy_sol_types`.
pub type InstructionLookupOpenings<F: JoltField> = InstructionLookupStuff<F>;
/// Note –– PCS: CommitmentScheme bound is not enforced.
///
/// See issue #112792 <https://github.com/rust-lang/rust/issues/112792>.
/// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break
/// `alloy_sol_types`.
Expand Down
2 changes: 2 additions & 0 deletions jolt-core/src/jolt/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,13 @@ impl<T: CanonicalSerialize + CanonicalDeserialize + Sync> StructuredPolynomialDa
}

/// Note –– F: JoltField bound is not enforced.
///
/// See issue #112792 <https://github.com/rust-lang/rust/issues/112792>.
/// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break
/// `alloy_sol_types`.
pub type JoltPolynomials<F: JoltField> = JoltStuff<DensePolynomial<F>>;
/// Note –– PCS: CommitmentScheme bound is not enforced.
///
/// See issue #112792 <https://github.com/rust-lang/rust/issues/112792>.
/// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break
/// `alloy_sol_types`.
Expand Down
21 changes: 12 additions & 9 deletions jolt-core/src/jolt/vm/read_write_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,19 @@ impl<T: CanonicalSerialize + CanonicalDeserialize> StructuredPolynomialData<T>
}

/// Note –– F: JoltField bound is not enforced.
///
/// See issue #112792 <https://github.com/rust-lang/rust/issues/112792>.
/// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break
/// `alloy_sol_types`.
pub type ReadWriteMemoryPolynomials<F: JoltField> = ReadWriteMemoryStuff<DensePolynomial<F>>;
/// Note –– F: JoltField bound is not enforced.
///
/// See issue #112792 <https://github.com/rust-lang/rust/issues/112792>.
/// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break
/// `alloy_sol_types`.
pub type ReadWriteMemoryOpenings<F: JoltField> = ReadWriteMemoryStuff<F>;
/// Note –– PCS: CommitmentScheme bound is not enforced.
///
/// See issue #112792 <https://github.com/rust-lang/rust/issues/112792>.
/// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break
/// `alloy_sol_types`.
Expand Down Expand Up @@ -246,7 +249,7 @@ impl<F: JoltField> ReadWriteMemoryPolynomials<F> {
pub fn generate_witness<InstructionSet: JoltInstructionSet>(
program_io: &JoltDevice,
preprocessing: &ReadWriteMemoryPreprocessing,
trace: &Vec<JoltTraceStep<InstructionSet>>,
trace: &[JoltTraceStep<InstructionSet>],
) -> (Self, [Vec<u64>; MEMORY_OPS_PER_INSTRUCTION]) {
assert!(program_io.inputs.len() <= program_io.memory_layout.max_input_size as usize);
assert!(program_io.outputs.len() <= program_io.memory_layout.max_output_size as usize);
Expand Down Expand Up @@ -284,7 +287,7 @@ impl<F: JoltField> ReadWriteMemoryPolynomials<F> {
for (i, byte) in chunk.iter().enumerate() {
word[i] = *byte;
}
let word = u32::from_le_bytes(word.try_into().unwrap());
let word = u32::from_le_bytes(word);
v_init[v_init_index] = word as u64;
v_init_index += 1;
}
Expand Down Expand Up @@ -710,19 +713,19 @@ where
let mut v_init: Vec<u64> = vec![0; memory_size];
// Copy bytecode
let mut v_init_index =
memory_address_to_witness_index(preprocessing.min_bytecode_address, &memory_layout);
memory_address_to_witness_index(preprocessing.min_bytecode_address, memory_layout);
for word in preprocessing.bytecode_words.iter() {
v_init[v_init_index] = *word as u64;
v_init_index += 1;
}
// Copy input bytes
v_init_index = memory_address_to_witness_index(memory_layout.input_start, &memory_layout);
v_init_index = memory_address_to_witness_index(memory_layout.input_start, memory_layout);
for chunk in preprocessing.program_io.as_ref().unwrap().inputs.chunks(4) {
let mut word = [0u8; 4];
for (i, byte) in chunk.iter().enumerate() {
word[i] = *byte;
}
let word = u32::from_le_bytes(word.try_into().unwrap());
let word = u32::from_le_bytes(word);
v_init[v_init_index] = word as u64;
v_init_index += 1;
}
Expand Down Expand Up @@ -867,7 +870,7 @@ where
for (i, byte) in chunk.iter().enumerate() {
word[i] = *byte;
}
let word = u32::from_le_bytes(word.try_into().unwrap());
let word = u32::from_le_bytes(word);
v_io[input_index] = word as u64;
input_index += 1;
}
Expand All @@ -881,7 +884,7 @@ where
for (i, byte) in chunk.iter().enumerate() {
word[i] = *byte;
}
let word = u32::from_le_bytes(word.try_into().unwrap());
let word = u32::from_le_bytes(word);
v_io[output_index] = word as u64;
output_index += 1;
}
Expand Down Expand Up @@ -993,7 +996,7 @@ where
for (i, byte) in chunk.iter().enumerate() {
word[i] = *byte;
}
let word = u32::from_le_bytes(word.try_into().unwrap());
let word = u32::from_le_bytes(word);
v_io[input_index] = word as u64;
input_index += 1;
}
Expand All @@ -1005,7 +1008,7 @@ where
for (i, byte) in chunk.iter().enumerate() {
word[i] = *byte;
}
let word = u32::from_le_bytes(word.try_into().unwrap());
let word = u32::from_le_bytes(word);
v_io[output_index] = word as u64;
output_index += 1;
}
Expand Down
3 changes: 3 additions & 0 deletions jolt-core/src/jolt/vm/timestamp_range_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,20 @@ impl<T: CanonicalSerialize + CanonicalDeserialize + Sync> StructuredPolynomialDa
}

/// Note –– F: JoltField bound is not enforced.
///
/// See issue #112792 <https://github.com/rust-lang/rust/issues/112792>.
/// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break
/// `alloy_sol_types`.
pub type TimestampRangeCheckPolynomials<F: JoltField> =
TimestampRangeCheckStuff<DensePolynomial<F>>;
/// Note –– F: JoltField bound is not enforced.
///
/// See issue #112792 <https://github.com/rust-lang/rust/issues/112792>.
/// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break
/// `alloy_sol_types`.
pub type TimestampRangeCheckOpenings<F: JoltField> = TimestampRangeCheckStuff<F>;
/// Note –– PCS: CommitmentScheme bound is not enforced.
///
/// See issue #112792 <https://github.com/rust-lang/rust/issues/112792>.
/// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break
/// `alloy_sol_types`.
Expand Down
1 change: 1 addition & 0 deletions jolt-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#![allow(long_running_const_eval)]
#![allow(clippy::len_without_is_empty)]
#![allow(type_alias_bounds)]
#![allow(clippy::too_long_first_doc_paragraph)]

#[cfg(feature = "host")]
pub mod benches;
Expand Down
8 changes: 4 additions & 4 deletions jolt-core/src/msm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn msm_bigint_wnaf<V: VariableBaseMSM>(
};

let num_bits = max_num_bits;
let digits_count = (num_bits + c - 1) / c;
let digits_count = num_bits.div_ceil(c);
let scalar_digits = scalars
.into_par_iter()
.flat_map_iter(|s| make_digits_bigint(s, c, num_bits))
Expand Down Expand Up @@ -235,7 +235,7 @@ fn make_digits_bigint(
} else {
num_bits
};
let digits_count = (num_bits + w - 1) / w;
let digits_count = num_bits.div_ceil(w);
(0..digits_count).map(move |i| {
// Construct a buffer of bits of the scalar, starting at `bit_offset`.
let bit_offset = i * w;
Expand Down Expand Up @@ -277,7 +277,7 @@ fn msm_u64_wnaf<V: VariableBaseMSM>(
ln_without_floats(bases.len()) + 2
};

let digits_count = (max_num_bits + c - 1) / c;
let digits_count = max_num_bits.div_ceil(c);
let scalar_digits = scalars
.into_par_iter()
.flat_map_iter(|s| make_digits_u64(*s, c, max_num_bits))
Expand Down Expand Up @@ -451,7 +451,7 @@ fn make_digits_u64(scalar: u64, w: usize, num_bits: usize) -> impl Iterator<Item
let window_mask: u64 = radix - 1;
let mut carry = 0u64;

let digits_count = (num_bits + w - 1) / w;
let digits_count = num_bits.div_ceil(w);
(0..digits_count).map(move |i| {
// Construct a buffer of bits of the scalar, starting at `bit_offset`.
let bit_offset = i * w;
Expand Down
1 change: 1 addition & 0 deletions jolt-core/src/poly/dense_interleaved_poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use super::dense_mlpoly::DensePolynomial;
use super::{split_eq_poly::SplitEqPolynomial, unipoly::UniPoly};

/// Represents a single layer of a grand product circuit.
///
/// A layer is assumed to be arranged in "interleaved" order, i.e. the natural
/// order in the visual representation of the circuit:
/// Λ Λ Λ Λ
Expand Down
2 changes: 2 additions & 0 deletions jolt-core/src/poly/opening_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::{
};

/// An opening computed by the prover.
///
/// May be a batched opening, where multiple polynomials opened
/// at the *same* point are reduced to a single polynomial opened
/// at the (same) point.
Expand All @@ -49,6 +50,7 @@ pub struct ProverOpening<F: JoltField> {
}

/// An opening that the verifier must verify.
///
/// May be a batched opening, where multiple polynomials opened
/// at the *same* point are reduced to a single polynomial opened
/// at the (same) point.
Expand Down
1 change: 1 addition & 0 deletions jolt-core/src/poly/sparse_interleaved_poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl<F: JoltField> From<(usize, F)> for SparseCoefficient<F> {
}

/// Represents a single layer of a sparse grand product circuit.
///
/// A layer is assumed to be arranged in "interleaved" order, i.e. the natural
/// order in the visual representation of the circuit:
/// Λ Λ Λ Λ
Expand Down
4 changes: 2 additions & 2 deletions jolt-core/src/r1cs/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl<F: JoltField> AuxComputation<F> {

let mut aux_poly: Vec<F> = unsafe_allocate_zero_vec(batch_size);
let num_threads = rayon::current_num_threads();
let chunk_size = (batch_size + num_threads - 1) / num_threads;
let chunk_size = batch_size.div_ceil(num_threads);

aux_poly
.par_chunks_mut(chunk_size)
Expand Down Expand Up @@ -180,7 +180,7 @@ impl<F: JoltField> AuxComputation<F> {
// in the batch to a buffer owend by each thread's chunk to minimize allocs.

let num_threads = rayon::current_num_threads();
let chunk_size = (batch_size + num_threads - 1) / num_threads;
let chunk_size = batch_size.div_ceil(num_threads);
let mut results: Vec<F> = unsafe_allocate_zero_vec(batch_size);

results
Expand Down
1 change: 1 addition & 0 deletions jolt-core/src/subprotocols/grand_product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ where
}

/// A batched grand product circuit.
///
/// Note that the circuit roots are not included in `self.layers`
/// o o
/// / \ / \
Expand Down
4 changes: 2 additions & 2 deletions jolt-core/src/utils/instruction_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn concatenate_lookups<F: JoltField>(vals: &[F], C: usize, operand_bits: usi
///
/// ```
/// use jolt_core::utils::instruction_utils::chunk_operand;
///
/// // Normal usage
/// let x = 0b1100_1010_1111_0000;
/// assert_eq!(chunk_operand(x, 4, 4), vec![12, 10, 15, 0]);
Expand Down Expand Up @@ -76,7 +76,7 @@ pub fn chunk_operand(x: u64, C: usize, chunk_len: usize) -> Vec<u64> {
///
/// ```
/// use jolt_core::utils::instruction_utils::chunk_operand_usize;
///
/// // Normal usage
/// let x = 0b1100_1010_1111_0000;
/// assert_eq!(chunk_operand_usize(x, 4, 4), vec![12, 10, 15, 0]);
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub fn mul_0_optimized<F: JoltField>(likely_zero: &F, x: &F) -> F {

/// Checks if `num` is a power of 2.
pub fn is_power_of_two(num: usize) -> bool {
num != 0 && (num & (num - 1)) == 0
num != 0 && num.is_power_of_two()
}

/// Take the first two `num_bits` chunks of `item` (from the right / LSB) and return them as a tuple `(high_chunk, low_chunk)`.
Expand Down
18 changes: 8 additions & 10 deletions tracer/src/emulator/device/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,15 @@ impl Uart {
//println!("UART Store AD:{:X} VAL:{:X}", address, value);
match address {
// Transfer Holding Register
0x10000000 => match (self.lcr >> 7) == 0 {
true => {
0x10000000 => {
if (self.lcr >> 7) == 0 {
self.thr = value;
self.lsr &= !LSR_THR_EMPTY;
self.update_iir();
}
false => {} // @TODO: Implement properly
},
0x10000001 => match (self.lcr >> 7) == 0 {
true => {
} // @TODO: Implement else properly
}
0x10000001 => {
if (self.lcr >> 7) == 0 {
// This bahavior isn't written in the data sheet
// but some drivers seem to rely on it.
if (self.ier & IER_THREINT_BIT) == 0
Expand All @@ -172,9 +171,8 @@ impl Uart {
}
self.ier = value;
self.update_iir();
}
false => {} // @TODO: Implement properly
},
} // @TODO: Implement else properly
}
0x10000003 => {
self.lcr = value;
}
Expand Down
2 changes: 1 addition & 1 deletion tracer/src/emulator/device/virtio_block_disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ impl VirtioBlockDisk {
fn get_base_used_address(&self) -> u64 {
let align = self.queue_align as u64;
let queue_size = self.queue_size as u64;
((self.get_base_avail_address() + 4 + queue_size * 2 + align - 1) / align) * align
(self.get_base_avail_address() + 4 + queue_size * 2).div_ceil(align) * align
}

// @TODO: Follow the virtio block specification more propertly.
Expand Down

0 comments on commit 137bcf1

Please sign in to comment.