Skip to content

Commit

Permalink
fix: merge resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 committed Nov 6, 2023
1 parent a937dc6 commit 1701a27
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
4 changes: 2 additions & 2 deletions ast/src/analyzed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ pub struct Identity<Expr> {
//
// NTS(Md) Both left and right are only used in the case of perm / plookup
//
pub left: SelectedExpressions<T>, // left is selector expressions - for an arithmetic gate, the entire relation is in SL
pub right: SelectedExpressions<T>, // right is the overall expressions
pub left: SelectedExpressions<Expr>, // left is selector expressions - for an arithmetic gate, the entire relation is in SL
pub right: SelectedExpressions<Expr>, // right is the overall expressions
}

impl<Expr> Identity<Expr> {
Expand Down
8 changes: 4 additions & 4 deletions backend/src/bberg_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<T: FieldElement> BackendImplWithSetup<T> for BBergCodegen {
}

// TODO: implement this
fn write_setup(&self, mut output: &mut dyn io::Write) -> Result<(), io::Error> {
fn write_setup(&self, _output: &mut dyn io::Write) -> Result<(), io::Error> {
Ok(())
// self.write_setup(&mut output)
}
Expand All @@ -51,9 +51,9 @@ impl<T: FieldElement> BackendImpl<T> for BBergMock {

fn prove(
&self,
pil: &Analyzed<T>,
fixed: &[(&str, Vec<T>)],
witness: &[(&str, Vec<T>)],
_pil: &Analyzed<T>,
_fixed: &[(&str, Vec<T>)],
_witness: &[(&str, Vec<T>)],
prev_proof: Option<Proof>,
) -> (Option<Proof>, Option<String>) {
if prev_proof.is_some() {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/pilstark/estark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<F: FieldElement> BackendImpl<F> for EStark {
&setup.program,
&pil,
&self.params,
"",
// "",
)
.unwrap();

Expand Down
33 changes: 18 additions & 15 deletions bberg/src/circuit_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ use std::collections::{HashMap, HashSet};
use std::fs::File;
use std::{fmt::Display, io::Write, process::id};

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

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

Expand Down Expand Up @@ -490,14 +493,14 @@ fn get_cols_in_identity_macro(all_rows_and_shifts: &Vec<String>) -> String {
)
}

fn create_identity<F: FieldElement>(
expression: &SelectedExpressions<F>,
fn create_identity<T: FieldElement>(
expression: &SelectedExpressions<Expression<T>>,
collected_shifts: &mut HashSet<String>,
) -> Option<BBIdentity> {
// We want to read the types of operators and then create the appropiate code

if let Some(expr) = &expression.selector {
let x = craft_expression(&expr, collected_shifts);
let x = craft_expression(expr, collected_shifts);
println!("{:?}", x);
Some(x)
} else {
Expand All @@ -518,7 +521,7 @@ fn create_subrelation(index: usize, preamble: String, identity: &mut BBIdentity)
auto tmp = {id};
tmp *= scaling_factor;
tmp *= main_FIRST; // Temp to switch off
tmp *= (-main_FIRST+ FF(1)); // Temp to switch off
std::get<{index}>(evals) += tmp;
}}",
)
Expand All @@ -530,7 +533,7 @@ fn craft_expression<T: FieldElement>(
) -> BBIdentity {
match expr {
Expression::Number(n) => (1, format!("FF({})", n.to_arbitrary_integer())),
Expression::Reference(Reference::Poly(polyref)) => {
Expression::Reference(polyref) => {
assert_eq!(polyref.index, None);
let mut poly_name = format!("{}", &polyref.name.replace(".", "_"));
let mut degree = 1;
Expand All @@ -553,27 +556,27 @@ fn craft_expression<T: FieldElement>(
// dbg!(&lhe);
let degree = std::cmp::max(ld, rd);
match op {
BinaryOperator::Add => (degree, format!("({} + {})", lhs, rhs)),
BinaryOperator::Sub => match lhe.as_ref() {
AlgebraicBinaryOperator::Add => (degree, format!("({} + {})", lhs, rhs)),
AlgebraicBinaryOperator::Sub => match lhe.as_ref() {
// BBerg hack, we do not want a field on the lhs of an expression
Expression::Number(_) => (degree, format!("(-{} + {})", rhs, lhs)),
_ => (degree, format!("({} - {})", lhs, rhs)),
},

BinaryOperator::Mul => (degree + 1, format!("({} * {})", lhs, rhs)),
AlgebraicBinaryOperator::Mul => (degree + 1, format!("({} * {})", lhs, rhs)),
_ => unimplemented!("{:?}", expr),
}
}
Expression::Constant(name) => {
panic!("Constant {name} was not inlined. optimize_constants needs to be run at least.")
}
// Expression::Constant(name) => {
// panic!("Constant {name} was not inlined. optimize_constants needs to be run at least.")
// }
// pub enum UnaryOperator {
// Plus,
// Minus,
// LogicalNot,
// }
Expression::UnaryOperation(operator, expression) => match operator {
UnaryOperator::Minus => {
AlgebraicUnaryOperator::Minus => {
let (d, e) = craft_expression(expression, collected_shifts);
(d, format!("-{}", e))
}
Expand All @@ -589,7 +592,7 @@ type BBIdentity = (DegreeType, String);

/// Todo, eventually these will need to be siloed based on the file name they are in
fn create_identities<F: FieldElement>(
identities: &Vec<Identity<F>>,
identities: &Vec<Identity<Expression<F>>>,
) -> (Vec<String>, Vec<BBIdentity>, HashSet<String>) {
// We only want the expressions for now
// When we have a poly type, we only need the left side of it
Expand Down
6 changes: 2 additions & 4 deletions bberg/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ use std::iter;

use std::collections::HashMap;




/// Module to convert brillig assmebly into powdr assembly

// struct BrilligArchitecture {}
Expand Down Expand Up @@ -58,7 +55,8 @@ fn main() {
let bytecode = Vec::from(decoded);

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

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

Expand Down

0 comments on commit 1701a27

Please sign in to comment.