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

more clippy and nightly fmt #14

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Expand Up @@ -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
Expand Down
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
Expand Up @@ -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" }
Expand Down
3 changes: 3 additions & 0 deletions crates/brainfuck_prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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"
Expand Down
7 changes: 2 additions & 5 deletions crates/brainfuck_vm/src/bin/brainfuck_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 7 additions & 10 deletions crates/brainfuck_vm/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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));
}
_ => (),
}
Expand All @@ -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!['+', '+', '>', ',', '<', '[', '>', '+', '.', '<', '-', ']'];
Expand All @@ -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!['+', '+', '>', ',', '<', '[', '>', '+', '.', '<', '-', ']'];
Expand All @@ -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()
Expand Down
Loading