Skip to content

Commit

Permalink
more clippy and nightly fmt (#14)
Browse files Browse the repository at this point in the history
* more clippy and nightly fmt

* clippy

* cleanup trunk config
tcoratger authored Nov 6, 2024
1 parent 0a4fb78 commit 3bbec7d
Showing 14 changed files with 145 additions and 172 deletions.
4 changes: 0 additions & 4 deletions .trunk/configs/.rustfmt.toml

This file was deleted.

4 changes: 2 additions & 2 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -35,12 +35,12 @@ lint:
enabled:
- actionlint@1.7.4
- checkov@3.2.278
- clippy@1.65.0
- rustfmt@2024-01-04
- clippy@2024-01-04
- git-diff-check
- markdownlint@0.42.0
- osv-scanner@1.9.1
- prettier@3.3.3
- rustfmt@1.65.0
- shellcheck@0.10.0
- shfmt@3.6.0
- taplo@0.9.3
48 changes: 24 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -8,6 +8,33 @@ edition = "2021"
authors = ["Simon Malatrait <simon@kakarot.org>"]
description = "Brainfuck ZK-VM with STWO"

[workspace.lints]
rust.unreachable_pub = "warn"
rust.unused_must_use = "deny"
rust.rust_2018_idioms = { level = "deny", priority = -1 }
rustdoc.all = "warn"

[workspace.lints.clippy]
# all lints that are on by default (correctness, suspicious, style, complexity, perf)
all = { level = "warn", priority = -1 }

# new lints that are still under development
nursery = { level = "warn", priority = -1 }
# avoid lints that are too pedantic
future_not_send = "allow"
fallible_impl_from = "allow"

# lints which are rather strict or have occasional false positives
pedantic = { level = "warn", priority = -1 }
# avoid lints that are too pedantic
must_use_candidate = "allow"
cast_possible_truncation = "allow"
cast_precision_loss = "allow"
missing_errors_doc = "allow"
missing_panics_doc = "allow"
default_trait_access = "allow"
module_name_repetitions = "allow"

[workspace.dependencies]
clap = { version = "4.3.10", features = ["derive"] }
stwo-prover = { git = "https://github.com/starkware-libs/stwo", rev = "f6214d1" }
3 changes: 3 additions & 0 deletions crates/brainfuck_prover/Cargo.toml
Original file line number Diff line number Diff line change
@@ -5,4 +5,7 @@ edition.workspace = true
authors.workspace = true
description.workspace = true

[lints]
workspace = true

[dependencies]
3 changes: 3 additions & 0 deletions crates/brainfuck_vm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -5,6 +5,9 @@ edition.workspace = true
authors.workspace = true
description.workspace = true

[lints]
workspace = true

[dependencies]
clap = { workspace = true, features = ["derive"] }
num-traits = "0.2.19"
7 changes: 2 additions & 5 deletions crates/brainfuck_vm/src/bin/brainfuck_vm.rs
Original file line number Diff line number Diff line change
@@ -30,12 +30,9 @@ fn main() {
tracing_subscriber::fmt().with_env_filter(args.log).init();

let code = fs::read_to_string(&args.filename).expect("Failed to read file");
let mut bf_compiler = Compiler::new(code);
let mut bf_compiler = Compiler::new(&code);
let ins = bf_compiler.compile();
tracing::info!(
"Assembled instructions: {:?}",
ins.iter().map(|x| x.0).collect::<Vec<u32>>()
);
tracing::info!("Assembled instructions: {:?}", ins.iter().map(|x| x.0).collect::<Vec<u32>>());
tracing::info!("Program execution");
let stdin = stdin();
let stdout = stdout();
17 changes: 7 additions & 10 deletions crates/brainfuck_vm/src/compiler.rs
Original file line number Diff line number Diff line change
@@ -8,12 +8,9 @@ pub struct Compiler {
}

impl Compiler {
pub fn new(code: String) -> Self {
pub fn new(code: &str) -> Self {
let trimmed_code = code.chars().filter(|c| !c.is_whitespace()).collect();
Self {
code: trimmed_code,
instructions: vec![],
}
Self { code: trimmed_code, instructions: vec![] }
}

pub fn compile(&mut self) -> Vec<BaseField> {
@@ -30,8 +27,7 @@ impl Compiler {
let start_pos = loop_stack.pop().unwrap();
let loop_end_pos = self.instructions.len() + 1;
self.instructions[start_pos] = BaseField::from((loop_end_pos - 1) as u32);
self.instructions
.push(BaseField::from((start_pos + 1) as u32));
self.instructions.push(BaseField::from((start_pos + 1) as u32));
}
_ => (),
}
@@ -47,7 +43,7 @@ mod tests {

#[test]
fn test_new() {
let code = "++>,<[>+.<-]".to_string();
let code = "++>,<[>+.<-]";
let compiler = Compiler::new(code);
let expected_trimmed_code =
vec!['+', '+', '>', ',', '<', '[', '>', '+', '.', '<', '-', ']'];
@@ -56,7 +52,7 @@ mod tests {

#[test]
fn test_whitespace() {
let code = " + +> , < [> +.< - ] ".to_string();
let code = " + +> , <[> +.< - ] ";
let compiler = Compiler::new(code);
let expected_trimmed_code =
vec!['+', '+', '>', ',', '<', '[', '>', '+', '.', '<', '-', ']'];
@@ -65,9 +61,10 @@ mod tests {

#[test]
fn test_compile() {
let code = "++>,<[>+.<-]".to_string();
let code = "++>,<[>+.<-]";
let mut compiler = Compiler::new(code);
let instructions = compiler.compile();
#[allow(clippy::cast_sign_loss)]
let expected_ins: Vec<BaseField> =
vec![43, 43, 62, 44, 60, 91, 13, 62, 43, 46, 60, 45, 93, 7]
.into_iter()
Loading

0 comments on commit 3bbec7d

Please sign in to comment.