From dcd484a62f2ad165a347e497ddcd7e00c2b3fb47 Mon Sep 17 00:00:00 2001 From: collin Date: Tue, 5 May 2020 18:40:25 -0700 Subject: [PATCH] fix imports --- benchmark/src/main.rs | 8 +++----- compiler/src/ast.rs | 4 ---- compiler/src/compiler.rs | 5 +++-- compiler/src/constraints/boolean.rs | 18 +++++++++++------- compiler/src/constraints/expression.rs | 17 ++++++++++------- compiler/src/constraints/field_element.rs | 18 +++++++++++------- compiler/src/constraints/integer.rs | 19 +++++++++++-------- .../{constraints.rs => main_function.rs} | 13 ++++++++----- compiler/src/constraints/mod.rs | 6 +++--- compiler/src/constraints/resolved_program.rs | 14 +++++++------- compiler/src/constraints/resolved_value.rs | 10 ++++++---- compiler/src/constraints/statement.rs | 16 +++++++++------- compiler/src/imports.rs | 2 ++ compiler/src/lib.rs | 2 +- compiler/src/types.rs | 2 +- compiler/src/types_display.rs | 2 +- compiler/src/types_from.rs | 10 ++++------ 17 files changed, 91 insertions(+), 75 deletions(-) rename compiler/src/constraints/{constraints.rs => main_function.rs} (98%) diff --git a/benchmark/src/main.rs b/benchmark/src/main.rs index c80668c867..fab2618639 100644 --- a/benchmark/src/main.rs +++ b/benchmark/src/main.rs @@ -1,6 +1,7 @@ -use leo_compiler::errors::CompilerError; -use leo_compiler::{self, ast, ParameterValue, Program}; +use leo_compiler::{self, ast, errors::CompilerError, ParameterValue, Program}; +use from_pest::FromPest; +use rand::thread_rng; use snarkos_algorithms::snark::{ create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof, }; @@ -10,9 +11,6 @@ use snarkos_models::{ curves::{Field, PrimeField}, gadgets::r1cs::{ConstraintSynthesizer, ConstraintSystem}, }; - -use from_pest::FromPest; -use rand::thread_rng; use std::{ fs, marker::PhantomData, diff --git a/compiler/src/ast.rs b/compiler/src/ast.rs index 706745e473..750a7c5f35 100644 --- a/compiler/src/ast.rs +++ b/compiler/src/ast.rs @@ -1,8 +1,4 @@ //! Abstract syntax tree (ast) representation from leo.pest. -//! -//! @file zokrates_program.rs -//! @author Howard Wu -//! @date 2020 use from_pest::{ConversionError, FromPest, Void}; use pest::{ diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index 511aa3780c..b97a66b17c 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -1,5 +1,6 @@ -use crate::errors::CompilerError; -use crate::{ast, ParameterValue, Program, ResolvedProgram, ResolvedValue}; +//! Compiles a Leo program from a file path. + +use crate::{ast, errors::CompilerError, ParameterValue, Program, ResolvedProgram, ResolvedValue}; use snarkos_errors::gadgets::SynthesisError; use snarkos_models::{ diff --git a/compiler/src/constraints/boolean.rs b/compiler/src/constraints/boolean.rs index 65d9f5a318..49839a504b 100644 --- a/compiler/src/constraints/boolean.rs +++ b/compiler/src/constraints/boolean.rs @@ -1,13 +1,17 @@ -//! Methods to enforce constraints on booleans in a resolved aleo program. +//! Methods to enforce constraints on booleans in a resolved Leo program. -use crate::constraints::{ResolvedProgram, ResolvedValue}; -use crate::{new_variable_from_variable, ParameterModel, ParameterValue, Variable}; +use crate::{ + constraints::{new_variable_from_variable, ResolvedProgram, ResolvedValue}, + types::{ParameterModel, ParameterValue, Variable}, +}; use snarkos_errors::gadgets::SynthesisError; -use snarkos_models::curves::{Field, PrimeField}; -use snarkos_models::gadgets::{ - r1cs::ConstraintSystem, - utilities::{alloc::AllocGadget, boolean::Boolean, eq::EqGadget}, +use snarkos_models::{ + curves::{Field, PrimeField}, + gadgets::{ + r1cs::ConstraintSystem, + utilities::{alloc::AllocGadget, boolean::Boolean, eq::EqGadget}, + }, }; impl> ResolvedProgram { diff --git a/compiler/src/constraints/expression.rs b/compiler/src/constraints/expression.rs index 51165da6a6..a2365db7c5 100644 --- a/compiler/src/constraints/expression.rs +++ b/compiler/src/constraints/expression.rs @@ -1,14 +1,17 @@ -//! Methods to enforce constraints on expressions in a resolved aleo program. +//! Methods to enforce constraints on expressions in a resolved Leo program. -use crate::constraints::{new_scope_from_variable, ResolvedProgram, ResolvedValue}; use crate::{ - new_variable_from_variable, Expression, RangeOrExpression, ResolvedStructMember, - SpreadOrExpression, StructMember, Variable, + constraints::{ + new_scope_from_variable, new_variable_from_variable, ResolvedProgram, ResolvedStructMember, + ResolvedValue, + }, + types::{Expression, RangeOrExpression, SpreadOrExpression, StructMember, Variable}, }; -use snarkos_models::curves::{Field, PrimeField}; -use snarkos_models::gadgets::r1cs::ConstraintSystem; -use snarkos_models::gadgets::utilities::boolean::Boolean; +use snarkos_models::{ + curves::{Field, PrimeField}, + gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean}, +}; impl> ResolvedProgram { /// Enforce a variable expression by getting the resolved value diff --git a/compiler/src/constraints/field_element.rs b/compiler/src/constraints/field_element.rs index 77a5b7244d..37fc6047e5 100644 --- a/compiler/src/constraints/field_element.rs +++ b/compiler/src/constraints/field_element.rs @@ -1,13 +1,17 @@ -//! Methods to enforce constraints on field elements in a resolved aleo program. +//! Methods to enforce constraints on field elements in a resolved Leo program. -use crate::constraints::{ResolvedProgram, ResolvedValue}; -use crate::{new_variable_from_variable, FieldElement, ParameterModel, ParameterValue, Variable}; +use crate::{ + constraints::{new_variable_from_variable, FieldElement, ResolvedProgram, ResolvedValue}, + types::{ParameterModel, ParameterValue, Variable}, +}; use snarkos_errors::gadgets::SynthesisError; -use snarkos_models::curves::{Field, PrimeField}; -use snarkos_models::gadgets::{ - r1cs::{ConstraintSystem, LinearCombination, Variable as R1CSVariable}, - utilities::uint32::UInt32, +use snarkos_models::{ + curves::{Field, PrimeField}, + gadgets::{ + r1cs::{ConstraintSystem, LinearCombination, Variable as R1CSVariable}, + utilities::uint32::UInt32, + }, }; impl> ResolvedProgram { diff --git a/compiler/src/constraints/integer.rs b/compiler/src/constraints/integer.rs index 6e9f1fb10d..75ddf9464b 100644 --- a/compiler/src/constraints/integer.rs +++ b/compiler/src/constraints/integer.rs @@ -1,14 +1,17 @@ -//! Methods to enforce constraints on integers in a resolved aleo program. +//! Methods to enforce constraints on integers in a resolved Leo program. -use crate::constraints::{ResolvedProgram, ResolvedValue}; -use crate::{new_variable_from_variable, Integer, ParameterModel, ParameterValue, Variable}; +use crate::{ + constraints::{new_variable_from_variable, ResolvedProgram, ResolvedValue}, + types::{Integer, ParameterModel, ParameterValue, Variable}, +}; use snarkos_errors::gadgets::SynthesisError; -use snarkos_models::curves::{Field, PrimeField}; -use snarkos_models::gadgets::utilities::eq::EqGadget; -use snarkos_models::gadgets::{ - r1cs::ConstraintSystem, - utilities::{alloc::AllocGadget, boolean::Boolean, uint32::UInt32}, +use snarkos_models::{ + curves::{Field, PrimeField}, + gadgets::{ + r1cs::ConstraintSystem, + utilities::{alloc::AllocGadget, boolean::Boolean, eq::EqGadget, uint32::UInt32}, + }, }; impl> ResolvedProgram { diff --git a/compiler/src/constraints/constraints.rs b/compiler/src/constraints/main_function.rs similarity index 98% rename from compiler/src/constraints/constraints.rs rename to compiler/src/constraints/main_function.rs index 35c9da40aa..3800815668 100644 --- a/compiler/src/constraints/constraints.rs +++ b/compiler/src/constraints/main_function.rs @@ -1,4 +1,5 @@ -//! Methods to enforce constraints and construct a resolved aleo program. +//! Methods to enforce the main function with arguments in +//! a resolved Leo program. use crate::{ ast, @@ -6,13 +7,15 @@ use crate::{ new_scope, new_scope_from_variable, new_variable_from_variables, ResolvedProgram, ResolvedValue, }, - types::{Expression, Function, Program, Type}, - Import, ParameterValue, + types::{Expression, Function, ParameterValue, Program, Type}, + Import, }; use from_pest::FromPest; -use snarkos_models::curves::{Field, PrimeField}; -use snarkos_models::gadgets::r1cs::ConstraintSystem; +use snarkos_models::{ + curves::{Field, PrimeField}, + gadgets::r1cs::ConstraintSystem, +}; use std::fs; use std::path::Path; diff --git a/compiler/src/constraints/mod.rs b/compiler/src/constraints/mod.rs index bb21afb799..907625ec94 100644 --- a/compiler/src/constraints/mod.rs +++ b/compiler/src/constraints/mod.rs @@ -1,10 +1,10 @@ -//! Module containing methods to enforce constraints in an aleo program +//! Module containing methods to enforce constraints in an Leo program pub mod boolean; pub use boolean::*; -pub mod constraints; -pub use constraints::*; +pub mod main_function; +pub use main_function::*; pub mod expression; pub use expression::*; diff --git a/compiler/src/constraints/resolved_program.rs b/compiler/src/constraints/resolved_program.rs index aa4d48a6fc..7e19c12120 100644 --- a/compiler/src/constraints/resolved_program.rs +++ b/compiler/src/constraints/resolved_program.rs @@ -1,12 +1,12 @@ -//! An in memory store to keep track of defined names when constraining an aleo program. +//! An in memory store to keep track of defined names when constraining a Leo program. -use crate::constraints::ResolvedValue; -use crate::types::Variable; +use crate::{constraints::ResolvedValue, types::Variable}; -use snarkos_models::curves::{Field, PrimeField}; -use snarkos_models::gadgets::r1cs::ConstraintSystem; -use std::collections::HashMap; -use std::marker::PhantomData; +use snarkos_models::{ + curves::{Field, PrimeField}, + gadgets::r1cs::ConstraintSystem, +}; +use std::{collections::HashMap, marker::PhantomData}; pub struct ResolvedProgram> { pub resolved_names: HashMap>, diff --git a/compiler/src/constraints/resolved_value.rs b/compiler/src/constraints/resolved_value.rs index d8ca67bbf8..7ee115ec3b 100644 --- a/compiler/src/constraints/resolved_value.rs +++ b/compiler/src/constraints/resolved_value.rs @@ -1,10 +1,12 @@ -//! The in memory stored value for a defined name in a resolved aleo program. +//! The in memory stored value for a defined name in a resolved Leo program. use crate::types::{Function, Struct, Type, Variable}; -use snarkos_models::curves::{Field, PrimeField}; -use snarkos_models::gadgets::{ - r1cs::Variable as R1CSVariable, utilities::boolean::Boolean, utilities::uint32::UInt32, +use snarkos_models::{ + curves::{Field, PrimeField}, + gadgets::{ + r1cs::Variable as R1CSVariable, utilities::boolean::Boolean, utilities::uint32::UInt32, + }, }; use std::fmt; diff --git a/compiler/src/constraints/statement.rs b/compiler/src/constraints/statement.rs index bcffd5c0b8..54ce16bd1d 100644 --- a/compiler/src/constraints/statement.rs +++ b/compiler/src/constraints/statement.rs @@ -1,14 +1,16 @@ -//! Methods to enforce constraints on statements in a resolved aleo program. +//! Methods to enforce constraints on statements in a resolved Leo program. -use crate::constraints::{new_scope_from_variable, ResolvedProgram, ResolvedValue}; use crate::{ - Assignee, ConditionalNestedOrEnd, ConditionalStatement, Expression, Integer, RangeOrExpression, - Statement, Type, Variable, + constraints::{new_scope_from_variable, ResolvedProgram, ResolvedValue}, + types::{ + Assignee, ConditionalNestedOrEnd, ConditionalStatement, Expression, Integer, + RangeOrExpression, Statement, Type, Variable, + }, }; -use snarkos_models::curves::{Field, PrimeField}; -use snarkos_models::gadgets::{ - r1cs::ConstraintSystem, utilities::boolean::Boolean, utilities::uint32::UInt32, +use snarkos_models::{ + curves::{Field, PrimeField}, + gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean, utilities::uint32::UInt32}, }; impl> ResolvedProgram { diff --git a/compiler/src/imports.rs b/compiler/src/imports.rs index cdd338fcf5..edb61f043a 100644 --- a/compiler/src/imports.rs +++ b/compiler/src/imports.rs @@ -1,3 +1,5 @@ +//! The Import type for a Leo program. + use crate::Variable; use snarkos_models::curves::{Field, PrimeField}; diff --git a/compiler/src/lib.rs b/compiler/src/lib.rs index 8b4abb56fc..5d22179f24 100644 --- a/compiler/src/lib.rs +++ b/compiler/src/lib.rs @@ -1,4 +1,4 @@ -//! Module containing structs and types that make up an Leo program. +//! Module containing structs and types that make up a Leo program. #[macro_use] extern crate failure; diff --git a/compiler/src/types.rs b/compiler/src/types.rs index 00a19787e2..36272da3c2 100644 --- a/compiler/src/types.rs +++ b/compiler/src/types.rs @@ -1,4 +1,4 @@ -//! A typed program in aleo consists of import, struct, and function definitions. +//! A typed Leo program consists of import, struct, and function definitions. //! Each defined type consists of typed statements and expressions. use crate::Import; diff --git a/compiler/src/types_display.rs b/compiler/src/types_display.rs index a96332d913..8b2f49e215 100644 --- a/compiler/src/types_display.rs +++ b/compiler/src/types_display.rs @@ -1,4 +1,4 @@ -//! Format display functions for zokrates_program types. +//! Format display functions for Leo types. use crate::{ Assignee, ConditionalNestedOrEnd, ConditionalStatement, Expression, Function, FunctionName, diff --git a/compiler/src/types_from.rs b/compiler/src/types_from.rs index 1aa39bfa1f..25fb3f69a8 100644 --- a/compiler/src/types_from.rs +++ b/compiler/src/types_from.rs @@ -1,11 +1,9 @@ -//! Logic to convert from an abstract syntax tree (ast) representation to a typed aleo program. +//! Logic to convert from an abstract syntax tree (ast) representation to a Leo program. -use crate::{ast, FunctionName}; -use crate::{types, Import, ImportSymbol}; +use crate::{ast, types, Import, ImportSymbol}; use snarkos_models::curves::{Field, PrimeField}; -use std::collections::HashMap; -use std::marker::PhantomData; +use std::{collections::HashMap, marker::PhantomData}; /// pest ast -> types::Variable @@ -730,7 +728,7 @@ impl<'ast, F: Field + PrimeField> types::Program { ); }); - if let Some(main_function) = functions.get(&FunctionName("main".into())) { + if let Some(main_function) = functions.get(&types::FunctionName("main".into())) { num_parameters = main_function.parameters.len(); }