Skip to content

Commit

Permalink
fix: rustfmt fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tohrnii committed Feb 24, 2023
1 parent 6ec1b2c commit 471f170
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion air-script-core/src/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl ListComprehension {
}

/// Contains values to be iterated over in a list comprehension.
///
///
/// For e.g. in the list comprehension \[x + y + z for (x, y, z) in (x, 0..5, z\[1..6\])\],
/// `x` is an Iterable of type Identifier representing the vector to iterate over,
/// `0..5` is an Iterable of type Range representing the range to iterate over,
Expand Down
14 changes: 7 additions & 7 deletions air-script/tests/list_comprehension/list_comprehension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Air for ListComprehensionAir {
fn evaluate_transition<E: FieldElement<BaseField = Felt>>(&self, frame: &EvaluationFrame<E>, periodic_values: &[E], result: &mut [E]) {
let main_current = frame.current();
let main_next = frame.next();
result[0] = main_current[0] - (main_current[2]);
result[0] = main_current[0] - main_current[2];
}

fn evaluate_aux_transition<F, E>(&self, main_frame: &EvaluationFrame<F>, aux_frame: &EvaluationFrame<E>, _periodic_values: &[F], aux_rand_elements: &AuxTraceRandElements<E>, result: &mut [E])
Expand All @@ -86,11 +86,11 @@ impl Air for ListComprehensionAir {
let main_next = main_frame.next();
let aux_current = aux_frame.current();
let aux_next = aux_frame.next();
result[0] = aux_current[0] - ((main_current[0]) * (((E::from(2_u64)).exp(E::PositiveInteger::from(3_u64))) * (aux_current[7])));
result[1] = aux_current[0] - ((main_current[0]) * (aux_next[4] - (aux_next[8])));
result[2] = aux_current[2] - ((main_current[0]) * (aux_current[5] - (aux_current[10])));
result[3] = aux_current[0] - (E::from(0_u64) + aux_current[1] - (aux_current[4]) - (aux_current[8]) + E::from(1_u64) + aux_current[2] - (aux_current[5]) - (aux_current[9]) + E::from(2_u64) + aux_current[3] - (aux_current[6]) - (aux_current[10]));
result[4] = aux_current[7] - ((aux_current[4]) * (aux_current[8]) + (aux_current[5]) * (aux_current[9]) + (aux_current[6]) * (aux_current[10]) + (aux_current[7]) * (aux_current[11]) + (((aux_current[4] + aux_current[8]) * (aux_current[5] + aux_current[9])) * (aux_current[6] + aux_current[10])) * (aux_current[7] + aux_current[11]));
result[5] = (aux_current[0]) * (main_current[0]) - (main_current[1] + (aux_current[4]) * (aux_current[8]) + (aux_current[5]) * (aux_current[9]) + (aux_current[6]) * (aux_current[10]) + (aux_current[7]) * (aux_current[11]) + (aux_current[4]) * (aux_current[8]) + (aux_current[5]) * (aux_current[9]) + (aux_current[6]) * (aux_current[10]) + (aux_current[7]) * (aux_current[11]));
result[0] = aux_current[0] - main_current[0] * E::from(2_u64).exp(E::PositiveInteger::from(3_u64)) * aux_current[7];
result[1] = aux_current[0] - main_current[0] * (aux_next[4] - aux_next[8]);
result[2] = aux_current[2] - main_current[0] * (aux_current[5] - aux_current[10]);
result[3] = aux_current[0] - (E::from(0_u64) + aux_current[1] - aux_current[4] - aux_current[8] + E::from(1_u64) + aux_current[2] - aux_current[5] - aux_current[9] + E::from(2_u64) + aux_current[3] - aux_current[6] - aux_current[10]);
result[4] = aux_current[7] - (aux_current[4] * aux_current[8] + aux_current[5] * aux_current[9] + aux_current[6] * aux_current[10] + aux_current[7] * aux_current[11] + (aux_current[4] + aux_current[8]) * (aux_current[5] + aux_current[9]) * (aux_current[6] + aux_current[10]) * (aux_current[7] + aux_current[11]));
result[5] = aux_current[0] * main_current[0] - (main_current[1] + aux_current[4] * aux_current[8] + aux_current[5] * aux_current[9] + aux_current[6] * aux_current[10] + aux_current[7] * aux_current[11] + aux_current[4] * aux_current[8] + aux_current[5] * aux_current[9] + aux_current[6] * aux_current[10] + aux_current[7] * aux_current[11]);
}
}
7 changes: 4 additions & 3 deletions ir/src/constraints/graph.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::{
list_comprehension::unfold_lc, BTreeMap, ConstantType, ConstraintDomain, ExprDetails, Expression, Identifier, IdentifierType,
IndexedTraceAccess, IntegrityConstraintDegree, ListFoldingType, MatrixAccess, Scope, SemanticError, SymbolTable,
TraceSegment, VariableRoots, VariableType, VectorAccess,
list_comprehension::unfold_lc, BTreeMap, ConstantType, ConstraintDomain, ExprDetails,
Expression, Identifier, IdentifierType, IndexedTraceAccess, IntegrityConstraintDegree,
ListFoldingType, MatrixAccess, Scope, SemanticError, SymbolTable, TraceSegment, VariableRoots,
VariableType, VectorAccess,
};

