mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-26 11:45:00 +03:00
clippy: fix redundant_clone & clone_on_copy
Signed-off-by: ljedrz <ljedrz@gmail.com>
This commit is contained in:
parent
93369aed33
commit
1fc9b902dd
@ -53,7 +53,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
// Unwrap assertion value and handle errors
|
// Unwrap assertion value and handle errors
|
||||||
let result_option = match assert_expression {
|
let result_option = match assert_expression {
|
||||||
ConstrainedValue::Boolean(boolean) => boolean.get_value(),
|
ConstrainedValue::Boolean(boolean) => boolean.get_value(),
|
||||||
_ => return Err(ConsoleError::assertion_must_be_boolean(expression_string, span.clone())),
|
_ => return Err(ConsoleError::assertion_must_be_boolean(expression_string, span)),
|
||||||
};
|
};
|
||||||
let result_bool = result_option.ok_or(ConsoleError::assertion_depends_on_input(span.clone()))?;
|
let result_bool = result_option.ok_or(ConsoleError::assertion_depends_on_input(span.clone()))?;
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
return Err(ConsoleError::length(
|
return Err(ConsoleError::length(
|
||||||
formatted.containers.len(),
|
formatted.containers.len(),
|
||||||
formatted.parameters.len(),
|
formatted.parameters.len(),
|
||||||
formatted.span.clone(),
|
formatted.span,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
};
|
};
|
||||||
let to_resolved = match to {
|
let to_resolved = match to {
|
||||||
Some(to_index) => {
|
Some(to_index) => {
|
||||||
self.enforce_index(cs, file_scope.clone(), function_scope.clone(), to_index, span.clone())?
|
self.enforce_index(cs, file_scope, function_scope, to_index, span)?
|
||||||
}
|
}
|
||||||
None => array.len(), // Array slice ends at array length
|
None => array.len(), // Array slice ends at array length
|
||||||
};
|
};
|
||||||
|
@ -47,12 +47,12 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
match type_ {
|
match type_ {
|
||||||
Type::Array(ref type_, ref dimensions) => {
|
Type::Array(ref type_, ref dimensions) => {
|
||||||
let number = match dimensions.first() {
|
let number = match dimensions.first() {
|
||||||
Some(number) => number.clone(),
|
Some(number) => *number,
|
||||||
None => return Err(ExpressionError::unexpected_array(type_.to_string(), span)),
|
None => return Err(ExpressionError::unexpected_array(type_.to_string(), span)),
|
||||||
};
|
};
|
||||||
|
|
||||||
expected_dimensions.push(number);
|
expected_dimensions.push(number);
|
||||||
expected_type = Some(type_.outer_dimension(dimensions).clone());
|
expected_type = Some(type_.outer_dimension(dimensions));
|
||||||
}
|
}
|
||||||
ref type_ => {
|
ref type_ => {
|
||||||
return Err(ExpressionError::unexpected_array(type_.to_string(), span));
|
return Err(ExpressionError::unexpected_array(type_.to_string(), span));
|
||||||
|
@ -36,13 +36,13 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
let expected_type = Some(Type::IntegerType(IntegerType::U32));
|
let expected_type = Some(Type::IntegerType(IntegerType::U32));
|
||||||
match self.enforce_operand(
|
match self.enforce_operand(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope,
|
||||||
expected_type,
|
expected_type,
|
||||||
index,
|
index,
|
||||||
span.clone(),
|
span.clone(),
|
||||||
)? {
|
)? {
|
||||||
ConstrainedValue::Integer(number) => Ok(number.to_usize(span.clone())?),
|
ConstrainedValue::Integer(number) => Ok(number.to_usize(span)?),
|
||||||
value => Err(ExpressionError::invalid_index(value.to_string(), span)),
|
value => Err(ExpressionError::invalid_index(value.to_string(), span)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,8 +45,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
)?;
|
)?;
|
||||||
let mut resolved_right = self.enforce_operand(
|
let mut resolved_right = self.enforce_operand(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope,
|
||||||
expected_type.clone(),
|
expected_type.clone(),
|
||||||
right,
|
right,
|
||||||
span.clone(),
|
span.clone(),
|
||||||
|
@ -45,11 +45,11 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
// access a circuit member using the `self` keyword
|
// access a circuit member using the `self` keyword
|
||||||
if let Expression::Identifier(ref identifier) = *circuit_identifier {
|
if let Expression::Identifier(ref identifier) = *circuit_identifier {
|
||||||
if identifier.is_self() {
|
if identifier.is_self() {
|
||||||
let self_file_scope = new_scope(file_scope.clone(), identifier.name.to_string());
|
let self_file_scope = new_scope(file_scope, identifier.name.to_string());
|
||||||
let self_function_scope = new_scope(self_file_scope.clone(), identifier.name.to_string());
|
let self_function_scope = new_scope(self_file_scope.clone(), identifier.name.to_string());
|
||||||
|
|
||||||
let member_value =
|
let member_value =
|
||||||
self.evaluate_identifier(self_file_scope, self_function_scope, None, circuit_member.clone())?;
|
self.evaluate_identifier(self_file_scope, self_function_scope, None, circuit_member)?;
|
||||||
|
|
||||||
return Ok(member_value);
|
return Ok(member_value);
|
||||||
}
|
}
|
||||||
@ -58,9 +58,9 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
let (circuit_name, members) = match self.enforce_operand(
|
let (circuit_name, members) = match self.enforce_operand(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope.clone(),
|
||||||
function_scope.clone(),
|
function_scope,
|
||||||
expected_type,
|
expected_type,
|
||||||
*circuit_identifier.clone(),
|
*circuit_identifier,
|
||||||
span.clone(),
|
span.clone(),
|
||||||
)? {
|
)? {
|
||||||
ConstrainedValue::CircuitExpression(name, members) => (name, members),
|
ConstrainedValue::CircuitExpression(name, members) => (name, members),
|
||||||
|
@ -55,7 +55,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
let circuit_identifier = circuit.circuit_name.clone();
|
let circuit_identifier = circuit.circuit_name.clone();
|
||||||
let mut resolved_members = vec![];
|
let mut resolved_members = vec![];
|
||||||
|
|
||||||
for member in circuit.members.clone().into_iter() {
|
for member in circuit.members.into_iter() {
|
||||||
match member {
|
match member {
|
||||||
CircuitMember::CircuitVariable(is_mutable, identifier, type_) => {
|
CircuitMember::CircuitVariable(is_mutable, identifier, type_) => {
|
||||||
let matched_variable = members
|
let matched_variable = members
|
||||||
@ -98,7 +98,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(ConstrainedValue::CircuitExpression(
|
Ok(ConstrainedValue::CircuitExpression(
|
||||||
circuit_identifier.clone(),
|
circuit_identifier,
|
||||||
resolved_members,
|
resolved_members,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -36,23 +36,23 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
span: Span,
|
span: Span,
|
||||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||||
// Get defined circuit
|
// Get defined circuit
|
||||||
let circuit = match *circuit_identifier.clone() {
|
let circuit = match *circuit_identifier {
|
||||||
Expression::Identifier(identifier) => {
|
Expression::Identifier(identifier) => {
|
||||||
// Use the "Self" keyword to access a static circuit function
|
// Use the "Self" keyword to access a static circuit function
|
||||||
if identifier.is_self() {
|
if identifier.is_self() {
|
||||||
let circuit = self
|
let circuit = self
|
||||||
.get(&file_scope)
|
.get(&file_scope)
|
||||||
.ok_or(ExpressionError::self_keyword(identifier.span.clone()))?;
|
.ok_or(ExpressionError::self_keyword(identifier.span))?;
|
||||||
|
|
||||||
circuit.to_owned()
|
circuit.to_owned()
|
||||||
} else {
|
} else {
|
||||||
self.evaluate_identifier(file_scope.clone(), function_scope.clone(), expected_type, identifier)?
|
self.evaluate_identifier(file_scope, function_scope, expected_type, identifier)?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expression => self.enforce_expression(
|
expression => self.enforce_expression(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope,
|
||||||
expected_type,
|
expected_type,
|
||||||
expression,
|
expression,
|
||||||
)?,
|
)?,
|
||||||
|
@ -59,8 +59,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
|
|
||||||
let second_value = self.enforce_operand(
|
let second_value = self.enforce_operand(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope,
|
||||||
expected_type,
|
expected_type,
|
||||||
second,
|
second,
|
||||||
span.clone(),
|
span.clone(),
|
||||||
|
@ -70,8 +70,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
Expression::Add(left, right, span) => {
|
Expression::Add(left, right, span) => {
|
||||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope,
|
||||||
expected_type,
|
expected_type,
|
||||||
*left,
|
*left,
|
||||||
*right,
|
*right,
|
||||||
@ -83,8 +83,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
Expression::Sub(left, right, span) => {
|
Expression::Sub(left, right, span) => {
|
||||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope,
|
||||||
expected_type,
|
expected_type,
|
||||||
*left,
|
*left,
|
||||||
*right,
|
*right,
|
||||||
@ -96,8 +96,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
Expression::Mul(left, right, span) => {
|
Expression::Mul(left, right, span) => {
|
||||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope,
|
||||||
expected_type,
|
expected_type,
|
||||||
*left,
|
*left,
|
||||||
*right,
|
*right,
|
||||||
@ -109,8 +109,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
Expression::Div(left, right, span) => {
|
Expression::Div(left, right, span) => {
|
||||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope,
|
||||||
expected_type,
|
expected_type,
|
||||||
*left,
|
*left,
|
||||||
*right,
|
*right,
|
||||||
@ -122,8 +122,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
Expression::Pow(left, right, span) => {
|
Expression::Pow(left, right, span) => {
|
||||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope,
|
||||||
expected_type,
|
expected_type,
|
||||||
*left,
|
*left,
|
||||||
*right,
|
*right,
|
||||||
@ -141,8 +141,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
Expression::Or(left, right, span) => {
|
Expression::Or(left, right, span) => {
|
||||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope,
|
||||||
expected_type,
|
expected_type,
|
||||||
*left,
|
*left,
|
||||||
*right,
|
*right,
|
||||||
@ -154,8 +154,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
Expression::And(left, right, span) => {
|
Expression::And(left, right, span) => {
|
||||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope,
|
||||||
expected_type,
|
expected_type,
|
||||||
*left,
|
*left,
|
||||||
*right,
|
*right,
|
||||||
@ -167,8 +167,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
Expression::Eq(left, right, span) => {
|
Expression::Eq(left, right, span) => {
|
||||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope,
|
||||||
None,
|
None,
|
||||||
*left,
|
*left,
|
||||||
*right,
|
*right,
|
||||||
@ -180,8 +180,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
Expression::Ge(left, right, span) => {
|
Expression::Ge(left, right, span) => {
|
||||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope,
|
||||||
None,
|
None,
|
||||||
*left,
|
*left,
|
||||||
*right,
|
*right,
|
||||||
@ -193,8 +193,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
Expression::Gt(left, right, span) => {
|
Expression::Gt(left, right, span) => {
|
||||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope,
|
||||||
None,
|
None,
|
||||||
*left,
|
*left,
|
||||||
*right,
|
*right,
|
||||||
@ -206,8 +206,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
Expression::Le(left, right, span) => {
|
Expression::Le(left, right, span) => {
|
||||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope,
|
||||||
None,
|
None,
|
||||||
*left,
|
*left,
|
||||||
*right,
|
*right,
|
||||||
@ -219,8 +219,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
Expression::Lt(left, right, span) => {
|
Expression::Lt(left, right, span) => {
|
||||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope,
|
||||||
None,
|
None,
|
||||||
*left,
|
*left,
|
||||||
*right,
|
*right,
|
||||||
|
@ -35,7 +35,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
arguments: Vec<Expression>,
|
arguments: Vec<Expression>,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||||
let (declared_circuit_reference, function_value) = match *function.clone() {
|
let (declared_circuit_reference, function_value) = match *function {
|
||||||
Expression::CircuitMemberAccess(circuit_identifier, circuit_member, span) => {
|
Expression::CircuitMemberAccess(circuit_identifier, circuit_member, span) => {
|
||||||
// Call a circuit function that can mutate self.
|
// Call a circuit function that can mutate self.
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
let (outer_scope, function_call) = function_value.extract_function(file_scope.clone(), span.clone())?;
|
let (outer_scope, function_call) = function_value.extract_function(file_scope, span.clone())?;
|
||||||
|
|
||||||
let name_unique = format!(
|
let name_unique = format!(
|
||||||
"function call {} {}:{}",
|
"function call {} {}:{}",
|
||||||
|
@ -37,7 +37,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
unresolved_identifier: Identifier,
|
unresolved_identifier: Identifier,
|
||||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||||
// Evaluate the identifier name in the current function scope
|
// Evaluate the identifier name in the current function scope
|
||||||
let variable_name = new_scope(function_scope.clone(), unresolved_identifier.to_string());
|
let variable_name = new_scope(function_scope, unresolved_identifier.to_string());
|
||||||
let identifier_name = new_scope(file_scope, unresolved_identifier.to_string());
|
let identifier_name = new_scope(file_scope, unresolved_identifier.to_string());
|
||||||
|
|
||||||
let mut result_value = if let Some(value) = self.get(&variable_name) {
|
let mut result_value = if let Some(value) = self.get(&variable_name) {
|
||||||
@ -58,7 +58,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
return Err(ExpressionError::undefined_identifier(unresolved_identifier));
|
return Err(ExpressionError::undefined_identifier(unresolved_identifier));
|
||||||
};
|
};
|
||||||
|
|
||||||
result_value.resolve_type(expected_type, unresolved_identifier.span.clone())?;
|
result_value.resolve_type(expected_type, unresolved_identifier.span)?;
|
||||||
|
|
||||||
Ok(result_value)
|
Ok(result_value)
|
||||||
}
|
}
|
||||||
|
@ -37,14 +37,14 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||||
let tuple = match self.enforce_operand(
|
let tuple = match self.enforce_operand(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope,
|
||||||
expected_type,
|
expected_type,
|
||||||
*tuple,
|
*tuple,
|
||||||
span.clone(),
|
span.clone(),
|
||||||
)? {
|
)? {
|
||||||
ConstrainedValue::Tuple(tuple) => tuple,
|
ConstrainedValue::Tuple(tuple) => tuple,
|
||||||
value => return Err(ExpressionError::undefined_array(value.to_string(), span.clone())),
|
value => return Err(ExpressionError::undefined_array(value.to_string(), span)),
|
||||||
};
|
};
|
||||||
|
|
||||||
if index > tuple.len() - 1 {
|
if index > tuple.len() - 1 {
|
||||||
|
@ -55,7 +55,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
check_arguments_length(function.input.len(), input.len(), function.span.clone())?;
|
check_arguments_length(function.input.len(), input.len(), function.span.clone())?;
|
||||||
|
|
||||||
// Store input values as new variables in resolved program
|
// Store input values as new variables in resolved program
|
||||||
for (input_model, input_expression) in function.input.clone().iter().zip(input.into_iter()) {
|
for (input_model, input_expression) in function.input.iter().zip(input.into_iter()) {
|
||||||
let (name, value) = match input_model {
|
let (name, value) = match input_model {
|
||||||
InputVariable::InputKeyword(identifier) => {
|
InputVariable::InputKeyword(identifier) => {
|
||||||
let input_value = self.enforce_function_input(
|
let input_value = self.enforce_function_input(
|
||||||
|
@ -30,11 +30,10 @@ fn parse_import_file(entry: &DirEntry, span: &Span) -> Result<Program, ImportErr
|
|||||||
.map_err(|error| ImportError::directory_error(error, span.clone(), entry.path()))?;
|
.map_err(|error| ImportError::directory_error(error, span.clone(), entry.path()))?;
|
||||||
let file_name = entry
|
let file_name = entry
|
||||||
.file_name()
|
.file_name()
|
||||||
.to_os_string()
|
|
||||||
.into_string()
|
.into_string()
|
||||||
.map_err(|_| ImportError::convert_os_string(span.clone()))?;
|
.map_err(|_| ImportError::convert_os_string(span.clone()))?;
|
||||||
|
|
||||||
let mut file_path = entry.path().to_path_buf();
|
let mut file_path = entry.path();
|
||||||
if file_type.is_dir() {
|
if file_type.is_dir() {
|
||||||
file_path.push(LIBRARY_FILE);
|
file_path.push(LIBRARY_FILE);
|
||||||
|
|
||||||
@ -62,7 +61,7 @@ impl ImportParser {
|
|||||||
.extension()
|
.extension()
|
||||||
.map_or(false, |ext| ext.eq(&OsString::from(FILE_EXTENSION)));
|
.map_or(false, |ext| ext.eq(&OsString::from(FILE_EXTENSION)));
|
||||||
|
|
||||||
let mut package_path = path.to_path_buf();
|
let mut package_path = path;
|
||||||
package_path.push(LIBRARY_FILE);
|
package_path.push(LIBRARY_FILE);
|
||||||
|
|
||||||
let is_package = is_dir && package_path.exists();
|
let is_package = is_dir && package_path.exists();
|
||||||
@ -93,7 +92,7 @@ impl ImportParser {
|
|||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
// importing * from a directory or non-leo file in `package/src/` is illegal
|
// importing * from a directory or non-leo file in `package/src/` is illegal
|
||||||
Err(ImportError::star(entry.path().to_path_buf(), span.clone()))
|
Err(ImportError::star(entry.path(), span.clone()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
.find(|package| import.package.eq(package));
|
.find(|package| import.package.eq(package));
|
||||||
|
|
||||||
if let Some(package) = core_dependency {
|
if let Some(package) = core_dependency {
|
||||||
self.store_core_package(scope.clone(), package.clone())?;
|
self.store_core_package(scope, package.clone())?;
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
|
|
||||||
let value = match matched_circuit {
|
let value = match matched_circuit {
|
||||||
Some((_circuit_name, circuit)) => ConstrainedValue::Import(
|
Some((_circuit_name, circuit)) => ConstrainedValue::Import(
|
||||||
program_name.clone(),
|
program_name,
|
||||||
Box::new(ConstrainedValue::CircuitDefinition(circuit.clone())),
|
Box::new(ConstrainedValue::CircuitDefinition(circuit.clone())),
|
||||||
),
|
),
|
||||||
None => {
|
None => {
|
||||||
@ -71,7 +71,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
|
|
||||||
match matched_function {
|
match matched_function {
|
||||||
Some((_function_name, function)) => ConstrainedValue::Import(
|
Some((_function_name, function)) => ConstrainedValue::Import(
|
||||||
program_name.clone(),
|
program_name,
|
||||||
Box::new(ConstrainedValue::Function(None, function.clone())),
|
Box::new(ConstrainedValue::Function(None, function.clone())),
|
||||||
),
|
),
|
||||||
None => return Err(ImportError::unknown_symbol(symbol.to_owned(), program_name)),
|
None => return Err(ImportError::unknown_symbol(symbol.to_owned(), program_name)),
|
||||||
|
@ -44,7 +44,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
// Resolve index so we know if we are assigning to a single value or a range of values
|
// Resolve index so we know if we are assigning to a single value or a range of values
|
||||||
match range_or_expression {
|
match range_or_expression {
|
||||||
RangeOrExpression::Expression(index) => {
|
RangeOrExpression::Expression(index) => {
|
||||||
let index = self.enforce_index(cs, file_scope.clone(), function_scope.clone(), index, span.clone())?;
|
let index = self.enforce_index(cs, file_scope, function_scope, index, span.clone())?;
|
||||||
|
|
||||||
// Modify the single value of the array in place
|
// Modify the single value of the array in place
|
||||||
match self.get_mutable_assignee(name, span.clone())? {
|
match self.get_mutable_assignee(name, span.clone())? {
|
||||||
@ -77,8 +77,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
let to_index_option = match to {
|
let to_index_option = match to {
|
||||||
Some(integer) => Some(self.enforce_index(
|
Some(integer) => Some(self.enforce_index(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope,
|
||||||
integer,
|
integer,
|
||||||
span.clone(),
|
span.clone(),
|
||||||
)?),
|
)?),
|
||||||
|
@ -57,7 +57,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
match assignee {
|
match assignee {
|
||||||
Assignee::Identifier(_identifier) => {
|
Assignee::Identifier(_identifier) => {
|
||||||
let condition = indicator.unwrap_or(Boolean::Constant(true));
|
let condition = indicator.unwrap_or(Boolean::Constant(true));
|
||||||
let old_value = self.get_mutable_assignee(variable_name.clone(), span.clone())?;
|
let old_value = self.get_mutable_assignee(variable_name, span.clone())?;
|
||||||
|
|
||||||
new_value.resolve_type(Some(old_value.to_type(span.clone())?), span.clone())?;
|
new_value.resolve_type(Some(old_value.to_type(span.clone())?), span.clone())?;
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
|
|
||||||
member.1 = selected_value.to_owned();
|
member.1 = selected_value.to_owned();
|
||||||
|
|
||||||
Ok(selected_value.to_owned())
|
Ok(selected_value)
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// Throw an error if we try to mutate an immutable circuit variable
|
// Throw an error if we try to mutate an immutable circuit variable
|
||||||
|
@ -41,7 +41,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope.clone(),
|
||||||
function_scope.clone(),
|
function_scope.clone(),
|
||||||
indicator.clone(),
|
indicator,
|
||||||
statement.clone(),
|
statement.clone(),
|
||||||
return_type.clone(),
|
return_type.clone(),
|
||||||
"".to_owned(),
|
"".to_owned(),
|
||||||
|
@ -56,7 +56,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
) -> Result<Vec<ConstrainedValue<F, G>>, StatementError> {
|
) -> Result<Vec<ConstrainedValue<F, G>>, StatementError> {
|
||||||
let types = match type_ {
|
let types = match type_ {
|
||||||
Some(Type::Tuple(types)) => types,
|
Some(Type::Tuple(types)) => types,
|
||||||
Some(type_) => return Err(StatementError::tuple_type(type_.to_string(), span.clone())),
|
Some(type_) => return Err(StatementError::tuple_type(type_.to_string(), span)),
|
||||||
None => vec![],
|
None => vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
let variable = variables.names[0].clone();
|
let variable = variables.names[0].clone();
|
||||||
let expression = self.enforce_expression(
|
let expression = self.enforce_expression(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope.clone(),
|
||||||
variables.type_,
|
variables.type_,
|
||||||
expressions[0].clone(),
|
expressions[0].clone(),
|
||||||
@ -181,14 +181,14 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
|
|
||||||
let values = match self.enforce_expression(
|
let values = match self.enforce_expression(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope.clone(),
|
||||||
variables.type_.clone(),
|
variables.type_.clone(),
|
||||||
expressions[0].clone(),
|
expressions[0].clone(),
|
||||||
)? {
|
)? {
|
||||||
// ConstrainedValue::Return(values) => values,
|
// ConstrainedValue::Return(values) => values,
|
||||||
ConstrainedValue::Tuple(values) => values,
|
ConstrainedValue::Tuple(values) => values,
|
||||||
value => return Err(StatementError::multiple_definition(value.to_string(), span.clone())),
|
value => return Err(StatementError::multiple_definition(value.to_string(), span)),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.enforce_multiple_definition(cs, function_scope, is_constant, variables, values, span)
|
self.enforce_multiple_definition(cs, function_scope, is_constant, variables, values, span)
|
||||||
|
@ -56,8 +56,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
|
|
||||||
let result = self.enforce_operand(
|
let result = self.enforce_operand(
|
||||||
cs,
|
cs,
|
||||||
file_scope.clone(),
|
file_scope,
|
||||||
function_scope.clone(),
|
function_scope,
|
||||||
return_type.clone(),
|
return_type.clone(),
|
||||||
expression,
|
expression,
|
||||||
span.clone(),
|
span.clone(),
|
||||||
|
@ -205,7 +205,7 @@ impl EdwardsGroupType {
|
|||||||
// Sign inferred
|
// Sign inferred
|
||||||
None => {
|
None => {
|
||||||
// Attempt to recover with a sign_low bit.
|
// Attempt to recover with a sign_low bit.
|
||||||
if let Some(element) = EdwardsAffine::from_x_coordinate(x.clone(), false) {
|
if let Some(element) = EdwardsAffine::from_x_coordinate(x, false) {
|
||||||
return Ok(element);
|
return Ok(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +234,7 @@ impl EdwardsGroupType {
|
|||||||
// Sign inferred
|
// Sign inferred
|
||||||
None => {
|
None => {
|
||||||
// Attempt to recover with a sign_low bit.
|
// Attempt to recover with a sign_low bit.
|
||||||
if let Some(element) = EdwardsAffine::from_y_coordinate(y.clone(), false) {
|
if let Some(element) = EdwardsAffine::from_y_coordinate(y, false) {
|
||||||
return Ok(element);
|
return Ok(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedValue<F, G> {
|
|||||||
|
|
||||||
// Data type wrappers
|
// Data type wrappers
|
||||||
ConstrainedValue::Array(array) => {
|
ConstrainedValue::Array(array) => {
|
||||||
let array_type = array[0].to_type(span.clone())?;
|
let array_type = array[0].to_type(span)?;
|
||||||
let mut dimensions = vec![array.len()];
|
let mut dimensions = vec![array.len()];
|
||||||
|
|
||||||
// Nested array type
|
// Nested array type
|
||||||
@ -205,12 +205,12 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedValue<F, G> {
|
|||||||
// If this is a circuit function, evaluate inside the circuit scope
|
// If this is a circuit function, evaluate inside the circuit scope
|
||||||
if let Some(identifier) = circuit_identifier {
|
if let Some(identifier) = circuit_identifier {
|
||||||
// avoid creating recursive scope
|
// avoid creating recursive scope
|
||||||
if !is_in_scope(&scope, &identifier.name.to_string()) {
|
if !is_in_scope(&scope, &identifier.name) {
|
||||||
outer_scope = new_scope(scope, identifier.name.to_string());
|
outer_scope = new_scope(scope, identifier.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((outer_scope, function.clone()))
|
Ok((outer_scope, function))
|
||||||
}
|
}
|
||||||
ConstrainedValue::Import(import_scope, function) => function.extract_function(import_scope, span),
|
ConstrainedValue::Import(import_scope, function) => function.extract_function(import_scope, span),
|
||||||
value => Err(ExpressionError::undefined_function(value.to_string(), span)),
|
value => Err(ExpressionError::undefined_function(value.to_string(), span)),
|
||||||
|
@ -104,7 +104,7 @@ impl CoreCircuit for Blake2sCircuit {
|
|||||||
),
|
),
|
||||||
span.clone(),
|
span.clone(),
|
||||||
)],
|
)],
|
||||||
span: span.clone(),
|
span,
|
||||||
},
|
},
|
||||||
)],
|
)],
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ impl SignExtend for Boolean {
|
|||||||
fn sign_extend(bits: &[Boolean], length: usize) -> Vec<Boolean> {
|
fn sign_extend(bits: &[Boolean], length: usize) -> Vec<Boolean> {
|
||||||
let msb = bits.last().expect("empty bit list");
|
let msb = bits.last().expect("empty bit list");
|
||||||
let bits_needed = length - bits.len();
|
let bits_needed = length - bits.len();
|
||||||
let mut extension = vec![msb.clone(); bits_needed];
|
let mut extension = vec![*msb; bits_needed];
|
||||||
|
|
||||||
let mut result = Vec::from(bits);
|
let mut result = Vec::from(bits);
|
||||||
result.append(&mut extension);
|
result.append(&mut extension);
|
||||||
|
@ -93,7 +93,7 @@ impl CLI for BuildCommand {
|
|||||||
// Compile the library file but do not output
|
// Compile the library file but do not output
|
||||||
let _program = Compiler::<Fq, EdwardsGroupType>::parse_program_without_input(
|
let _program = Compiler::<Fq, EdwardsGroupType>::parse_program_without_input(
|
||||||
package_name.clone(),
|
package_name.clone(),
|
||||||
lib_file_path.clone(),
|
lib_file_path,
|
||||||
output_directory.clone(),
|
output_directory.clone(),
|
||||||
)?;
|
)?;
|
||||||
tracing::info!("Complete");
|
tracing::info!("Complete");
|
||||||
@ -121,7 +121,7 @@ impl CLI for BuildCommand {
|
|||||||
// Load the program at `main_file_path`
|
// Load the program at `main_file_path`
|
||||||
let program = Compiler::<Fq, EdwardsGroupType>::parse_program_with_input(
|
let program = Compiler::<Fq, EdwardsGroupType>::parse_program_with_input(
|
||||||
package_name.clone(),
|
package_name.clone(),
|
||||||
main_file_path.clone(),
|
main_file_path,
|
||||||
output_directory,
|
output_directory,
|
||||||
&input_string,
|
&input_string,
|
||||||
input_path,
|
input_path,
|
||||||
|
@ -65,7 +65,7 @@ impl CLI for DeployCommand {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let mut main_file_path = path.clone();
|
let mut main_file_path = path;
|
||||||
main_file_path.push(SOURCE_DIRECTORY_NAME);
|
main_file_path.push(SOURCE_DIRECTORY_NAME);
|
||||||
main_file_path.push(MAIN_FILENAME);
|
main_file_path.push(MAIN_FILENAME);
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ impl CLI for LintCommand {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let mut main_file_path = path.clone();
|
let mut main_file_path = path;
|
||||||
main_file_path.push(SOURCE_DIRECTORY_NAME);
|
main_file_path.push(SOURCE_DIRECTORY_NAME);
|
||||||
main_file_path.push(MAIN_FILENAME);
|
main_file_path.push(MAIN_FILENAME);
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ impl CLI for SetupCommand {
|
|||||||
Ok((program, proving_key, prepared_verifying_key))
|
Ok((program, proving_key, prepared_verifying_key))
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let mut main_file_path = path.clone();
|
let mut main_file_path = path;
|
||||||
main_file_path.push(SOURCE_DIRECTORY_NAME);
|
main_file_path.push(SOURCE_DIRECTORY_NAME);
|
||||||
main_file_path.push(MAIN_FILENAME);
|
main_file_path.push(MAIN_FILENAME);
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ impl CLI for TestCommand {
|
|||||||
let package_name = manifest.get_package_name();
|
let package_name = manifest.get_package_name();
|
||||||
|
|
||||||
// Sanitize the package path to the root directory
|
// Sanitize the package path to the root directory
|
||||||
let mut package_path = path.clone();
|
let mut package_path = path;
|
||||||
if package_path.is_file() {
|
if package_path.is_file() {
|
||||||
package_path.pop();
|
package_path.pop();
|
||||||
}
|
}
|
||||||
@ -93,8 +93,8 @@ impl CLI for TestCommand {
|
|||||||
|
|
||||||
// Parse the current main program file
|
// Parse the current main program file
|
||||||
let program = Compiler::<Fq, EdwardsGroupType>::parse_program_without_input(
|
let program = Compiler::<Fq, EdwardsGroupType>::parse_program_without_input(
|
||||||
package_name.clone(),
|
package_name,
|
||||||
file_path.clone(),
|
file_path,
|
||||||
output_directory,
|
output_directory,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ impl CLI for TestCommand {
|
|||||||
let pairs = InputPairs::try_from(&package_path)?;
|
let pairs = InputPairs::try_from(&package_path)?;
|
||||||
|
|
||||||
// Run tests
|
// Run tests
|
||||||
let temporary_program = program.clone();
|
let temporary_program = program;
|
||||||
let (passed, failed) = temporary_program.compile_test_constraints(pairs)?;
|
let (passed, failed) = temporary_program.compile_test_constraints(pairs)?;
|
||||||
|
|
||||||
// Drop "Test" context for console logging
|
// Drop "Test" context for console logging
|
||||||
|
@ -131,7 +131,7 @@ pub fn write_token(token: &str) -> Result<(), io::Error> {
|
|||||||
let config_dir = LEO_CONFIG_DIRECTORY.clone();
|
let config_dir = LEO_CONFIG_DIRECTORY.clone();
|
||||||
|
|
||||||
// Create Leo config directory if it not exists
|
// Create Leo config directory if it not exists
|
||||||
if !Path::new(&config_dir.to_path_buf()).exists() {
|
if !Path::new(&config_dir).exists() {
|
||||||
create_dir_all(&config_dir)?;
|
create_dir_all(&config_dir)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ impl From<Index> for SerializedIndex {
|
|||||||
impl From<&SerializedIndex> for Index {
|
impl From<&SerializedIndex> for Index {
|
||||||
fn from(serialized_index: &SerializedIndex) -> Self {
|
fn from(serialized_index: &SerializedIndex) -> Self {
|
||||||
match serialized_index {
|
match serialized_index {
|
||||||
SerializedIndex::Input(idx) => Index::Input(idx.clone()),
|
SerializedIndex::Input(idx) => Index::Input(*idx),
|
||||||
SerializedIndex::Aux(idx) => Index::Aux(idx.clone()),
|
SerializedIndex::Aux(idx) => Index::Aux(*idx),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user