deprecate new_variable methods

This commit is contained in:
collin 2020-05-19 12:04:01 -07:00
parent a9a8cb95c6
commit 1c733b5dd9
3 changed files with 7 additions and 38 deletions

View File

@ -1,9 +1,7 @@
//! Methods to enforce constraints on expressions in a resolved Leo program.
use crate::{
constraints::{
new_scope_from_variable, ConstrainedCircuitMember, ConstrainedProgram, ConstrainedValue,
},
constraints::{ConstrainedCircuitMember, ConstrainedProgram, ConstrainedValue},
errors::ExpressionError,
new_scope,
types::{
@ -411,8 +409,8 @@ impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgra
for element in array.into_iter() {
match *element {
SpreadOrExpression::Spread(spread) => match spread {
Expression::Identifier(variable) => {
let array_name = new_scope_from_variable(function_scope.clone(), &variable);
Expression::Identifier(identifier) => {
let array_name = new_scope(function_scope.clone(), identifier.to_string());
match self.get(&array_name) {
Some(value) => match value {
ConstrainedValue::Array(array) => result.extend(array.clone()),
@ -420,7 +418,7 @@ impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgra
return Err(ExpressionError::InvalidSpread(value.to_string()));
}
},
None => return Err(ExpressionError::UndefinedArray(variable.name)),
None => return Err(ExpressionError::UndefinedArray(identifier.name)),
}
}
value => return Err(ExpressionError::InvalidSpread(value.to_string())),

View File

@ -17,35 +17,6 @@ pub fn new_scope(outer: String, inner: String) -> String {
format!("{}_{}", outer, inner)
}
pub fn new_scope_from_variable<F: Field + PrimeField, G: Group>(
outer: String,
inner: &Identifier<F, G>,
) -> String {
new_scope(outer, inner.name.clone())
}
pub fn new_variable_from_variable<F: Field + PrimeField, G: Group>(
outer: String,
inner: &Identifier<F, G>,
) -> Identifier<F, G> {
Identifier {
name: new_scope_from_variable(outer, inner),
_engine: PhantomData::<F>,
_group: PhantomData::<G>,
}
}
pub fn new_variable_from_variables<F: Field + PrimeField, G: Group>(
outer: &Identifier<F, G>,
inner: &Identifier<F, G>,
) -> Identifier<F, G> {
Identifier {
name: new_scope_from_variable(outer.name.clone(), inner),
_engine: PhantomData::<F>,
_group: PhantomData::<G>,
}
}
impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgram<F, G, CS> {
pub fn new() -> Self {
Self {

View File

@ -1,7 +1,7 @@
//! Methods to enforce constraints on statements in a resolved Leo program.
use crate::{
constraints::{new_scope_from_variable, ConstrainedProgram, ConstrainedValue},
constraints::{ConstrainedProgram, ConstrainedValue},
errors::StatementError,
new_scope,
types::{
@ -19,7 +19,7 @@ use snarkos_models::{
impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgram<F, G, CS> {
fn resolve_assignee(&mut self, scope: String, assignee: Assignee<F, G>) -> String {
match assignee {
Assignee::Identifier(name) => new_scope_from_variable(scope, &name),
Assignee::Identifier(name) => new_scope(scope, name.to_string()),
Assignee::Array(array, _index) => self.resolve_assignee(scope, *array),
Assignee::CircuitField(circuit_name, _member) => {
self.resolve_assignee(scope, *circuit_name)
@ -378,7 +378,7 @@ impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgra
for i in start.to_usize()..stop.to_usize() {
// Store index in current function scope.
// For loop scope is not implemented.
let index_name = new_scope_from_variable(function_scope.clone(), &index);
let index_name = new_scope(function_scope.clone(), index.to_string());
self.store(
index_name,
ConstrainedValue::Integer(Integer::U32(UInt32::constant(i as u32))),