remove unnecessary program clone

This commit is contained in:
collin 2020-11-12 15:43:37 -08:00
parent 12fdb826e9
commit d3ab32822e
3 changed files with 18 additions and 8 deletions

View File

@ -46,7 +46,7 @@ pub fn generate_constraints<F: Field + PrimeField, G: GroupType<F>, CS: Constrai
let program_name = program.get_name();
let main_function_name = new_scope(&program_name, "main");
resolved_program.store_definitions(program, imported_programs)?;
resolved_program.store_definitions(&program, imported_programs)?;
let main = resolved_program.get(&main_function_name).ok_or(CompilerError::NoMain)?;
@ -72,7 +72,7 @@ pub fn generate_test_constraints<F: Field + PrimeField, G: GroupType<F>>(
let tests = program.tests.clone();
// Store definitions
resolved_program.store_definitions(program, imported_programs)?;
resolved_program.store_definitions(&program, imported_programs)?;
// Get default input
let default = input.pairs.get(&program_name);

View File

@ -28,7 +28,11 @@ use leo_imports::ImportParser;
use snarkos_models::curves::{Field, PrimeField};
impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
pub fn store_definitions(&mut self, program: Program, imported_programs: &ImportParser) -> Result<(), ImportError> {
pub fn store_definitions(
&mut self,
program: &Program,
imported_programs: &ImportParser,
) -> Result<(), ImportError> {
let program_name = program.name.trim_end_matches(".leo");
// evaluate all import statements and store imported definitions
@ -39,15 +43,21 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
.collect::<Result<Vec<_>, ImportError>>()?;
// evaluate and store all circuit definitions
program.circuits.into_iter().for_each(|(identifier, circuit)| {
program.circuits.iter().for_each(|(identifier, circuit)| {
let resolved_circuit_name = new_scope(program_name, &identifier.name);
self.store(resolved_circuit_name, ConstrainedValue::CircuitDefinition(circuit));
self.store(
resolved_circuit_name,
ConstrainedValue::CircuitDefinition(circuit.clone()),
);
});
// evaluate and store all function definitions
program.functions.into_iter().for_each(|(function_name, function)| {
program.functions.iter().for_each(|(function_name, function)| {
let resolved_function_name = new_scope(program_name, &function_name.name);
self.store(resolved_function_name, ConstrainedValue::Function(None, function));
self.store(
resolved_function_name,
ConstrainedValue::Function(None, function.clone()),
);
});
Ok(())

View File

@ -47,7 +47,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
.ok_or_else(|| ImportError::unknown_package(import.package.name.clone()))?;
// Parse imported program
self.store_definitions(program.clone(), imported_programs)?;
self.store_definitions(program, imported_programs)?;
// Store the imported symbol
self.store_symbol(scope, &name, &symbol, program)?;