diff --git a/compiler/src/expression/arithmetic/add.rs b/compiler/src/expression/arithmetic/add.rs index 28ae8b4003..e62ccfee78 100644 --- a/compiler/src/expression/arithmetic/add.rs +++ b/compiler/src/expression/arithmetic/add.rs @@ -1,4 +1,4 @@ -//! Methods to enforce arithmetic addition in a compiled Leo program. +//! Enforces an arithmetic `+` operator in a resolved Leo program. use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_types::Span; @@ -8,7 +8,7 @@ use snarkos_models::{ gadgets::r1cs::ConstraintSystem, }; -pub fn enforce_add_expression, CS: ConstraintSystem>( +pub fn enforce_add, CS: ConstraintSystem>( cs: &mut CS, left: ConstrainedValue, right: ConstrainedValue, @@ -26,11 +26,11 @@ pub fn enforce_add_expression, CS: Constr } (ConstrainedValue::Unresolved(string), val_2) => { let val_1 = ConstrainedValue::from_other(string, &val_2, span.clone())?; - enforce_add_expression(cs, val_1, val_2, span) + enforce_add(cs, val_1, val_2, span) } (val_1, ConstrainedValue::Unresolved(string)) => { let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?; - enforce_add_expression(cs, val_1, val_2, span) + enforce_add(cs, val_1, val_2, span) } (val_1, val_2) => Err(ExpressionError::incompatible_types( format!("{} + {}", val_1, val_2), diff --git a/compiler/src/expression/arithmetic/div.rs b/compiler/src/expression/arithmetic/div.rs index 51c9a8dd76..3f2a6c82c6 100644 --- a/compiler/src/expression/arithmetic/div.rs +++ b/compiler/src/expression/arithmetic/div.rs @@ -1,4 +1,4 @@ -//! Methods to enforce arithmetic division in a compiled Leo program. +//! Enforces an arithmetic `/` operator in a resolved Leo program. use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_types::Span; @@ -8,7 +8,7 @@ use snarkos_models::{ gadgets::r1cs::ConstraintSystem, }; -pub fn enforce_div_expression, CS: ConstraintSystem>( +pub fn enforce_div, CS: ConstraintSystem>( cs: &mut CS, left: ConstrainedValue, right: ConstrainedValue, @@ -23,11 +23,11 @@ pub fn enforce_div_expression, CS: Constr } (ConstrainedValue::Unresolved(string), val_2) => { let val_1 = ConstrainedValue::from_other(string, &val_2, span.clone())?; - enforce_div_expression(cs, val_1, val_2, span) + enforce_div(cs, val_1, val_2, span) } (val_1, ConstrainedValue::Unresolved(string)) => { let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?; - enforce_div_expression(cs, val_1, val_2, span) + enforce_div(cs, val_1, val_2, span) } (val_1, val_2) => { return Err(ExpressionError::incompatible_types( diff --git a/compiler/src/expression/arithmetic/mul.rs b/compiler/src/expression/arithmetic/mul.rs index a6b60c893a..9742c6ee83 100644 --- a/compiler/src/expression/arithmetic/mul.rs +++ b/compiler/src/expression/arithmetic/mul.rs @@ -1,4 +1,4 @@ -//! Methods to enforce arithmetic multiplication in a compiled Leo program. +//! Enforces an arithmetic `*` operator in a resolved Leo program. use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_types::Span; @@ -8,7 +8,7 @@ use snarkos_models::{ gadgets::r1cs::ConstraintSystem, }; -pub fn enforce_mul_expression, CS: ConstraintSystem>( +pub fn enforce_mul, CS: ConstraintSystem>( cs: &mut CS, left: ConstrainedValue, right: ConstrainedValue, @@ -23,11 +23,11 @@ pub fn enforce_mul_expression, CS: Constr } (ConstrainedValue::Unresolved(string), val_2) => { let val_1 = ConstrainedValue::from_other(string, &val_2, span.clone())?; - enforce_mul_expression(cs, val_1, val_2, span) + enforce_mul(cs, val_1, val_2, span) } (val_1, ConstrainedValue::Unresolved(string)) => { let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?; - enforce_mul_expression(cs, val_1, val_2, span) + enforce_mul(cs, val_1, val_2, span) } (val_1, val_2) => { return Err(ExpressionError::incompatible_types( diff --git a/compiler/src/expression/arithmetic/pow.rs b/compiler/src/expression/arithmetic/pow.rs index 0072f0e4a8..b817436c7f 100644 --- a/compiler/src/expression/arithmetic/pow.rs +++ b/compiler/src/expression/arithmetic/pow.rs @@ -1,4 +1,4 @@ -//! Methods to enforce arithmetic exponentiation in a compiled Leo program. +//! Enforces an arithmetic `**` operator in a resolved Leo program. use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_types::Span; @@ -8,7 +8,7 @@ use snarkos_models::{ gadgets::r1cs::ConstraintSystem, }; -pub fn enforce_pow_expression, CS: ConstraintSystem>( +pub fn enforce_pow, CS: ConstraintSystem>( cs: &mut CS, left: ConstrainedValue, right: ConstrainedValue, @@ -20,11 +20,11 @@ pub fn enforce_pow_expression, CS: Constr } (ConstrainedValue::Unresolved(string), val_2) => { let val_1 = ConstrainedValue::from_other(string, &val_2, span.clone())?; - enforce_pow_expression(cs, val_1, val_2, span) + enforce_pow(cs, val_1, val_2, span) } (val_1, ConstrainedValue::Unresolved(string)) => { let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?; - enforce_pow_expression(cs, val_1, val_2, span) + enforce_pow(cs, val_1, val_2, span) } (val_1, val_2) => Err(ExpressionError::incompatible_types( format!("{} ** {}", val_1, val_2,), diff --git a/compiler/src/expression/arithmetic/sub.rs b/compiler/src/expression/arithmetic/sub.rs index 86248fda23..aca482b6b3 100644 --- a/compiler/src/expression/arithmetic/sub.rs +++ b/compiler/src/expression/arithmetic/sub.rs @@ -1,4 +1,4 @@ -//! Methods to enforce arithmetic subtraction in a compiled Leo program. +//! Enforces an arithmetic `-` operator in a resolved Leo program. use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_types::Span; @@ -8,7 +8,7 @@ use snarkos_models::{ gadgets::r1cs::ConstraintSystem, }; -pub fn enforce_sub_expression, CS: ConstraintSystem>( +pub fn enforce_sub, CS: ConstraintSystem>( cs: &mut CS, left: ConstrainedValue, right: ConstrainedValue, @@ -26,11 +26,11 @@ pub fn enforce_sub_expression, CS: Constr } (ConstrainedValue::Unresolved(string), val_2) => { let val_1 = ConstrainedValue::from_other(string, &val_2, span.clone())?; - enforce_sub_expression(cs, val_1, val_2, span) + enforce_sub(cs, val_1, val_2, span) } (val_1, ConstrainedValue::Unresolved(string)) => { let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?; - enforce_sub_expression(cs, val_1, val_2, span) + enforce_sub(cs, val_1, val_2, span) } (val_1, val_2) => Err(ExpressionError::incompatible_types( format!("{} - {}", val_1, val_2), diff --git a/compiler/src/expression/array/access.rs b/compiler/src/expression/array/access.rs index c21d39efb6..dfe8da05e9 100644 --- a/compiler/src/expression/array/access.rs +++ b/compiler/src/expression/array/access.rs @@ -1,4 +1,4 @@ -//! Enforces constraints on array access expressions in a compiled Leo program. +//! Enforces array access in a compiled Leo program. use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_types::{Expression, RangeOrExpression, Span, Type}; @@ -9,7 +9,7 @@ use snarkos_models::{ }; impl> ConstrainedProgram { - pub fn enforce_array_access_expression>( + pub fn enforce_array_access>( &mut self, cs: &mut CS, file_scope: String, diff --git a/compiler/src/expression/array/array.rs b/compiler/src/expression/array/array.rs index 1711846407..070b28a2ec 100644 --- a/compiler/src/expression/array/array.rs +++ b/compiler/src/expression/array/array.rs @@ -1,4 +1,4 @@ -//! Enforces constraints on array expressions in a compiled Leo program. +//! Enforces an array expression in a compiled Leo program. use crate::{ errors::ExpressionError, @@ -15,7 +15,7 @@ use snarkos_models::{ impl> ConstrainedProgram { /// Enforce array expressions - pub fn enforce_array_expression>( + pub fn enforce_array>( &mut self, cs: &mut CS, file_scope: String, diff --git a/compiler/src/expression/array/index.rs b/compiler/src/expression/array/index.rs index 78aaec1b0b..a8aa4ca390 100644 --- a/compiler/src/expression/array/index.rs +++ b/compiler/src/expression/array/index.rs @@ -1,4 +1,4 @@ -//! Enforces constraints on an array index expression in a compiled Leo program. +//! Enforces an array index expression in a compiled Leo program. use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_types::{Expression, IntegerType, Span, Type}; diff --git a/compiler/src/expression/array/mod.rs b/compiler/src/expression/array/mod.rs index 4bb30b4e97..155fb848a8 100644 --- a/compiler/src/expression/array/mod.rs +++ b/compiler/src/expression/array/mod.rs @@ -1,3 +1,5 @@ +//! Methods to enforce array expressions in a compiled Leo program. + pub mod array; pub use self::array::*; diff --git a/compiler/src/expression/binary/binary.rs b/compiler/src/expression/binary/binary.rs index 46978b665a..c4502ac68b 100644 --- a/compiler/src/expression/binary/binary.rs +++ b/compiler/src/expression/binary/binary.rs @@ -1,4 +1,4 @@ -//! Enforce constraints on binary expressions in a compiled Leo program. +//! Enforces a binary expression in a compiled Leo program. use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_types::{Expression, Span, Type}; diff --git a/compiler/src/expression/binary/mod.rs b/compiler/src/expression/binary/mod.rs index 3d05d5b7a8..6c773d3071 100644 --- a/compiler/src/expression/binary/mod.rs +++ b/compiler/src/expression/binary/mod.rs @@ -1,3 +1,5 @@ +//! Methods to enforce binary expressions in a compiled Leo program. + pub mod binary; pub use self::binary::*; diff --git a/compiler/src/expression/binary/operand.rs b/compiler/src/expression/binary/operand.rs index e7675d3930..65ce939bbc 100644 --- a/compiler/src/expression/binary/operand.rs +++ b/compiler/src/expression/binary/operand.rs @@ -1,4 +1,4 @@ -//! Enforce constraints on one operand in a binary expression in a compiled Leo program. +//! Enforces one operand in a binary expression in a compiled Leo program. use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_types::{Expression, Span, Type}; diff --git a/compiler/src/expression/circuit/access.rs b/compiler/src/expression/circuit/access.rs index 69cdd29011..d7d672f5dd 100644 --- a/compiler/src/expression/circuit/access.rs +++ b/compiler/src/expression/circuit/access.rs @@ -1,4 +1,4 @@ -//! Enforces constraints on circuit access expressions in a compiled Leo program. +//! Enforces a circuit access expression in a compiled Leo program. use crate::{ errors::ExpressionError, @@ -16,7 +16,7 @@ use snarkos_models::{ static SELF_KEYWORD: &'static str = "self"; impl> ConstrainedProgram { - pub fn enforce_circuit_access_expression>( + pub fn enforce_circuit_access>( &mut self, cs: &mut CS, file_scope: String, diff --git a/compiler/src/expression/circuit/circuit.rs b/compiler/src/expression/circuit/circuit.rs index 1db54b7e55..fe1f5332aa 100644 --- a/compiler/src/expression/circuit/circuit.rs +++ b/compiler/src/expression/circuit/circuit.rs @@ -1,4 +1,4 @@ -//! Enforces constraints on circuit expressions in a compiled Leo program. +//! Enforces a circuit expression in a compiled Leo program. use crate::{ errors::ExpressionError, @@ -14,7 +14,7 @@ use snarkos_models::{ }; impl> ConstrainedProgram { - pub fn enforce_circuit_expression>( + pub fn enforce_circuit>( &mut self, cs: &mut CS, file_scope: String, diff --git a/compiler/src/expression/circuit/mod.rs b/compiler/src/expression/circuit/mod.rs index f932b09a75..ad707d8465 100644 --- a/compiler/src/expression/circuit/mod.rs +++ b/compiler/src/expression/circuit/mod.rs @@ -1,3 +1,5 @@ +//! Methods to enforce circuit expressions in a compiled Leo program. + pub mod access; pub use self::access::*; diff --git a/compiler/src/expression/circuit/static_access.rs b/compiler/src/expression/circuit/static_access.rs index 5c275acc0b..2afa33b20e 100644 --- a/compiler/src/expression/circuit/static_access.rs +++ b/compiler/src/expression/circuit/static_access.rs @@ -1,4 +1,4 @@ -//! Enforces constraints on circuit static access expressions in a compiled Leo program. +//! Enforces a circuit static access expression in a compiled Leo program. use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_types::{CircuitMember, Expression, Identifier, Span, Type}; @@ -9,7 +9,7 @@ use snarkos_models::{ }; impl> ConstrainedProgram { - pub fn enforce_circuit_static_access_expression>( + pub fn enforce_circuit_static_access>( &mut self, cs: &mut CS, file_scope: String, diff --git a/compiler/src/expression/conditional/ternary.rs b/compiler/src/expression/conditional/conditional.rs similarity index 95% rename from compiler/src/expression/conditional/ternary.rs rename to compiler/src/expression/conditional/conditional.rs index 1c2a960817..53df643584 100644 --- a/compiler/src/expression/conditional/ternary.rs +++ b/compiler/src/expression/conditional/conditional.rs @@ -1,4 +1,4 @@ -//! Methods to enforce constraints on ternary expressions in a compiled Leo program. +//! Enforces a conditional expression in a compiled Leo program. use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_types::{Expression, Span, Type}; diff --git a/compiler/src/expression/conditional/mod.rs b/compiler/src/expression/conditional/mod.rs index 66600b3a6d..34e4db8050 100644 --- a/compiler/src/expression/conditional/mod.rs +++ b/compiler/src/expression/conditional/mod.rs @@ -1,2 +1,4 @@ -pub mod ternary; -pub use self::ternary::*; +//! Methods to enforce conditional expressions in a compiled Leo program. + +pub mod conditional; +pub use self::conditional::*; diff --git a/compiler/src/expression/expression.rs b/compiler/src/expression/expression.rs index a8c7a51302..49b6b83b9f 100644 --- a/compiler/src/expression/expression.rs +++ b/compiler/src/expression/expression.rs @@ -1,4 +1,4 @@ -//! Methods to enforce constraints on expressions in a compiled Leo program. +//! Enforce constraints on an expression in a compiled Leo program. use crate::{ arithmetic::*, @@ -6,13 +6,13 @@ use crate::{ logical::*, program::ConstrainedProgram, relational::*, - value::{boolean::input::new_bool_constant, ConstrainedValue}, + value::{boolean::input::new_bool_constant, implicit::*, ConstrainedValue}, Address, FieldType, GroupType, Integer, }; -use leo_types::{Expression, Span, Type}; +use leo_types::{Expression, Type}; use snarkos_models::{ curves::{Field, PrimeField}, @@ -20,18 +20,6 @@ use snarkos_models::{ }; impl> ConstrainedProgram { - pub(crate) fn enforce_number_implicit( - expected_types: &Vec, - value: String, - span: Span, - ) -> Result, ExpressionError> { - if expected_types.len() == 1 { - return Ok(ConstrainedValue::from_type(value, &expected_types[0], span)?); - } - - Ok(ConstrainedValue::Unresolved(value)) - } - pub(crate) fn enforce_expression>( &mut self, cs: &mut CS, @@ -51,7 +39,7 @@ impl> ConstrainedProgram { Expression::Boolean(boolean, span) => Ok(ConstrainedValue::Boolean(new_bool_constant(boolean, span)?)), Expression::Field(field, span) => Ok(ConstrainedValue::Field(FieldType::constant(field, span)?)), Expression::Group(group_affine, span) => Ok(ConstrainedValue::Group(G::constant(group_affine, span)?)), - Expression::Implicit(value, span) => Self::enforce_number_implicit(expected_types, value, span), + Expression::Implicit(value, span) => Ok(enforce_number_implicit(expected_types, value, span)?), Expression::Integer(type_, integer, span) => { Ok(ConstrainedValue::Integer(Integer::new_constant(&type_, integer, span)?)) } @@ -68,7 +56,7 @@ impl> ConstrainedProgram { span.clone(), )?; - enforce_add_expression(cs, resolved_left, resolved_right, span) + enforce_add(cs, resolved_left, resolved_right, span) } Expression::Sub(left, right, span) => { let (resolved_left, resolved_right) = self.enforce_binary_expression( @@ -81,7 +69,7 @@ impl> ConstrainedProgram { span.clone(), )?; - enforce_sub_expression(cs, resolved_left, resolved_right, span) + enforce_sub(cs, resolved_left, resolved_right, span) } Expression::Mul(left, right, span) => { let (resolved_left, resolved_right) = self.enforce_binary_expression( @@ -94,7 +82,7 @@ impl> ConstrainedProgram { span.clone(), )?; - enforce_mul_expression(cs, resolved_left, resolved_right, span) + enforce_mul(cs, resolved_left, resolved_right, span) } Expression::Div(left, right, span) => { let (resolved_left, resolved_right) = self.enforce_binary_expression( @@ -107,7 +95,7 @@ impl> ConstrainedProgram { span.clone(), )?; - enforce_div_expression(cs, resolved_left, resolved_right, span) + enforce_div(cs, resolved_left, resolved_right, span) } Expression::Pow(left, right, span) => { let (resolved_left, resolved_right) = self.enforce_binary_expression( @@ -120,7 +108,7 @@ impl> ConstrainedProgram { span.clone(), )?; - enforce_pow_expression(cs, resolved_left, resolved_right, span) + enforce_pow(cs, resolved_left, resolved_right, span) } // Boolean operations @@ -165,7 +153,7 @@ impl> ConstrainedProgram { span.clone(), )?; - Ok(evaluate_eq_expression(cs, resolved_left, resolved_right, span)?) + Ok(evaluate_eq(cs, resolved_left, resolved_right, span)?) } Expression::Ge(left, right, span) => { let (resolved_left, resolved_right) = self.enforce_binary_expression( @@ -178,7 +166,7 @@ impl> ConstrainedProgram { span.clone(), )?; - Ok(evaluate_ge_expression(cs, resolved_left, resolved_right, span)?) + Ok(evaluate_ge(cs, resolved_left, resolved_right, span)?) } Expression::Gt(left, right, span) => { let (resolved_left, resolved_right) = self.enforce_binary_expression( @@ -191,7 +179,7 @@ impl> ConstrainedProgram { span.clone(), )?; - Ok(evaluate_gt_expression(cs, resolved_left, resolved_right, span)?) + Ok(evaluate_gt(cs, resolved_left, resolved_right, span)?) } Expression::Le(left, right, span) => { let (resolved_left, resolved_right) = self.enforce_binary_expression( @@ -204,7 +192,7 @@ impl> ConstrainedProgram { span.clone(), )?; - Ok(evaluate_le_expression(cs, resolved_left, resolved_right, span)?) + Ok(evaluate_le(cs, resolved_left, resolved_right, span)?) } Expression::Lt(left, right, span) => { let (resolved_left, resolved_right) = self.enforce_binary_expression( @@ -217,7 +205,7 @@ impl> ConstrainedProgram { span.clone(), )?; - Ok(evaluate_lt_expression(cs, resolved_left, resolved_right, span)?) + Ok(evaluate_lt(cs, resolved_left, resolved_right, span)?) } // Conditionals @@ -234,34 +222,27 @@ impl> ConstrainedProgram { // Arrays Expression::Array(array, span) => { - self.enforce_array_expression(cs, file_scope, function_scope, expected_types, array, span) + self.enforce_array(cs, file_scope, function_scope, expected_types, array, span) } - Expression::ArrayAccess(array, index, span) => self.enforce_array_access_expression( + Expression::ArrayAccess(array, index, span) => { + self.enforce_array_access(cs, file_scope, function_scope, expected_types, array, *index, span) + } + + // Circuits + Expression::Circuit(circuit_name, members, span) => { + self.enforce_circuit(cs, file_scope, function_scope, circuit_name, members, span) + } + Expression::CircuitMemberAccess(circuit_variable, circuit_member, span) => self.enforce_circuit_access( cs, file_scope, function_scope, expected_types, - array, - *index, + circuit_variable, + circuit_member, span, ), - - // Circuits - Expression::Circuit(circuit_name, members, span) => { - self.enforce_circuit_expression(cs, file_scope, function_scope, circuit_name, members, span) - } - Expression::CircuitMemberAccess(circuit_variable, circuit_member, span) => self - .enforce_circuit_access_expression( - cs, - file_scope, - function_scope, - expected_types, - circuit_variable, - circuit_member, - span, - ), Expression::CircuitStaticFunctionAccess(circuit_identifier, circuit_member, span) => self - .enforce_circuit_static_access_expression( + .enforce_circuit_static_access( cs, file_scope, function_scope, diff --git a/compiler/src/expression/function/function.rs b/compiler/src/expression/function/function.rs index 7a9eea46ae..1fa9c50797 100644 --- a/compiler/src/expression/function/function.rs +++ b/compiler/src/expression/function/function.rs @@ -1,4 +1,4 @@ -//! Enforce constraints on a function call expression in a compiled Leo program. +//! Enforce a function call expression in a compiled Leo program. use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_types::{Expression, Span, Type}; diff --git a/compiler/src/expression/function/mod.rs b/compiler/src/expression/function/mod.rs index 80945cf378..c456ec23e3 100644 --- a/compiler/src/expression/function/mod.rs +++ b/compiler/src/expression/function/mod.rs @@ -1,2 +1,4 @@ +//! Methods to enforce function call expressions in a compiled Leo program. + pub mod function; pub use self::function::*; diff --git a/compiler/src/expression/identifier/identifier.rs b/compiler/src/expression/identifier/identifier.rs index 1949fe7aaf..4b35ccb05a 100644 --- a/compiler/src/expression/identifier/identifier.rs +++ b/compiler/src/expression/identifier/identifier.rs @@ -1,4 +1,4 @@ -//! Methods to enforce constraints on expressions in a compiled Leo program. +//! Enforces an identifier expression in a compiled Leo program. use crate::{ errors::ExpressionError, diff --git a/compiler/src/expression/identifier/mod.rs b/compiler/src/expression/identifier/mod.rs index 294cb98b19..2845a35609 100644 --- a/compiler/src/expression/identifier/mod.rs +++ b/compiler/src/expression/identifier/mod.rs @@ -1,2 +1,4 @@ +//! Methods to enforce identifier expressions in a compiled Leo program. + pub mod identifier; pub use self::identifier::*; diff --git a/compiler/src/expression/logical/and.rs b/compiler/src/expression/logical/and.rs index 2ffc1f4ab5..db35ed1b5e 100644 --- a/compiler/src/expression/logical/and.rs +++ b/compiler/src/expression/logical/and.rs @@ -1,4 +1,4 @@ -//! Methods to enforce constraints on boolean operations in a resolved Leo program. +//! Enforces a logical `&&` operator in a resolved Leo program. use crate::{errors::BooleanError, value::ConstrainedValue, GroupType}; use leo_types::Span; diff --git a/compiler/src/expression/logical/not.rs b/compiler/src/expression/logical/not.rs index 6a17dbd830..8eaede90e8 100644 --- a/compiler/src/expression/logical/not.rs +++ b/compiler/src/expression/logical/not.rs @@ -1,4 +1,4 @@ -//! Methods to enforce constraints on boolean operations in a resolved Leo program. +//! Enforces a logical `!` operator in a resolved Leo program. use crate::{errors::BooleanError, value::ConstrainedValue, GroupType}; use leo_types::Span; diff --git a/compiler/src/expression/logical/or.rs b/compiler/src/expression/logical/or.rs index 92e2e39a37..a4f900adf6 100644 --- a/compiler/src/expression/logical/or.rs +++ b/compiler/src/expression/logical/or.rs @@ -1,4 +1,4 @@ -//! Methods to enforce constraints on boolean operations in a resolved Leo program. +//! Enforces a logical `||` operator in a resolved Leo program. use crate::{errors::BooleanError, value::ConstrainedValue, GroupType}; use leo_types::Span; diff --git a/compiler/src/expression/relational/eq.rs b/compiler/src/expression/relational/eq.rs index c755b8dc94..766544556f 100644 --- a/compiler/src/expression/relational/eq.rs +++ b/compiler/src/expression/relational/eq.rs @@ -1,4 +1,4 @@ -//! Methods to enforce constraints on `==` comparison expressions in a compiled Leo program. +//! Enforces a relational `==` operator in a resolved Leo program. use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_types::Span; @@ -8,7 +8,7 @@ use snarkos_models::{ gadgets::{r1cs::ConstraintSystem, utilities::eq::EvaluateEqGadget}, }; -pub fn evaluate_eq_expression, CS: ConstraintSystem>( +pub fn evaluate_eq, CS: ConstraintSystem>( cs: &mut CS, left: ConstrainedValue, right: ConstrainedValue, @@ -33,11 +33,11 @@ pub fn evaluate_eq_expression, CS: Constr } (ConstrainedValue::Unresolved(string), val_2) => { let val_1 = ConstrainedValue::from_other(string, &val_2, span.clone())?; - return evaluate_eq_expression(&mut unique_namespace, val_1, val_2, span); + return evaluate_eq(&mut unique_namespace, val_1, val_2, span); } (val_1, ConstrainedValue::Unresolved(string)) => { let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?; - return evaluate_eq_expression(&mut unique_namespace, val_1, val_2, span); + return evaluate_eq(&mut unique_namespace, val_1, val_2, span); } (val_1, val_2) => { return Err(ExpressionError::incompatible_types( diff --git a/compiler/src/expression/relational/ge.rs b/compiler/src/expression/relational/ge.rs index b7c329a957..f2628a932b 100644 --- a/compiler/src/expression/relational/ge.rs +++ b/compiler/src/expression/relational/ge.rs @@ -1,4 +1,4 @@ -//! Methods to enforce constraints on `>=` comparison expressions in a compiled Leo program. +//! Enforces a relational `>=` operator in a resolved Leo program. use crate::{comparator::ComparatorGadget, errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_types::Span; @@ -8,7 +8,7 @@ use snarkos_models::{ gadgets::r1cs::ConstraintSystem, }; -pub fn evaluate_ge_expression, CS: ConstraintSystem>( +pub fn evaluate_ge, CS: ConstraintSystem>( cs: &mut CS, left: ConstrainedValue, right: ConstrainedValue, @@ -24,11 +24,11 @@ pub fn evaluate_ge_expression, CS: Constr } (ConstrainedValue::Unresolved(string), val_2) => { let val_1 = ConstrainedValue::from_other(string, &val_2, span.clone())?; - return evaluate_ge_expression(&mut unique_namespace, val_1, val_2, span); + return evaluate_ge(&mut unique_namespace, val_1, val_2, span); } (val_1, ConstrainedValue::Unresolved(string)) => { let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?; - return evaluate_ge_expression(&mut unique_namespace, val_1, val_2, span); + return evaluate_ge(&mut unique_namespace, val_1, val_2, span); } (val_1, val_2) => { return Err(ExpressionError::incompatible_types( diff --git a/compiler/src/expression/relational/gt.rs b/compiler/src/expression/relational/gt.rs index adfea7800b..283005f1cf 100644 --- a/compiler/src/expression/relational/gt.rs +++ b/compiler/src/expression/relational/gt.rs @@ -1,4 +1,4 @@ -//! Methods to enforce constraints on `>` comparison expressions in a compiled Leo program. +//! Enforces a relational `>` operator in a resolved Leo program. use crate::{comparator::ComparatorGadget, errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_types::Span; @@ -8,7 +8,7 @@ use snarkos_models::{ gadgets::r1cs::ConstraintSystem, }; -pub fn evaluate_gt_expression, CS: ConstraintSystem>( +pub fn evaluate_gt, CS: ConstraintSystem>( cs: &mut CS, left: ConstrainedValue, right: ConstrainedValue, @@ -24,11 +24,11 @@ pub fn evaluate_gt_expression, CS: Constr } (ConstrainedValue::Unresolved(string), val_2) => { let val_1 = ConstrainedValue::from_other(string, &val_2, span.clone())?; - return evaluate_gt_expression(&mut unique_namespace, val_1, val_2, span); + return evaluate_gt(&mut unique_namespace, val_1, val_2, span); } (val_1, ConstrainedValue::Unresolved(string)) => { let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?; - return evaluate_gt_expression(&mut unique_namespace, val_1, val_2, span); + return evaluate_gt(&mut unique_namespace, val_1, val_2, span); } (val_1, val_2) => { return Err(ExpressionError::incompatible_types( diff --git a/compiler/src/expression/relational/le.rs b/compiler/src/expression/relational/le.rs index 835a7744b5..945dae2794 100644 --- a/compiler/src/expression/relational/le.rs +++ b/compiler/src/expression/relational/le.rs @@ -1,4 +1,4 @@ -//! Methods to enforce constraints on `<=` comparison expressions in a compiled Leo program. +//! Enforces a relational `<=` operator in a resolved Leo program. use crate::{comparator::ComparatorGadget, errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_types::Span; @@ -8,7 +8,7 @@ use snarkos_models::{ gadgets::r1cs::ConstraintSystem, }; -pub fn evaluate_le_expression, CS: ConstraintSystem>( +pub fn evaluate_le, CS: ConstraintSystem>( cs: &mut CS, left: ConstrainedValue, right: ConstrainedValue, @@ -24,11 +24,11 @@ pub fn evaluate_le_expression, CS: Constr } (ConstrainedValue::Unresolved(string), val_2) => { let val_1 = ConstrainedValue::from_other(string, &val_2, span.clone())?; - return evaluate_le_expression(&mut unique_namespace, val_1, val_2, span); + return evaluate_le(&mut unique_namespace, val_1, val_2, span); } (val_1, ConstrainedValue::Unresolved(string)) => { let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?; - return evaluate_le_expression(&mut unique_namespace, val_1, val_2, span); + return evaluate_le(&mut unique_namespace, val_1, val_2, span); } (val_1, val_2) => { return Err(ExpressionError::incompatible_types( diff --git a/compiler/src/expression/relational/lt.rs b/compiler/src/expression/relational/lt.rs index 356f22d745..1b8f94a2c0 100644 --- a/compiler/src/expression/relational/lt.rs +++ b/compiler/src/expression/relational/lt.rs @@ -1,4 +1,4 @@ -//! Methods to enforce constraints on `<` comparison expressions in a compiled Leo program. +//! Enforces a relational `<` operator in a resolved Leo program. use crate::{comparator::EvaluateLtGadget, errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_types::Span; @@ -8,7 +8,7 @@ use snarkos_models::{ gadgets::r1cs::ConstraintSystem, }; -pub fn evaluate_lt_expression, CS: ConstraintSystem>( +pub fn evaluate_lt, CS: ConstraintSystem>( cs: &mut CS, left: ConstrainedValue, right: ConstrainedValue, @@ -24,11 +24,11 @@ pub fn evaluate_lt_expression, CS: Constr } (ConstrainedValue::Unresolved(string), val_2) => { let val_1 = ConstrainedValue::from_other(string, &val_2, span.clone())?; - return evaluate_lt_expression(&mut unique_namespace, val_1, val_2, span); + return evaluate_lt(&mut unique_namespace, val_1, val_2, span); } (val_1, ConstrainedValue::Unresolved(string)) => { let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?; - return evaluate_lt_expression(&mut unique_namespace, val_1, val_2, span); + return evaluate_lt(&mut unique_namespace, val_1, val_2, span); } (val_1, val_2) => { return Err(ExpressionError::incompatible_types( diff --git a/compiler/src/value/implicit/implicit.rs b/compiler/src/value/implicit/implicit.rs new file mode 100644 index 0000000000..b626d85e93 --- /dev/null +++ b/compiler/src/value/implicit/implicit.rs @@ -0,0 +1,18 @@ +//! Enforces constraints on an implicit number in a compiled Leo program. + +use crate::{errors::ValueError, value::ConstrainedValue, GroupType}; +use leo_types::{Span, Type}; + +use snarkos_models::curves::{Field, PrimeField}; + +pub fn enforce_number_implicit>( + expected_types: &Vec, + value: String, + span: Span, +) -> Result, ValueError> { + if expected_types.len() == 1 { + return Ok(ConstrainedValue::from_type(value, &expected_types[0], span)?); + } + + Ok(ConstrainedValue::Unresolved(value)) +} diff --git a/compiler/src/value/implicit/mod.rs b/compiler/src/value/implicit/mod.rs new file mode 100644 index 0000000000..59fbd36610 --- /dev/null +++ b/compiler/src/value/implicit/mod.rs @@ -0,0 +1,2 @@ +pub mod implicit; +pub use self::implicit::*; diff --git a/compiler/src/value/mod.rs b/compiler/src/value/mod.rs index aa41621c84..095f164bff 100644 --- a/compiler/src/value/mod.rs +++ b/compiler/src/value/mod.rs @@ -13,6 +13,9 @@ pub use self::field::*; pub mod group; pub use self::group::*; +pub mod implicit; +pub use self::implicit::*; + pub mod integer; pub use self::integer::*;