remove unused assign code

This commit is contained in:
Protryon 2020-12-12 04:49:05 -08:00
parent d1276bd95d
commit 6bb3437280
4 changed files with 0 additions and 284 deletions

View File

@ -1,105 +0,0 @@
// Copyright (C) 2019-2020 Aleo Systems Inc.
// This file is part of the Leo library.
// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
//! Enforces an array assignment statement in a compiled Leo program.
use crate::{errors::StatementError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
use leo_ast::{RangeOrExpression, Span};
use snarkos_models::{
curves::{Field, PrimeField},
gadgets::{
r1cs::ConstraintSystem,
utilities::{boolean::Boolean, select::CondSelectGadget},
},
};
impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
#[allow(clippy::too_many_arguments)]
pub fn assign_array<CS: ConstraintSystem<F>>(
&mut self,
cs: &mut CS,
file_scope: &str,
function_scope: &str,
indicator: &Boolean,
name: &str,
range_or_expression: RangeOrExpression,
mut new_value: ConstrainedValue<F, G>,
span: &Span,
) -> Result<(), StatementError> {
// Resolve index so we know if we are assigning to a single value or a range of values
match range_or_expression {
RangeOrExpression::Expression(index) => {
let index = self.enforce_index(cs, file_scope, function_scope, index, span)?;
// Modify the single value of the array in place
match self.get_mutable_assignee(name, &span)? {
ConstrainedValue::Array(old) => {
new_value.resolve_type(Some(old[index].to_type(&span)?), &span)?;
let selected_value = ConstrainedValue::conditionally_select(
cs.ns(|| format!("select {} {}:{}", new_value, span.line, span.start)),
indicator,
&new_value,
&old[index],
)
.map_err(|_| {
StatementError::select_fail(new_value.to_string(), old[index].to_string(), span.to_owned())
})?;
old[index] = selected_value;
}
_ => return Err(StatementError::array_assign_index(span.to_owned())),
}
}
RangeOrExpression::Range(from, to) => {
let from_index = match from {
Some(integer) => self.enforce_index(cs, file_scope, function_scope, integer, span)?,
None => 0usize,
};
let to_index_option = match to {
Some(integer) => Some(self.enforce_index(cs, file_scope, function_scope, integer, span)?),
None => None,
};
// Modify the range of values of the array
let old_array = self.get_mutable_assignee(name, &span)?;
let new_array = match (old_array.clone(), new_value) {
(ConstrainedValue::Array(mut mutable), ConstrainedValue::Array(new)) => {
let to_index = to_index_option.unwrap_or(mutable.len());
mutable.splice(from_index..to_index, new.iter().cloned());
ConstrainedValue::Array(mutable)
}
_ => return Err(StatementError::array_assign_range(span.to_owned())),
};
let selected_array = ConstrainedValue::conditionally_select(
cs.ns(|| format!("select {} {}:{}", new_array, span.line, span.start)),
indicator,
&new_array,
old_array,
)
.map_err(|_| {
StatementError::select_fail(new_array.to_string(), old_array.to_string(), span.to_owned())
})?;
*old_array = selected_array;
}
}
Ok(())
}
}

View File