// CONSTANTS
Expand Down
16 changes: 8 additions & 8 deletions ir/src/constraints/list_comprehension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ pub fn unfold_lc(
symbol_table: &SymbolTable,
) -> Result<Vec<Expression>, SemanticError> {
let num_iterations = get_num_iterations(lc, symbol_table)?;
if num_iterations <= 1 {
if num_iterations == 0 {
return Err(SemanticError::InvalidListComprehension(
"List comprehensions must have more than one iteration.".to_string(),
"List comprehensions must have at least one iteration.".to_string(),
));
}

Expand Down Expand Up @@ -174,7 +174,7 @@ fn parse_named_trace_access(
}

/// Parses a list folding expression inside a list comprehension expression.
///
///
/// # Errors
/// - Returns an error if there is an error while unfolding the list comprehension.
fn parse_list_folding(
Expand Down Expand Up @@ -256,7 +256,7 @@ fn get_iterable_len(

/// Checks if the access index is valid. Returns an error if the access index is greater than
/// the size of the vector.
///
///
/// # Errors
/// - Returns an error if the access index is greater than the size of the vector.
fn validate_access(i: usize, size: usize) -> Result<(), SemanticError> {
Expand All @@ -270,7 +270,7 @@ fn validate_access(i: usize, size: usize) -> Result<(), SemanticError> {
}

/// Builds an [IterableContext] from a given list comprehension.
///
///
/// # Errors
/// - Returns an error if there are duplicate members in the list comprehension.
fn build_iterable_context(lc: &ListComprehension) -> Result<IterableContext, SemanticError> {
Expand All @@ -280,9 +280,9 @@ fn build_iterable_context(lc: &ListComprehension) -> Result<IterableContext, Sem
.insert(member.clone(), iterable.clone())
.is_some()
{
return Err(SemanticError::InvalidListComprehension(
format!("Duplicate member {member} in list comprehension"),
));
return Err(SemanticError::InvalidListComprehension(format!(
"Duplicate member {member} in list comprehension"
)));
}
}
Ok(iterable_context)
Expand Down
15 changes: 9 additions & 6 deletions ir/src/constraints/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{
symbol_table::IdentifierType, Boundary, BoundaryStmt, ConstantType, Expression, Identifier,
IndexedTraceAccess, IntegrityStmt, ListFoldingType, MatrixAccess, Scope, SemanticError, SymbolTable,
TraceSegment, Variable, VariableType, VectorAccess,
IndexedTraceAccess, IntegrityStmt, ListFoldingType, MatrixAccess, Scope, SemanticError,
SymbolTable, TraceSegment, Variable, VariableType, VectorAccess,
};
use std::collections::{BTreeMap, BTreeSet};

Expand Down Expand Up @@ -237,10 +237,13 @@ impl Constraints {
IntegrityStmt::Variable(variable) => {
if let VariableType::ListComprehension(list_comprehension) = variable.value() {
let vector = unfold_lc(list_comprehension, symbol_table)?;
symbol_table.insert_variable(Scope::IntegrityConstraints, &Variable::new(
Identifier(variable.name().to_string()),
VariableType::Vector(vector),
))?
symbol_table.insert_variable(
Scope::IntegrityConstraints,
&Variable::new(
Identifier(variable.name().to_string()),
VariableType::Vector(vector),
),
)?
} else {
symbol_table.insert_variable(Scope::IntegrityConstraints, variable)?
}
Expand Down
2 changes: 1 addition & 1 deletion ir/src/tests/list_comprehension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,4 @@ fn err_duplicate_member() {
let parsed = parse(source).expect("Parsing failed");
let result = AirIR::new(&parsed);
assert!(result.is_err());
}
}

0 comments on commit 471f170

Please sign in to comment.