diff --git a/ast/src/circuits/circuit_member.rs b/ast/src/circuits/circuit_member.rs index 37c33f9689..d3d949e99b 100644 --- a/ast/src/circuits/circuit_member.rs +++ b/ast/src/circuits/circuit_member.rs @@ -16,7 +16,7 @@ use crate::{ ast::Rule, - circuits::{CircuitFieldDefinition, CircuitFunction}, + circuits::{CircuitFunction, CircuitVariableDefinition}, }; use pest_ast::FromPest; @@ -25,6 +25,6 @@ use serde::Serialize; #[derive(Clone, Debug, FromPest, PartialEq, Serialize)] #[pest_ast(rule(Rule::circuit_member))] pub enum CircuitMember<'ast> { - CircuitFieldDefinition(CircuitFieldDefinition<'ast>), + CircuitVariableDefinition(CircuitVariableDefinition<'ast>), CircuitFunction(CircuitFunction<'ast>), } diff --git a/ast/src/circuits/circuit_field.rs b/ast/src/circuits/circuit_variable.rs similarity index 93% rename from ast/src/circuits/circuit_field.rs rename to ast/src/circuits/circuit_variable.rs index d141ae718f..0f14fa43e0 100644 --- a/ast/src/circuits/circuit_field.rs +++ b/ast/src/circuits/circuit_variable.rs @@ -21,8 +21,8 @@ use pest_ast::FromPest; use serde::Serialize; #[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::circuit_field))] -pub struct CircuitField<'ast> { +#[pest_ast(rule(Rule::circuit_variable))] +pub struct CircuitVariable<'ast> { pub identifier: Identifier<'ast>, pub expression: Expression<'ast>, #[pest_ast(outer())] diff --git a/ast/src/circuits/circuit_field_definition.rs b/ast/src/circuits/circuit_variable_definition.rs similarity index 91% rename from ast/src/circuits/circuit_field_definition.rs rename to ast/src/circuits/circuit_variable_definition.rs index a919786a4f..533fff7455 100644 --- a/ast/src/circuits/circuit_field_definition.rs +++ b/ast/src/circuits/circuit_variable_definition.rs @@ -21,8 +21,8 @@ use pest_ast::FromPest; use serde::Serialize; #[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::circuit_field_definition))] -pub struct CircuitFieldDefinition<'ast> { +#[pest_ast(rule(Rule::circuit_variable_definition))] +pub struct CircuitVariableDefinition<'ast> { pub identifier: Identifier<'ast>, pub _type: Type<'ast>, #[pest_ast(outer())] diff --git a/ast/src/circuits/mod.rs b/ast/src/circuits/mod.rs index dcb5aae1e8..768a36fd7e 100644 --- a/ast/src/circuits/mod.rs +++ b/ast/src/circuits/mod.rs @@ -17,11 +17,11 @@ pub mod circuit; pub use circuit::*; -pub mod circuit_field; -pub use circuit_field::*; +pub mod circuit_variable; +pub use circuit_variable::*; -pub mod circuit_field_definition; -pub use circuit_field_definition::*; +pub mod circuit_variable_definition; +pub use circuit_variable_definition::*; pub mod circuit_function; pub use circuit_function::*; diff --git a/ast/src/expressions/circuit_inline_expression.rs b/ast/src/expressions/circuit_inline_expression.rs index d829f66fd1..22fdd7074a 100644 --- a/ast/src/expressions/circuit_inline_expression.rs +++ b/ast/src/expressions/circuit_inline_expression.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, circuits::CircuitField, common::Identifier, SpanDef}; +use crate::{ast::Rule, circuits::CircuitVariable, common::Identifier, SpanDef}; use pest::Span; use pest_ast::FromPest; @@ -24,7 +24,7 @@ use serde::Serialize; #[pest_ast(rule(Rule::expression_circuit_inline))] pub struct CircuitInlineExpression<'ast> { pub identifier: Identifier<'ast>, - pub members: Vec>, + pub members: Vec>, #[pest_ast(outer())] #[serde(with = "SpanDef")] pub span: Span<'ast>, diff --git a/ast/src/leo.pest b/ast/src/leo.pest index 9fb9df066f..fb6e5468e6 100644 --- a/ast/src/leo.pest +++ b/ast/src/leo.pest @@ -307,17 +307,17 @@ access_static_member = ${ "::" ~ identifier } // Declared in circuits/circuit_definition.rs circuit = { "circuit " ~ identifier ~ "{" ~ NEWLINE* ~ circuit_member* ~ NEWLINE* ~ "}" ~ NEWLINE* } -// Declared in circuits/circuit_field.rs -circuit_field = { identifier ~ ":" ~ expression } +// Declared in circuits/circuit_variable.rs +circuit_variable = { identifier ~ ":" ~ expression } -// Declared in circuits/circuit_field_definition.rs -circuit_field_definition = { identifier ~ ":" ~ type_ ~ ","?} +// Declared in circuits/circuit_variable_definition.rs +circuit_variable_definition = { identifier ~ ":" ~ type_ ~ ","?} // Declared in circuits/circuit_function.rs circuit_function = { static_? ~ function } // Declared in circuits/circuit_member.rs -circuit_member = { circuit_function | circuit_field_definition ~ NEWLINE*} +circuit_member = { circuit_function | circuit_variable_definition ~ NEWLINE*} /// Conditionals @@ -353,8 +353,8 @@ expression_array_inline = { "[" ~ NEWLINE* ~ inline_array_inner ~ NEWLINE* ~ "]" inline_array_inner = _{(spread_or_expression ~ ("," ~ NEWLINE* ~ spread_or_expression)*)?} // Declared in expressions/circuit_inline_expression.rs -expression_circuit_inline = { identifier ~ "{" ~ NEWLINE* ~ circuit_field_list ~ NEWLINE* ~ "}" } -circuit_field_list = _{ (circuit_field ~ ("," ~ NEWLINE* ~ circuit_field)*)? ~ ","? } +expression_circuit_inline = { identifier ~ "{" ~ NEWLINE* ~ circuit_variable_list ~ NEWLINE* ~ "}" } +circuit_variable_list = _{ (circuit_variable ~ ("," ~ NEWLINE* ~ circuit_variable)*)? ~ ","? } // Declared in expressions/unary_expression.rs expression_unary = { operation_unary ~ expression_term } diff --git a/compiler/src/expression/circuit/circuit.rs b/compiler/src/expression/circuit/circuit.rs index c45292ec4b..b27196e49c 100644 --- a/compiler/src/expression/circuit/circuit.rs +++ b/compiler/src/expression/circuit/circuit.rs @@ -22,7 +22,7 @@ use crate::{ value::{ConstrainedCircuitMember, ConstrainedValue}, GroupType, }; -use leo_typed::{CircuitFieldDefinition, CircuitMember, Identifier, Span}; +use leo_typed::{CircuitMember, CircuitVariableDefinition, Identifier, Span}; use snarkos_models::{ curves::{Field, PrimeField}, @@ -36,7 +36,7 @@ impl> ConstrainedProgram { file_scope: String, function_scope: String, identifier: Identifier, - members: Vec, + members: Vec, span: Span, ) -> Result, ExpressionError> { let mut program_identifier = new_scope(file_scope.clone(), identifier.to_string()); @@ -55,23 +55,23 @@ impl> ConstrainedProgram { for member in circuit.members.clone().into_iter() { match member { - CircuitMember::CircuitField(identifier, _type) => { - let matched_field = members + CircuitMember::CircuitVariable(identifier, _type) => { + let matched_variable = members .clone() .into_iter() - .find(|field| field.identifier.eq(&identifier)); - match matched_field { - Some(field) => { + .find(|variable| variable.identifier.eq(&identifier)); + match matched_variable { + Some(variable) => { // Resolve and enforce circuit object - let field_value = self.enforce_expression( + let variable_value = self.enforce_expression( cs, file_scope.clone(), function_scope.clone(), Some(_type.clone()), - field.expression, + variable.expression, )?; - resolved_members.push(ConstrainedCircuitMember(identifier, field_value)) + resolved_members.push(ConstrainedCircuitMember(identifier, variable_value)) } None => return Err(ExpressionError::expected_circuit_member(identifier.to_string(), span)), } diff --git a/compiler/src/statement/assign/assign.rs b/compiler/src/statement/assign/assign.rs index 29a2d78dd1..de63c4bd99 100644 --- a/compiler/src/statement/assign/assign.rs +++ b/compiler/src/statement/assign/assign.rs @@ -80,7 +80,7 @@ impl> ConstrainedProgram { ), Assignee::Tuple(_tuple, index) => self.assign_tuple(cs, indicator, variable_name, index, new_value, span), Assignee::CircuitField(_assignee, object_name) => { - self.mutute_circuit_field(cs, indicator, variable_name, object_name, new_value, span) + self.mutute_circuit_variable(cs, indicator, variable_name, object_name, new_value, span) } } } diff --git a/compiler/src/statement/assign/circuit_field.rs b/compiler/src/statement/assign/circuit_variable.rs similarity index 90% rename from compiler/src/statement/assign/circuit_field.rs rename to compiler/src/statement/assign/circuit_variable.rs index fb11e39dd9..82b08f0d31 100644 --- a/compiler/src/statement/assign/circuit_field.rs +++ b/compiler/src/statement/assign/circuit_variable.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -//! Enforces a circuit field assignment statement in a compiled Leo program. +//! Enforces a circuit variable assignment statement in a compiled Leo program. use crate::{errors::StatementError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_typed::{Identifier, Span}; @@ -28,7 +28,7 @@ use snarkos_models::{ }; impl> ConstrainedProgram { - pub fn mutute_circuit_field>( + pub fn mutute_circuit_variable>( &mut self, cs: &mut CS, indicator: Option, @@ -41,10 +41,10 @@ impl> ConstrainedProgram { match self.get_mutable_assignee(circuit_name, span.clone())? { ConstrainedValue::CircuitExpression(_variable, members) => { - // Modify the circuit field in place - let matched_field = members.into_iter().find(|object| object.0 == object_name); + // Modify the circuit variable in place + let matched_variable = members.into_iter().find(|object| object.0 == object_name); - match matched_field { + match matched_variable { Some(object) => match &object.1 { ConstrainedValue::Function(_circuit_identifier, function) => { return Err(StatementError::immutable_circuit_function( diff --git a/compiler/src/statement/assign/mod.rs b/compiler/src/statement/assign/mod.rs index 5fbffe869c..d340f99a07 100644 --- a/compiler/src/statement/assign/mod.rs +++ b/compiler/src/statement/assign/mod.rs @@ -25,8 +25,8 @@ pub use self::assign::*; pub mod assignee; pub use self::assignee::*; -pub mod circuit_field; -pub use self::circuit_field::*; +pub mod circuit_variable; +pub use self::circuit_variable::*; pub mod tuple; pub use self::tuple::*; diff --git a/compiler/tests/circuits/member_field.leo b/compiler/tests/circuits/member_variable.leo similarity index 100% rename from compiler/tests/circuits/member_field.leo rename to compiler/tests/circuits/member_variable.leo diff --git a/compiler/tests/circuits/member_field_and_function.leo b/compiler/tests/circuits/member_variable_and_function.leo similarity index 100% rename from compiler/tests/circuits/member_field_and_function.leo rename to compiler/tests/circuits/member_variable_and_function.leo diff --git a/compiler/tests/circuits/member_field_fail.leo b/compiler/tests/circuits/member_variable_fail.leo similarity index 100% rename from compiler/tests/circuits/member_field_fail.leo rename to compiler/tests/circuits/member_variable_fail.leo diff --git a/compiler/tests/circuits/mod.rs b/compiler/tests/circuits/mod.rs index deb615c99b..912e462a15 100644 --- a/compiler/tests/circuits/mod.rs +++ b/compiler/tests/circuits/mod.rs @@ -55,24 +55,24 @@ fn test_inline_undefined() { // Members #[test] -fn test_member_field() { - let bytes = include_bytes!("member_field.leo"); +fn test_member_variable() { + let bytes = include_bytes!("member_variable.leo"); let program = parse_program(bytes).unwrap(); assert_satisfied(program); } #[test] -fn test_member_field_fail() { - let bytes = include_bytes!("member_field_fail.leo"); +fn test_member_variable_fail() { + let bytes = include_bytes!("member_variable_fail.leo"); let program = parse_program(bytes).unwrap(); expect_fail(program); } #[test] -fn test_member_field_and_function() { - let bytes = include_bytes!("member_field_and_function.leo"); +fn test_member_variable_and_function() { + let bytes = include_bytes!("member_variable_and_function.leo"); let program = parse_program(bytes).unwrap(); assert_satisfied(program); diff --git a/typed/src/circuits/circuit_member.rs b/typed/src/circuits/circuit_member.rs index 54d170be33..9434fa9e9a 100644 --- a/typed/src/circuits/circuit_member.rs +++ b/typed/src/circuits/circuit_member.rs @@ -16,9 +16,9 @@ use crate::{Function, Identifier, Type}; use leo_ast::circuits::{ - CircuitFieldDefinition as AstCircuitFieldDefinition, CircuitFunction as AstCircuitFunction, CircuitMember as AstCircuitMember, + CircuitVariableDefinition as AstCircuitVariableDefinition, }; use serde::{Deserialize, Serialize}; @@ -26,13 +26,13 @@ use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum CircuitMember { - CircuitField(Identifier, Type), + CircuitVariable(Identifier, Type), CircuitFunction(bool, Function), } -impl<'ast> From> for CircuitMember { - fn from(circuit_value: AstCircuitFieldDefinition<'ast>) -> Self { - CircuitMember::CircuitField( +impl<'ast> From> for CircuitMember { + fn from(circuit_value: AstCircuitVariableDefinition<'ast>) -> Self { + CircuitMember::CircuitVariable( Identifier::from(circuit_value.identifier), Type::from(circuit_value._type), ) @@ -51,7 +51,7 @@ impl<'ast> From> for CircuitMember { impl<'ast> From> for CircuitMember { fn from(object: AstCircuitMember<'ast>) -> Self { match object { - AstCircuitMember::CircuitFieldDefinition(circuit_value) => CircuitMember::from(circuit_value), + AstCircuitMember::CircuitVariableDefinition(circuit_value) => CircuitMember::from(circuit_value), AstCircuitMember::CircuitFunction(circuit_function) => CircuitMember::from(circuit_function), } } @@ -60,7 +60,7 @@ impl<'ast> From> for CircuitMember { impl fmt::Display for CircuitMember { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - CircuitMember::CircuitField(ref identifier, ref _type) => write!(f, "{}: {}", identifier, _type), + CircuitMember::CircuitVariable(ref identifier, ref _type) => write!(f, "{}: {}", identifier, _type), CircuitMember::CircuitFunction(ref _static, ref function) => { if *_static { write!(f, "static ")?; diff --git a/typed/src/circuits/circuit_field_definition.rs b/typed/src/circuits/circuit_variable_definition.rs similarity index 81% rename from typed/src/circuits/circuit_field_definition.rs rename to typed/src/circuits/circuit_variable_definition.rs index ffd99236a6..2abba2b377 100644 --- a/typed/src/circuits/circuit_field_definition.rs +++ b/typed/src/circuits/circuit_variable_definition.rs @@ -15,19 +15,19 @@ // along with the Leo library. If not, see . use crate::{Expression, Identifier}; -use leo_ast::circuits::CircuitField; +use leo_ast::circuits::CircuitVariable; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] -pub struct CircuitFieldDefinition { +pub struct CircuitVariableDefinition { pub identifier: Identifier, pub expression: Expression, } -impl<'ast> From> for CircuitFieldDefinition { - fn from(member: CircuitField<'ast>) -> Self { - CircuitFieldDefinition { +impl<'ast> From> for CircuitVariableDefinition { + fn from(member: CircuitVariable<'ast>) -> Self { + CircuitVariableDefinition { identifier: Identifier::from(member.identifier), expression: Expression::from(member.expression), } diff --git a/typed/src/circuits/mod.rs b/typed/src/circuits/mod.rs index f191d6485c..e25aaff89e 100644 --- a/typed/src/circuits/mod.rs +++ b/typed/src/circuits/mod.rs @@ -17,8 +17,8 @@ pub mod circuit; pub use circuit::*; -pub mod circuit_field_definition; -pub use circuit_field_definition::*; +pub mod circuit_variable_definition; +pub use circuit_variable_definition::*; pub mod circuit_member; pub use circuit_member::*; diff --git a/typed/src/common/assignee.rs b/typed/src/common/assignee.rs index 8ac62bd713..9bea935574 100644 --- a/typed/src/common/assignee.rs +++ b/typed/src/common/assignee.rs @@ -53,8 +53,8 @@ impl<'ast> From> for Assignee { AstAssigneeAccess::Tuple(tuple) => { Assignee::Tuple(Box::new(acc), Expression::get_count_from_ast(tuple.number)) } - AstAssigneeAccess::Member(circuit_field) => { - Assignee::CircuitField(Box::new(acc), Identifier::from(circuit_field.identifier)) + AstAssigneeAccess::Member(circuit_variable) => { + Assignee::CircuitField(Box::new(acc), Identifier::from(circuit_variable.identifier)) } }) } diff --git a/typed/src/expression.rs b/typed/src/expression.rs index 7dbfc71dfa..679a2f68b2 100644 --- a/typed/src/expression.rs +++ b/typed/src/expression.rs @@ -14,7 +14,15 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{CircuitFieldDefinition, GroupValue, Identifier, IntegerType, RangeOrExpression, Span, SpreadOrExpression}; +use crate::{ + CircuitVariableDefinition, + GroupValue, + Identifier, + IntegerType, + RangeOrExpression, + Span, + SpreadOrExpression, +}; use leo_ast::{ access::{Access, AssigneeAccess}, common::{Assignee, Identifier as AstIdentifier}, @@ -90,7 +98,7 @@ pub enum Expression { TupleAccess(Box, usize, Span), // Circuits - Circuit(Identifier, Vec, Span), + Circuit(Identifier, Vec, Span), CircuitMemberAccess(Box, Identifier, Span), // (declared circuit name, circuit member name) CircuitStaticFunctionAccess(Box, Identifier, Span), // (defined circuit name, circuit static member name) @@ -271,8 +279,8 @@ impl<'ast> From> for Expression { let members = expression .members .into_iter() - .map(|member| CircuitFieldDefinition::from(member)) - .collect::>(); + .map(|member| CircuitVariableDefinition::from(member)) + .collect::>(); Expression::Circuit(circuit_name, members, Span::from(expression.span)) }