Skip to content

Commit

Permalink
chore: Don't use wildcard imports
Browse files Browse the repository at this point in the history
changelog: ignore
  • Loading branch information
jan-ferdinand committed Sep 12, 2024
1 parent b842ec5 commit 96a9c3b
Show file tree
Hide file tree
Showing 24 changed files with 2,172 additions and 1,732 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ cloned_instead_of_copied = "warn"
copy_iterator = "warn"
default_trait_access = "warn"
doc_link_with_quotes = "warn"
enum_glob_use = "warn"
expl_impl_clone_on_copy = "warn"
explicit_deref_methods = "warn"
explicit_into_iter_loop = "warn"
Expand Down Expand Up @@ -145,6 +146,7 @@ unnested_or_patterns = "warn"
unused_async = "warn"
used_underscore_binding = "warn"
verbose_bit_mask = "warn"
wildcard_imports = "warn"

[workspace.dependencies.cargo-husky]
version = "1.5"
Expand Down
2 changes: 1 addition & 1 deletion triton-air/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub mod table_column;
/// - introduce new constraints `e = b²`, `f = c²`, and `g = e·f`,
/// - replace the original constraint with `a = g·d`.
///
/// The degree lowering happens in the Triton VM's build script, `build.rs`.
/// The degree lowering happens in Triton VM's build script, `build.rs`.
pub const TARGET_DEGREE: isize = 4;

pub trait AIR {
Expand Down
1,739 changes: 873 additions & 866 deletions triton-air/src/table/processor.rs

Large diffs are not rendered by default.

64 changes: 44 additions & 20 deletions triton-isa/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ use std::fmt::Formatter;
use std::fmt::Result as FmtResult;

use nom::branch::alt;
use nom::bytes::complete::*;
use nom::bytes::complete::tag;
use nom::bytes::complete::take_while;
use nom::bytes::complete::take_while1;
use nom::character::complete::digit1;
use nom::combinator::*;
use nom::error::*;
use nom::multi::*;
use nom::combinator::cut;
use nom::combinator::eof;
use nom::combinator::fail;
use nom::combinator::opt;
use nom::error::ErrorKind;
use nom::error::VerboseError;
use nom::error::VerboseErrorKind;
use nom::multi::many0;
use nom::multi::many1;
use nom::Finish;
use nom::IResult;
use twenty_first::bfe;
Expand Down Expand Up @@ -60,12 +68,15 @@ impl<'a> InstructionToken<'a> {
}

pub fn to_labelled_instruction(&self) -> LabelledInstruction {
use InstructionToken::*;
match self {
Instruction(instr, _) => LabelledInstruction::Instruction(instr.to_owned()),
Label(label, _) => LabelledInstruction::Label(label.to_owned()),
Breakpoint(_) => LabelledInstruction::Breakpoint,
TypeHint(type_hint, _) => LabelledInstruction::TypeHint(type_hint.to_owned()),
InstructionToken::Instruction(instr, _) => {
LabelledInstruction::Instruction(instr.to_owned())
}
InstructionToken::Label(label, _) => LabelledInstruction::Label(label.to_owned()),
InstructionToken::Breakpoint(_) => LabelledInstruction::Breakpoint,
InstructionToken::TypeHint(type_hint, _) => {
LabelledInstruction::TypeHint(type_hint.to_owned())
}
}
}
}
Expand Down Expand Up @@ -94,7 +105,7 @@ fn pretty_print_error(s: &str, mut e: VerboseError<&str>) -> String {
) {
e.errors.remove(0);
}
convert_error(s, e)
nom::error::convert_error(s, e)
}

/// Parse a program
Expand Down Expand Up @@ -185,7 +196,7 @@ type ParseResult<'input, Out> = IResult<&'input str, Out, VerboseError<&'input s
pub fn tokenize(s: &str) -> ParseResult<Vec<InstructionToken>> {
let (s, _) = comment_or_whitespace0(s)?;
let (s, instructions) = many0(alt((label, labelled_instruction, breakpoint, type_hint)))(s)?;
let (s, _) = context("expecting label, instruction or eof", eof)(s)?;
let (s, _) = nom::error::context("expecting label, instruction or eof", eof)(s)?;

Ok((s, instructions))
}
Expand All @@ -204,7 +215,10 @@ fn label(label_s: &str) -> ParseResult<InstructionToken> {
// `cut` will reject the alternative parser of `label`, being `labelled_instruction`, which
// *is* allowed to contain valid instruction names.
if is_instruction_name(&addr) {
return cut(context("label cannot be named after instruction", fail))(label_s);
return cut(nom::error::context(
"label cannot be named after instruction",
fail,
))(label_s);
}

Ok((s, InstructionToken::Label(addr, label_s)))
Expand Down Expand Up @@ -411,7 +425,10 @@ fn call_instruction<'a>() -> impl Fn(&'a str) -> ParseResult<AnInstruction<Strin
// between the scenarios `<label>:` and `call <label>`; the former requires
// parsing the `:` before rejecting a possible instruction name in the label.
if is_instruction_name(&addr) {
return cut(context("label cannot be named after instruction", fail))(s);
return cut(nom::error::context(
"label cannot be named after instruction",
fail,
))(s);
}