@ -1,105 +0,0 @@
// Copyright (C) 2019-2020 Aleo Systems Inc.
// This file is part of the Leo library.
// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
//! Enforces a circuit variable assignment statement in a compiled Leo program.
use crate::{errors::StatementError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
use leo_ast::{Identifier, Span};
use snarkos_models::{
curves::{Field, PrimeField},
gadgets::{
r1cs::ConstraintSystem,
utilities::{boolean::Boolean, select::CondSelectGadget},
},
};
impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
pub fn mutate_circuit_variable<CS: ConstraintSystem<F>>(
&mut self,
cs: &mut CS,
indicator: &Boolean,
circuit_name: &str,
variable_name: Identifier,
mut new_value: ConstrainedValue<F, G>,
span: &Span,
) -> Result<ConstrainedValue<F, G>, StatementError> {
// Get the mutable circuit by name
match self.get_mutable_assignee(circuit_name, span)? {
ConstrainedValue::CircuitExpression(_variable, members) => {
// Modify the circuit variable in place
let matched_variable = members.iter_mut().find(|member| member.0 == variable_name);
match matched_variable {
Some(member) => match &member.1 {
ConstrainedValue::Function(_circuit_identifier, function) => {
// Throw an error if we try to mutate a circuit function
Err(StatementError::immutable_circuit_function(
function.identifier.to_string(),
span.to_owned(),
))
}
ConstrainedValue::Static(_circuit_function) => {
// Throw an error if we try to mutate a static circuit function
Err(StatementError::immutable_circuit_function(
"static".into(),
span.to_owned(),
))
}
value => {
// Check that the new value type == old value type
new_value.resolve_type(Some(value.to_type(span)?), span)?;
// Conditionally select the value if this branch is executed.
let mut selected_value = ConstrainedValue::conditionally_select(
cs.ns(|| format!("select {} {}:{}", new_value, span.line, span.start)),
indicator,
&new_value,
&member.1,
)
.map_err(|_| {
StatementError::select_fail(
new_value.to_string(),
member.1.to_string(),
span.to_owned(),
)
})?;
// Make sure the new value is still mutable
selected_value = ConstrainedValue::Mutable(Box::new(selected_value));
member.1 = selected_value.to_owned();
Ok(selected_value)
}
},
None => {
// Throw an error if the circuit variable does not exist in the circuit
Err(StatementError::undefined_circuit_variable(
variable_name.to_string(),
span.to_owned(),
))
}
}
}
// Throw an error if the circuit definition does not exist in the file
_ => Err(StatementError::undefined_circuit(
variable_name.to_string(),
span.to_owned(),
)),
}
}
}

View File

@ -16,17 +16,8 @@
//! Methods to enforce constraints on assign statements in a compiled Leo program. //! Methods to enforce constraints on assign statements in a compiled Leo program.
pub mod array;
pub use self::array::*;
pub mod assign; pub mod assign;
pub use self::assign::*; pub use self::assign::*;
pub mod assignee; pub mod assignee;
pub use self::assignee::*; pub use self::assignee::*;
pub mod circuit_variable;
pub use self::circuit_variable::*;
pub mod tuple;
pub use self::tuple::*;

View File

@ -1,65 +0,0 @@
// Copyright (C) 2019-2020 Aleo Systems Inc.
// This file is part of the Leo library.
// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
//! Enforces a tuple assignment statement in a compiled Leo program.
use crate::{errors::StatementError, parse_index, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
use leo_ast::{PositiveNumber, Span};
use snarkos_models::{
curves::{Field, PrimeField},
gadgets::{
r1cs::ConstraintSystem,
utilities::{boolean::Boolean, select::CondSelectGadget},
},
};
impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
pub fn assign_tuple<CS: ConstraintSystem<F>>(
&mut self,
cs: &mut CS,
indicator: &Boolean,
name: &str,
index: PositiveNumber,
mut new_value: ConstrainedValue<F, G>,
span: &Span,
) -> Result<(), StatementError> {
// Parse the index.
let index_usize = parse_index(&index, &span)?;
// Modify the single value of the tuple in place
match self.get_mutable_assignee(name, &span)? {
ConstrainedValue::Tuple(old) => {
new_value.resolve_type(Some(old[index_usize].to_type(&span)?), &span)?;
let selected_value = ConstrainedValue::conditionally_select(
cs.ns(|| format!("select {} {}:{}", new_value, span.line, span.start)),
indicator,
&new_value,
&old[index_usize],
)
.map_err(|_| {
StatementError::select_fail(new_value.to_string(), old[index_usize].to_string(), span.to_owned())
})?;
old[index_usize] = selected_value;
}
_ => return Err(StatementError::tuple_assign_index(span.to_owned())),
}
Ok(())
}
}