Skip to content

Commit

Permalink
fix: clippy (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 authored Nov 8, 2023
1 parent 1701a27 commit 1dd45d1
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 95 deletions.
4 changes: 2 additions & 2 deletions bberg/src/bberg_codegen.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ast::analyzed::Analyzed;
use std::{io, str::FromStr};
use std::io;

use number::{BigInt, Bn254Field, DegreeType, FieldElement};

Expand All @@ -21,7 +21,7 @@ impl BBergCodegen {
Self {}
}

pub fn new_from_setup(input: &mut impl io::Read) -> Result<Self, io::Error> {
pub fn new_from_setup(_input: &mut impl io::Read) -> Result<Self, io::Error> {
println!("warning bberg: new_from_setup not implemented");
Ok(Self {})
}
Expand Down
53 changes: 26 additions & 27 deletions bberg/src/circuit_builder.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
use std::collections::{HashMap, HashSet};
use std::collections::HashSet;
use std::fs::File;
use std::{fmt::Display, io::Write, process::id};
use std::io::Write;

use ast::parsed::{SelectedExpressions, UnaryOperator};
use ast::parsed::SelectedExpressions;
// use acvm::acir::native_types::Expression;
use ast::{analyzed::Identity, asm_analysis::DegreeStatement, parsed::BinaryOperator};
use ast::analyzed::Identity;
use itertools::Itertools;
use num_bigint::BigUint;

use ast::analyzed::{
AlgebraicBinaryOperator, AlgebraicExpression as Expression, AlgebraicUnaryOperator, Analyzed,
IdentityKind, Reference,
IdentityKind,
};
use num_traits::{identities, One};
use number::{BigInt, DegreeType, FieldElement};

use number::{DegreeType, FieldElement};

// use super::circuit_data::CircuitData;

Expand Down Expand Up @@ -206,7 +205,7 @@ pub(crate) fn analyzed_to_cpp<F: FieldElement>(
let shifted_polys: Vec<String> = collected_shifts.drain().collect_vec();
dbg!(shifted_polys.clone());

let (all_cols, unshifted, to_be_shifted, shifted, all_cols_with_shifts) =
let (all_cols, unshifted, to_be_shifted, _shifted, all_cols_with_shifts) =
get_all_col_names(fixed, witness, &shifted_polys);
let num_cols = all_cols_with_shifts.len();

Expand Down Expand Up @@ -285,10 +284,10 @@ namespace arithmetization {{

fn create_relation_hpp(
name: &str,
sub_relations: &Vec<String>,
identities: &Vec<BBIdentity>,
sub_relations: &[String],
identities: &[BBIdentity],
row_type: &String,
all_rows_and_shifts: &Vec<String>,
all_rows_and_shifts: &[String],
) -> String {
let includes = relation_includes();
let class_boilerplate = relation_class_boilerplate(name, sub_relations, identities);
Expand All @@ -314,8 +313,8 @@ namespace proof_system::{name}_vm {{

fn relation_class_boilerplate(
name: &str,
sub_relations: &Vec<String>,
identities: &Vec<BBIdentity>,
sub_relations: &[String],
identities: &[BBIdentity],
) -> String {
// TODO: MOVE ELSEWHERE: We add one to all degrees because we have an extra scaling factor
let degrees = identities.iter().map(|(d, _)| d + 1).collect();
Expand All @@ -340,7 +339,7 @@ fn get_export(name: &str) -> String {
)
}

fn get_relation_code(ids: &Vec<String>) -> String {
fn get_relation_code(ids: &[String]) -> String {
let mut relation_code = r#"
template <typename ContainerOverSubrelations, typename AllEntities>
void static accumulate(
Expand Down Expand Up @@ -392,17 +391,17 @@ fn relation_includes() -> &'static str {
}

// Yucky that everything is allocated into vecs here
fn create_row_type_items(names: &Vec<String>) -> Vec<String> {
fn create_row_type_items(names: &[String]) -> Vec<String> {
names
.iter()
.map(|name| format!(" FF {} {{}};", name.replace(".", "_")))
.map(|name| format!(" FF {} {{}};", name.replace('.', "_")))
.collect::<Vec<_>>()
}

fn get_all_col_names<F: FieldElement>(
fixed: &[(&str, Vec<F>)],
witness: &[(&str, Vec<F>)],
to_be_shifted: &Vec<String>,
to_be_shifted: &[String],
) -> (
Vec<String>,
Vec<String>,
Expand All @@ -413,14 +412,14 @@ fn get_all_col_names<F: FieldElement>(
let fixed_names: Vec<String> = fixed
.iter()
.map(|(name, _)| {
let n = name.replace(".", "_");
let n = name.replace('.', "_");
n.to_owned()
})
.collect();
let witness_names: Vec<String> = witness
.iter()
.map(|(name, _)| {
let n = name.replace(".", "_");
let n = name.replace('.', "_");
n.to_owned()
})
.collect();
Expand Down Expand Up @@ -451,14 +450,14 @@ fn get_all_col_names<F: FieldElement>(
(
all_cols,
unshifted,
to_be_shifted.clone(),
to_be_shifted.to_vec(),
shifted,
with_shifts,
)
}

// Each vm will need to have a row which is a combination of all of the witness columns
fn create_row_type(all_rows: &Vec<String>) -> String {
fn create_row_type(all_rows: &[String]) -> String {
let all_annotated = create_row_type_items(all_rows);

let row_type = format!(
Expand All @@ -470,11 +469,11 @@ fn create_row_type(all_rows: &Vec<String>) -> String {
row_type
}

fn get_cols_in_identity_macro(all_rows_and_shifts: &Vec<String>) -> String {
fn get_cols_in_identity_macro(all_rows_and_shifts: &[String]) -> String {
let make_view_per_row = all_rows_and_shifts
.iter()
.map(|row_name| {
let name = row_name.replace(".", "_");
let name = row_name.replace('.', "_");
format!("[[maybe_unused]] auto {name} = View(new_term.{name}); \\")
})
.collect::<Vec<_>>()
Expand Down Expand Up @@ -514,7 +513,7 @@ fn create_subrelation(index: usize, preamble: String, identity: &mut BBIdentity)
let id = &identity.1;

// TODO: TEMP HACK: Part of the main_FIRST hack below - to switch off constraints on the first row
identity.0 += identity.0 + 1;
identity.0 += 1;
format!(
"//Contribution {index}
{{\n{preamble}
Expand All @@ -535,7 +534,7 @@ fn craft_expression<T: FieldElement>(
Expression::Number(n) => (1, format!("FF({})", n.to_arbitrary_integer())),
Expression::Reference(polyref) => {
assert_eq!(polyref.index, None);
let mut poly_name = format!("{}", &polyref.name.replace(".", "_"));
let mut poly_name = polyref.name.replace('.', "_").to_string();
let mut degree = 1;
if polyref.next {
// NOTE: Naive algorithm to collect all shifted polys
Expand All @@ -545,7 +544,7 @@ fn craft_expression<T: FieldElement>(

// TODO(HORRIBLE): TEMP, add in a relation that turns off shifts on the last row
poly_name = format!("{poly_name} * (-main_LAST + FF(1))");
degree = degree + 1;
degree += 1;
}
(degree, poly_name)
}
Expand Down
40 changes: 20 additions & 20 deletions bberg/src/flavor_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

pub(crate) fn create_flavor_hpp(
name: &str,
relations: &Vec<String>,
all_cols: &Vec<String>,
shifted: &Vec<String>,
// shifted: &Vec<String>,
relations: &[String],
all_cols: &[String],
shifted: &[String],
// shifted: &[String],
) -> String {
let includes = flavor_includes(name, &relations);
let includes = flavor_includes(name, relations);
let num_witness = all_cols.len();
let num_all = num_witness + shifted.len();
// Note: includes all witness shifts
// TODO: for now we include a shift OF ALL witness wires, however this is not necessarily true

let precomputed = witness_get(all_cols, 0, false);
let witness_str = create_witness_entities(&all_cols);
let all_shift = witness_get(&shifted, num_witness, true);
let witness_str = create_witness_entities(all_cols);
let all_shift = witness_get(shifted, num_witness, true);

dbg!(&all_shift);

let all_entities_get_wires = make_wires_set(
&[all_cols.clone(), shifted.clone()]
&[all_cols.to_vec(), shifted.to_vec()]
.into_iter()
.flatten()
.collect::<Vec<String>>(),
Expand All @@ -34,7 +34,7 @@ pub(crate) fn create_flavor_hpp(
.collect::<Vec<String>>(),
);

let commitment_labels_class = create_commitment_labels(&all_cols);
let commitment_labels_class = create_commitment_labels(all_cols);

let verification_commitments = create_verifier_commitments();

Expand Down Expand Up @@ -245,7 +245,7 @@ class {name}Flavor : public {name}FlavorBase<grumpkin::g1, curve::BN254, pcs::kz
)
}

fn flavor_includes(name: &str, _relations: &Vec<String>) -> String {
fn flavor_includes(name: &str, _relations: &[String]) -> String {
// TODO: when there are multiple relations generated, they will need to be known in this file

// TODO: Get the path for generated / other relations from self
Expand All @@ -267,10 +267,10 @@ fn flavor_includes(name: &str, _relations: &Vec<String>) -> String {
)
}

fn create_precomputed_entities(fixed: &Vec<String>) -> String {
fn create_precomputed_entities(fixed: &[String]) -> String {
let mut name_set = String::new();
for name in fixed {
let n = name.replace(".", "_");
let n = name.replace('.', "_");
name_set.push_str(&format!("{n}, ", n = n));
}

Expand All @@ -286,10 +286,10 @@ fn create_precomputed_entities(fixed: &Vec<String>) -> String {
get_selectors
}

fn witness_get(witness: &Vec<String>, offset: usize, shift: bool) -> String {
fn witness_get(witness: &[String], offset: usize, shift: bool) -> String {
let mut return_string = String::new();
for (i, name) in witness.iter().enumerate() {
let n = name.replace(".", "_");
let n = name.replace('.', "_");
let n = if shift { format!("{}_shift", n) } else { n };
let index = i + offset;
return_string.push_str(&format!(
Expand All @@ -309,11 +309,11 @@ fn witness_get(witness: &Vec<String>, offset: usize, shift: bool) -> String {
// fn wi

// Takes in a set of wire names and outputs wrapped get_wires function
fn make_wires_set(set: &Vec<String>) -> String {
fn make_wires_set(set: &[String]) -> String {
let mut wires = String::new();

for name in set.iter() {
let n = name.replace(".", "_");
let n = name.replace('.', "_");
wires.push_str(&format!(
"{n},
",
Expand All @@ -323,7 +323,7 @@ fn make_wires_set(set: &Vec<String>) -> String {
wires
}

fn create_witness_entities(witness: &Vec<String>) -> String {
fn create_witness_entities(witness: &[String]) -> String {
let data_types = witness_get(witness, 0, false);
let get_wires = make_wires_set(witness);

Expand All @@ -342,10 +342,10 @@ fn create_witness_entities(witness: &Vec<String>) -> String {
)
}

fn create_labels(all_ents: &Vec<String>) -> String {
fn create_labels(all_ents: &[String]) -> String {
let mut labels = String::new();
for name in all_ents {
let n = name.replace(".", "_");
let n = name.replace('.', "_");
labels.push_str(&format!(
"Base::{n} = \"{n}\";
",
Expand All @@ -355,7 +355,7 @@ fn create_labels(all_ents: &Vec<String>) -> String {
labels
}

fn create_commitment_labels(all_ents: &Vec<String>) -> String {
fn create_commitment_labels(all_ents: &[String]) -> String {
let labels = create_labels(all_ents);

format!(
Expand Down
33 changes: 14 additions & 19 deletions bberg/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use acvm::acir::circuit::Opcode;
use acvm::brillig_vm::brillig::BinaryFieldOp;
use acvm::brillig_vm::brillig::Label;
use acvm::brillig_vm::brillig::RegisterIndex;
use rand::distributions::Alphanumeric;

use rand::Rng;
use std::fs;
use std::io::Write;
Expand Down Expand Up @@ -51,12 +51,12 @@ fn main() {
// Read in file called bytecode.acir
let bytecode = fs::read("bytecode.acir").expect("Unable to read file");
// Convert the read-in base64 file into Vec<u8>
let decoded = base64::decode(&bytecode).expect("Failed to decode base64");
let bytecode = Vec::from(decoded);
let decoded = base64::decode(bytecode).expect("Failed to decode base64");
let bytecode = decoded;

// Create a new circuit from the bytecode instance
let circuit: Circuit =
Circuit::deserialize_circuit(&*bytecode).expect("Failed to deserialize circuit");
Circuit::deserialize_circuit(&bytecode).expect("Failed to deserialize circuit");

println!("circuit: {:?}", circuit);

Expand Down Expand Up @@ -114,22 +114,21 @@ fn construct_main(program: Opcode) -> Vec<String> {
}
};

println!("");
println!("");
println!();
println!();
trace.iter().for_each(|i| println!("{:?}", i));
println!("");
println!("");
println!();
println!();

// Label of [index], String, where index is the generated name of the jump, we will place a jump label there when
// we encounter it to prove
let mut index = 0;
let mut labels: HashMap<Label, String> = HashMap::new();

for instr in trace {
for (index, instr) in trace.into_iter().enumerate() {
println!("{:?}", instr);
println!("");
println!("");
println!("");
println!();
println!();
println!();
// powdr_asm.push_str(&instr.to_string());

// If we require a label to be placed at the jump location then we add it
Expand Down Expand Up @@ -205,9 +204,6 @@ fn construct_main(program: Opcode) -> Vec<String> {
}
_ => println!("not implemented"),
}

// Increment the index in the instruction array
index += 1;
}

println!("main_asm: {:?}", main_asm);
Expand All @@ -230,13 +226,12 @@ fn gen_label() -> String {

fn print_register(r_index: RegisterIndex) -> String {
let num = r_index.to_usize();
format!("r{}", num.to_string()).to_owned()
format!("r{}", num).to_owned()
}

// Read the preamble from the brillig.asm machine
fn get_preamble() -> String {
let preamble = fs::read_to_string("brillig.asm").expect("Unable to read file");
preamble
fs::read_to_string("brillig.asm").expect("Unable to read file")
}

fn extract_brillig(opcodes: Vec<Opcode>) -> Opcode {
Expand Down
Loading

0 comments on commit 1dd45d1

Please sign in to comment.