Ok((s, AnInstruction::Call(addr)))
Expand Down Expand Up @@ -456,12 +473,12 @@ fn field_element(s_orig: &str) -> ParseResult<BFieldElement> {
let (s, _) = comment_or_whitespace1(s)?;

let Ok(mut n): Result<i128, _> = n.parse() else {
return context("out-of-bounds constant", fail)(s);
return nom::error::context("out-of-bounds constant", fail)(s);
};

let quotient = i128::from(BFieldElement::P);
if n >= quotient {
return context("out-of-bounds constant", fail)(s_orig);
return nom::error::context("out-of-bounds constant", fail)(s_orig);
}

if negative.is_some() {
Expand Down Expand Up @@ -491,7 +508,11 @@ fn stack_register(s: &str) -> ParseResult<OpStackElement> {
"13" => OpStackElement::ST13,
"14" => OpStackElement::ST14,
"15" => OpStackElement::ST15,
_ => return context("using an out-of-bounds stack register (0-15 exist)", fail)(s),
_ => {
return nom::error::context("using an out-of-bounds stack register (0-15 exist)", fail)(
s,
)
}
};
let (s, _) = comment_or_whitespace1(s)?;

Expand All @@ -506,7 +527,7 @@ fn number_of_words(s: &str) -> ParseResult<NumberOfWords> {
"3" => NumberOfWords::N3,
"4" => NumberOfWords::N4,
"5" => NumberOfWords::N5,
_ => return context("using an out-of-bounds argument (1-5 allowed)", fail)(s),
_ => return nom::error::context("using an out-of-bounds argument (1-5 allowed)", fail)(s),
};
let (s, _) = comment_or_whitespace1(s)?; // require space after element

Expand All @@ -521,7 +542,7 @@ fn label_addr(s_orig: &str) -> ParseResult<String> {
// `alt`. With a custom error type, it is possible to have alt return the error of the
// parser that went the farthest in the input data.
let failure_reason = "label must start with an alphabetic character or underscore";
return context(failure_reason, fail)(s_orig);
return nom::error::context(failure_reason, fail)(s_orig);
}
let (s, addr_part_1) = take_while(is_label_char)(s)?;

Expand Down Expand Up @@ -615,7 +636,10 @@ fn type_hint(s_type_hint: &str) -> ParseResult<InstructionToken> {

let length = match maybe_range_end {
Some(range_end) if range_end <= range_start => {
return cut(context("range end must be greater than range start", fail))(s)
return cut(nom::error::context(
"range end must be greater than range start",
fail,
))(s)
}
Some(range_end) => range_end - range_start,
None => 1,
Expand Down Expand Up @@ -691,7 +715,7 @@ fn is_type_hint_type_name_character(c: char) -> bool {
fn parse_str_to_usize(s: &str) -> ParseResult<usize> {
match s.parse::<usize>() {
Ok(u) => Ok((s, u)),
Err(_) => cut(context("integer conversion failure", fail))(s),
Err(_) => cut(nom::error::context("integer conversion failure", fail))(s),
}
}

Expand Down
27 changes: 12 additions & 15 deletions triton-vm/benches/proof_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,34 +87,31 @@ enum DataSizeOrderOfMagnitude {
impl DataSizeOrderOfMagnitude {
/// The order of magnitude the given number of bytes falls in.
fn order_of_magnitude(num_bytes: f64) -> Self {
use DataSizeOrderOfMagnitude::*;
match num_bytes {
b if b < KiloBytes.min_bytes_in_order_of_magnitude() => Bytes,
b if b < MegaBytes.min_bytes_in_order_of_magnitude() => KiloBytes,
b if b < GigaBytes.min_bytes_in_order_of_magnitude() => MegaBytes,
_ => GigaBytes,
b if b < Self::KiloBytes.min_bytes_in_order_of_magnitude() => Self::Bytes,
b if b < Self::MegaBytes.min_bytes_in_order_of_magnitude() => Self::KiloBytes,
b if b < Self::GigaBytes.min_bytes_in_order_of_magnitude() => Self::MegaBytes,
_ => Self::GigaBytes,
}
}

/// The minimal number of bytes to be considered some order of magnitude.
fn min_bytes_in_order_of_magnitude(self) -> f64 {
use DataSizeOrderOfMagnitude::*;
match self {
Bytes => 1.0,
KiloBytes => 1024.0,
MegaBytes => 1024.0 * 1024.0,
GigaBytes => 1024.0 * 1024.0 * 1024.0,
Self::Bytes => 1.0,
Self::KiloBytes => 1024.0,
Self::MegaBytes => 1024.0 * 1024.0,
Self::GigaBytes => 1024.0 * 1024.0 * 1024.0,
}
}

/// The typical abbreviation for this order of magnitude.
fn abbreviation(self) -> &'static str {
use DataSizeOrderOfMagnitude::*;
match self {
Bytes => "bytes",
KiloBytes => "KiB",
MegaBytes => "MiB",
GigaBytes => "GiB",
Self::Bytes => "bytes",
Self::KiloBytes => "KiB",
Self::MegaBytes => "MiB",
Self::GigaBytes => "GiB",
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion triton-vm/benches/trace_mmr_new_peak_calculation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use criterion::*;
use criterion::criterion_group;
use criterion::criterion_main;
use criterion::Criterion;
use triton_vm::example_programs;
use triton_vm::prelude::VM;

Expand Down
15 changes: 8 additions & 7 deletions triton-vm/src/aet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use crate::table::op_stack::OpStackTableEntry;
use crate::table::ram::RamTableCall;
use crate::table::u32::U32TableEntry;
use crate::vm::CoProcessorCall;
use crate::vm::CoProcessorCall::*;
use crate::vm::VMState;

/// An Algebraic Execution Trace (AET) is the primary witness required for proof generation. It
Expand Down Expand Up @@ -241,12 +240,14 @@ impl AlgebraicExecutionTrace {

pub(crate) fn record_co_processor_call(&mut self, co_processor_call: CoProcessorCall) {
match co_processor_call {
Tip5Trace(Instruction::Hash, trace) => self.append_hash_trace(*trace),
SpongeStateReset => self.append_initial_sponge_state(),
Tip5Trace(instruction, trace) => self.append_sponge_trace(instruction, *trace),
U32Call(u32_entry) => self.record_u32_table_entry(u32_entry),
OpStackCall(op_stack_entry) => self.record_op_stack_entry(op_stack_entry),
RamCall(ram_call) => self.record_ram_call(ram_call),
CoProcessorCall::Tip5Trace(Instruction::Hash, trace) => self.append_hash_trace(*trace),
CoProcessorCall::SpongeStateReset => self.append_initial_sponge_state(),
CoProcessorCall::Tip5Trace(instruction, trace) => {
self.append_sponge_trace(instruction, *trace)
}
CoProcessorCall::U32(u32_entry) => self.record_u32_table_entry(u32_entry),
CoProcessorCall::OpStack(op_stack_entry) => self.record_op_stack_entry(op_stack_entry),
CoProcessorCall::Ram(ram_call) => self.record_ram_call(ram_call),
}
}

Expand Down
3 changes: 2 additions & 1 deletion triton-vm/src/arithmetic_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ mod tests {
use proptest_arbitrary_interop::arb;
use test_strategy::proptest;

use crate::shared_tests::*;
use crate::shared_tests::arbitrary_polynomial;
use crate::shared_tests::arbitrary_polynomial_of_degree;

use super::*;

Expand Down
6 changes: 3 additions & 3 deletions triton-vm/src/execution_trace_profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ impl ExecutionTraceProfiler {
CoProcessorCall::Tip5Trace(_, trace) => {
self.table_heights.hash += u32::try_from(trace.len()).unwrap();
}
CoProcessorCall::U32Call(c) => {
CoProcessorCall::U32(c) => {
self.u32_table_entries.insert(c);
let contribution = U32TableEntry::table_height_contribution;
self.table_heights.u32 = self.u32_table_entries.iter().map(contribution).sum();
}
CoProcessorCall::OpStackCall(_) => self.table_heights.op_stack += 1,
CoProcessorCall::RamCall(_) => self.table_heights.ram += 1,
CoProcessorCall::OpStack(_) => self.table_heights.op_stack += 1,
CoProcessorCall::Ram(_) => self.table_heights.ram += 1,
}
}
}
Expand Down
Loading

0 comments on commit 96a9c3b

Please sign in to comment.