From 214d9e0f8c23d433654b11c9f1bd13c8e2b91e04 Mon Sep 17 00:00:00 2001 From: gluax Date: Mon, 12 Apr 2021 12:33:06 -0400 Subject: [PATCH] More generic errors for reducing --- .../errors.rs => errors/canonicalization.rs} | 4 +- ast/src/errors/combiner.rs | 37 +++++++ ast/src/errors/mod.rs | 9 ++ ast/src/errors/reducer.rs | 43 ++++++++ ast/src/lib.rs | 2 +- ast/src/reducer/canonicalization.rs | 22 ++-- ast/src/reducer/mod.rs | 3 - ast/src/reducer/reconstructing_director.rs | 101 ++++++++---------- ast/src/reducer/reconstructing_reducer.rs | 96 ++++++++--------- compiler/src/errors/compiler.rs | 4 +- compiler/src/stages/reducing_director.rs | 82 +++++++------- 11 files changed, 237 insertions(+), 166 deletions(-) rename ast/src/{reducer/errors.rs => errors/canonicalization.rs} (94%) create mode 100644 ast/src/errors/combiner.rs create mode 100644 ast/src/errors/reducer.rs diff --git a/ast/src/reducer/errors.rs b/ast/src/errors/canonicalization.rs similarity index 94% rename from ast/src/reducer/errors.rs rename to ast/src/errors/canonicalization.rs index 0ed9d40942..febe7bd0f0 100644 --- a/ast/src/reducer/errors.rs +++ b/ast/src/errors/canonicalization.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::{FormattedError, Span}; +use crate::{FormattedError, LeoError, Span}; #[derive(Debug, Error)] pub enum CanonicalizeError { @@ -22,6 +22,8 @@ pub enum CanonicalizeError { Error(#[from] FormattedError), } +impl LeoError for CanonicalizeError {} + impl CanonicalizeError { fn new_from_span(message: String, span: &Span) -> Self { CanonicalizeError::Error(FormattedError::new_from_span(message, span)) diff --git a/ast/src/errors/combiner.rs b/ast/src/errors/combiner.rs new file mode 100644 index 0000000000..8ad146d1cd --- /dev/null +++ b/ast/src/errors/combiner.rs @@ -0,0 +1,37 @@ +// Copyright (C) 2019-2021 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 . + +use crate::{FormattedError, LeoError, Span}; + +#[derive(Debug, Error)] +pub enum CombinerError { + #[error("{}", _0)] + Error(#[from] FormattedError), +} + +impl LeoError for CombinerError {} + +impl CombinerError { + fn new_from_span(message: String, span: &Span) -> Self { + CombinerError::Error(FormattedError::new_from_span(message, span)) + } + + pub fn asg_statement_not_block(span: &Span) -> Self { + let message = "AstStatement should be be a block".to_string(); + + Self::new_from_span(message, span) + } +} diff --git a/ast/src/errors/mod.rs b/ast/src/errors/mod.rs index c998e0c485..88bfd8f2b4 100644 --- a/ast/src/errors/mod.rs +++ b/ast/src/errors/mod.rs @@ -14,7 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . +pub mod canonicalization; +pub use canonicalization::*; + +pub mod combiner; +pub use combiner::*; + pub mod error; pub use error::*; +pub mod reducer; +pub use reducer::*; + pub trait LeoError {} diff --git a/ast/src/errors/reducer.rs b/ast/src/errors/reducer.rs new file mode 100644 index 0000000000..e8b582af85 --- /dev/null +++ b/ast/src/errors/reducer.rs @@ -0,0 +1,43 @@ +// Copyright (C) 2019-2021 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 . + +use crate::{CanonicalizeError, CombinerError, FormattedError, LeoError, Span}; + +#[derive(Debug, Error)] +pub enum ReducerError { + #[error("{}", _0)] + Error(#[from] FormattedError), + + #[error("{}", _0)] + CanonicalizeError(#[from] CanonicalizeError), + + #[error("{}", _0)] + CombinerError(#[from] CombinerError), +} + +impl LeoError for ReducerError {} + +impl ReducerError { + fn new_from_span(message: String, span: &Span) -> Self { + ReducerError::Error(FormattedError::new_from_span(message, span)) + } + + pub fn impossible_console_assert_call(span: &Span) -> Self { + let message = "Console::Assert cannot be matched here, its handled in another case.".to_string(); + + Self::new_from_span(message, span) + } +} diff --git a/ast/src/lib.rs b/ast/src/lib.rs index c50b3021bc..4601a74959 100644 --- a/ast/src/lib.rs +++ b/ast/src/lib.rs @@ -83,7 +83,7 @@ impl Ast { } /// Mutates the program ast by preforming canonicalization on it. - pub fn canonicalize(&mut self) -> Result<(), CanonicalizeError> { + pub fn canonicalize(&mut self) -> Result<(), ReducerError> { self.ast = ReconstructingDirector::new(Canonicalizer::default()).reduce_program(self.as_repr())?; Ok(()) } diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index fc199a42a6..23d2c29028 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -394,11 +394,13 @@ impl ReconstructingReducer for Canonicalizer { self.in_circuit = !self.in_circuit; } - fn reduce_type(&mut self, _type_: &Type, new: Type, span: &Span) -> Result { + fn reduce_type(&mut self, _type_: &Type, new: Type, span: &Span) -> Result { match new { Type::Array(type_, mut dimensions) => { if dimensions.is_zero() { - return Err(CanonicalizeError::invalid_array_dimension_size(span)); + return Err(ReducerError::from(CanonicalizeError::invalid_array_dimension_size( + span, + ))); } let mut next = Type::Array(type_, ArrayDimensions(vec![dimensions.remove_last().unwrap()])); @@ -415,7 +417,9 @@ impl ReconstructingReducer for Canonicalizer { Ok(array) } - Type::SelfType if !self.in_circuit => Err(CanonicalizeError::big_self_outside_of_circuit(span)), + Type::SelfType if !self.in_circuit => { + Err(ReducerError::from(CanonicalizeError::big_self_outside_of_circuit(span))) + } _ => Ok(new.clone()), } } @@ -424,9 +428,11 @@ impl ReconstructingReducer for Canonicalizer { &mut self, array_init: &ArrayInitExpression, element: Expression, - ) -> Result { + ) -> Result { if array_init.dimensions.is_zero() { - return Err(CanonicalizeError::invalid_array_dimension_size(&array_init.span)); + return Err(ReducerError::from(CanonicalizeError::invalid_array_dimension_size( + &array_init.span, + ))); } let element = Box::new(element); @@ -473,7 +479,7 @@ impl ReconstructingReducer for Canonicalizer { assign: &AssignStatement, assignee: Assignee, value: Expression, - ) -> Result { + ) -> Result { match value { Expression::Value(value_expr) if assign.operation != AssignOperation::Assign => { let mut left = Box::new(Expression::Identifier(assignee.identifier.clone())); @@ -551,7 +557,7 @@ impl ReconstructingReducer for Canonicalizer { input: Vec, output: Option, block: Block, - ) -> Result { + ) -> Result { let new_output = match output { None => Some(Type::Tuple(vec![])), _ => output, @@ -572,7 +578,7 @@ impl ReconstructingReducer for Canonicalizer { _circuit: &Circuit, circuit_name: Identifier, members: Vec, - ) -> Result { + ) -> Result { self.circuit_name = Some(circuit_name.clone()); let circ = Circuit { circuit_name, diff --git a/ast/src/reducer/mod.rs b/ast/src/reducer/mod.rs index d5d4d52982..144997d8e1 100644 --- a/ast/src/reducer/mod.rs +++ b/ast/src/reducer/mod.rs @@ -17,9 +17,6 @@ mod canonicalization; pub use canonicalization::*; -mod errors; -pub use errors::*; - mod reconstructing_reducer; pub use reconstructing_reducer::*; diff --git a/ast/src/reducer/reconstructing_director.rs b/ast/src/reducer/reconstructing_director.rs index ae78b2dc33..c554790a9b 100644 --- a/ast/src/reducer/reconstructing_director.rs +++ b/ast/src/reducer/reconstructing_director.rs @@ -29,7 +29,7 @@ impl ReconstructingDirector { Self { reducer } } - pub fn reduce_type(&mut self, type_: &Type, span: &Span) -> Result { + pub fn reduce_type(&mut self, type_: &Type, span: &Span) -> Result { let new = match type_ { Type::Array(type_, dimensions) => Type::Array(Box::new(self.reduce_type(type_, span)?), dimensions.clone()), Type::Tuple(types) => { @@ -48,7 +48,7 @@ impl ReconstructingDirector { } // Expressions - pub fn reduce_expression(&mut self, expression: &Expression) -> Result { + pub fn reduce_expression(&mut self, expression: &Expression) -> Result { let new = match expression { Expression::Identifier(identifier) => Expression::Identifier(self.reduce_identifier(&identifier)?), Expression::Value(value) => Expression::Value(self.reduce_value(&value)?), @@ -83,15 +83,15 @@ impl ReconstructingDirector { self.reducer.reduce_expression(expression, new) } - pub fn reduce_identifier(&mut self, identifier: &Identifier) -> Result { + pub fn reduce_identifier(&mut self, identifier: &Identifier) -> Result { self.reducer.reduce_identifier(identifier) } - pub fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> Result { + pub fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> Result { self.reducer.reduce_group_tuple(group_tuple) } - pub fn reduce_group_value(&mut self, group_value: &GroupValue) -> Result { + pub fn reduce_group_value(&mut self, group_value: &GroupValue) -> Result { let new = match group_value { GroupValue::Tuple(group_tuple) => GroupValue::Tuple(self.reduce_group_tuple(&group_tuple)?), _ => group_value.clone(), @@ -100,7 +100,7 @@ impl ReconstructingDirector { self.reducer.reduce_group_value(group_value, new) } - pub fn reduce_value(&mut self, value: &ValueExpression) -> Result { + pub fn reduce_value(&mut self, value: &ValueExpression) -> Result { let new = match value { ValueExpression::Group(group_value) => { ValueExpression::Group(Box::new(self.reduce_group_value(&group_value)?)) @@ -111,20 +111,20 @@ impl ReconstructingDirector { self.reducer.reduce_value(value, new) } - pub fn reduce_binary(&mut self, binary: &BinaryExpression) -> Result { + pub fn reduce_binary(&mut self, binary: &BinaryExpression) -> Result { let left = self.reduce_expression(&binary.left)?; let right = self.reduce_expression(&binary.right)?; self.reducer.reduce_binary(binary, left, right, binary.op.clone()) } - pub fn reduce_unary(&mut self, unary: &UnaryExpression) -> Result { + pub fn reduce_unary(&mut self, unary: &UnaryExpression) -> Result { let inner = self.reduce_expression(&unary.inner)?; self.reducer.reduce_unary(unary, inner, unary.op.clone()) } - pub fn reduce_ternary(&mut self, ternary: &TernaryExpression) -> Result { + pub fn reduce_ternary(&mut self, ternary: &TernaryExpression) -> Result { let condition = self.reduce_expression(&ternary.condition)?; let if_true = self.reduce_expression(&ternary.if_true)?; let if_false = self.reduce_expression(&ternary.if_false)?; @@ -132,7 +132,7 @@ impl ReconstructingDirector { self.reducer.reduce_ternary(ternary, condition, if_true, if_false) } - pub fn reduce_cast(&mut self, cast: &CastExpression) -> Result { + pub fn reduce_cast(&mut self, cast: &CastExpression) -> Result { let inner = self.reduce_expression(&cast.inner)?; let target_type = self.reduce_type(&cast.target_type, &cast.span)?; @@ -142,7 +142,7 @@ impl ReconstructingDirector { pub fn reduce_array_inline( &mut self, array_inline: &ArrayInlineExpression, - ) -> Result { + ) -> Result { let mut elements = vec![]; for element in array_inline.elements.iter() { let reduced_element = match element { @@ -160,10 +160,7 @@ impl ReconstructingDirector { self.reducer.reduce_array_inline(array_inline, elements) } - pub fn reduce_array_init( - &mut self, - array_init: &ArrayInitExpression, - ) -> Result { + pub fn reduce_array_init(&mut self, array_init: &ArrayInitExpression) -> Result { let element = self.reduce_expression(&array_init.element)?; self.reducer.reduce_array_init(array_init, element) @@ -172,7 +169,7 @@ impl ReconstructingDirector { pub fn reduce_array_access( &mut self, array_access: &ArrayAccessExpression, - ) -> Result { + ) -> Result { let array = self.reduce_expression(&array_access.array)?; let index = self.reduce_expression(&array_access.index)?; @@ -182,7 +179,7 @@ impl ReconstructingDirector { pub fn reduce_array_range_access( &mut self, array_range_access: &ArrayRangeAccessExpression, - ) -> Result { + ) -> Result { let array = self.reduce_expression(&array_range_access.array)?; let left = array_range_access .left @@ -199,10 +196,7 @@ impl ReconstructingDirector { .reduce_array_range_access(array_range_access, array, left, right) } - pub fn reduce_tuple_init( - &mut self, - tuple_init: &TupleInitExpression, - ) -> Result { + pub fn reduce_tuple_init(&mut self, tuple_init: &TupleInitExpression) -> Result { let mut elements = vec![]; for element in tuple_init.elements.iter() { elements.push(self.reduce_expression(element)?); @@ -214,7 +208,7 @@ impl ReconstructingDirector { pub fn reduce_tuple_access( &mut self, tuple_access: &TupleAccessExpression, - ) -> Result { + ) -> Result { let tuple = self.reduce_expression(&tuple_access.tuple)?; self.reducer.reduce_tuple_access(tuple_access, tuple) @@ -223,7 +217,7 @@ impl ReconstructingDirector { pub fn reduce_circuit_implied_variable_definition( &mut self, variable: &CircuitImpliedVariableDefinition, - ) -> Result { + ) -> Result { let identifier = self.reduce_identifier(&variable.identifier)?; let expression = variable .expression @@ -238,7 +232,7 @@ impl ReconstructingDirector { pub fn reduce_circuit_init( &mut self, circuit_init: &CircuitInitExpression, - ) -> Result { + ) -> Result { let name = self.reduce_identifier(&circuit_init.name)?; let mut members = vec![]; @@ -252,7 +246,7 @@ impl ReconstructingDirector { pub fn reduce_circuit_member_access( &mut self, circuit_member_access: &CircuitMemberAccessExpression, - ) -> Result { + ) -> Result { let circuit = self.reduce_expression(&circuit_member_access.circuit)?; let name = self.reduce_identifier(&circuit_member_access.name)?; @@ -263,7 +257,7 @@ impl ReconstructingDirector { pub fn reduce_circuit_static_fn_access( &mut self, circuit_static_fn_access: &CircuitStaticFunctionAccessExpression, - ) -> Result { + ) -> Result { let circuit = self.reduce_expression(&circuit_static_fn_access.circuit)?; let name = self.reduce_identifier(&circuit_static_fn_access.name)?; @@ -271,7 +265,7 @@ impl ReconstructingDirector { .reduce_circuit_static_fn_access(circuit_static_fn_access, circuit, name) } - pub fn reduce_call(&mut self, call: &CallExpression) -> Result { + pub fn reduce_call(&mut self, call: &CallExpression) -> Result { let function = self.reduce_expression(&call.function)?; let mut arguments = vec![]; @@ -283,7 +277,7 @@ impl ReconstructingDirector { } // Statements - pub fn reduce_statement(&mut self, statement: &Statement) -> Result { + pub fn reduce_statement(&mut self, statement: &Statement) -> Result { let new = match statement { Statement::Return(return_statement) => Statement::Return(self.reduce_return(&return_statement)?), Statement::Definition(definition) => Statement::Definition(self.reduce_definition(&definition)?), @@ -298,22 +292,19 @@ impl ReconstructingDirector { self.reducer.reduce_statement(statement, new) } - pub fn reduce_return(&mut self, return_statement: &ReturnStatement) -> Result { + pub fn reduce_return(&mut self, return_statement: &ReturnStatement) -> Result { let expression = self.reduce_expression(&return_statement.expression)?; self.reducer.reduce_return(return_statement, expression) } - pub fn reduce_variable_name(&mut self, variable_name: &VariableName) -> Result { + pub fn reduce_variable_name(&mut self, variable_name: &VariableName) -> Result { let identifier = self.reduce_identifier(&variable_name.identifier)?; self.reducer.reduce_variable_name(variable_name, identifier) } - pub fn reduce_definition( - &mut self, - definition: &DefinitionStatement, - ) -> Result { + pub fn reduce_definition(&mut self, definition: &DefinitionStatement) -> Result { let mut variable_names = vec![]; for variable_name in definition.variable_names.iter() { variable_names.push(self.reduce_variable_name(variable_name)?); @@ -330,7 +321,7 @@ impl ReconstructingDirector { self.reducer.reduce_definition(definition, variable_names, type_, value) } - pub fn reduce_assignee_access(&mut self, access: &AssigneeAccess) -> Result { + pub fn reduce_assignee_access(&mut self, access: &AssigneeAccess) -> Result { let new = match access { AssigneeAccess::ArrayRange(left, right) => { let left = left.as_ref().map(|left| self.reduce_expression(left)).transpose()?; @@ -346,7 +337,7 @@ impl ReconstructingDirector { self.reducer.reduce_assignee_access(access, new) } - pub fn reduce_assignee(&mut self, assignee: &Assignee) -> Result { + pub fn reduce_assignee(&mut self, assignee: &Assignee) -> Result { let identifier = self.reduce_identifier(&assignee.identifier)?; let mut accesses = vec![]; @@ -357,7 +348,7 @@ impl ReconstructingDirector { self.reducer.reduce_assignee(assignee, identifier, accesses) } - pub fn reduce_assign(&mut self, assign: &AssignStatement) -> Result { + pub fn reduce_assign(&mut self, assign: &AssignStatement) -> Result { let assignee = self.reduce_assignee(&assign.assignee)?; let value = self.reduce_expression(&assign.value)?; @@ -367,7 +358,7 @@ impl ReconstructingDirector { pub fn reduce_conditional( &mut self, conditional: &ConditionalStatement, - ) -> Result { + ) -> Result { let condition = self.reduce_expression(&conditional.condition)?; let block = self.reduce_block(&conditional.block)?; let next = conditional @@ -379,10 +370,7 @@ impl ReconstructingDirector { self.reducer.reduce_conditional(conditional, condition, block, next) } - pub fn reduce_iteration( - &mut self, - iteration: &IterationStatement, - ) -> Result { + pub fn reduce_iteration(&mut self, iteration: &IterationStatement) -> Result { let variable = self.reduce_identifier(&iteration.variable)?; let start = self.reduce_expression(&iteration.start)?; let stop = self.reduce_expression(&iteration.stop)?; @@ -394,7 +382,7 @@ impl ReconstructingDirector { pub fn reduce_console( &mut self, console_function_call: &ConsoleStatement, - ) -> Result { + ) -> Result { let function = match &console_function_call.function { ConsoleFunction::Assert(expression) => ConsoleFunction::Assert(self.reduce_expression(expression)?), ConsoleFunction::Debug(format) | ConsoleFunction::Error(format) | ConsoleFunction::Log(format) => { @@ -413,7 +401,7 @@ impl ReconstructingDirector { ConsoleFunction::Debug(_) => ConsoleFunction::Debug(formatted), ConsoleFunction::Error(_) => ConsoleFunction::Error(formatted), ConsoleFunction::Log(_) => ConsoleFunction::Log(formatted), - _ => unimplemented!(), // impossible + _ => return Err(ReducerError::impossible_console_assert_call(&format.span)), } } }; @@ -424,12 +412,12 @@ impl ReconstructingDirector { pub fn reduce_expression_statement( &mut self, expression: &ExpressionStatement, - ) -> Result { + ) -> Result { let inner_expression = self.reduce_expression(&expression.expression)?; self.reducer.reduce_expression_statement(expression, inner_expression) } - pub fn reduce_block(&mut self, block: &Block) -> Result { + pub fn reduce_block(&mut self, block: &Block) -> Result { let mut statements = vec![]; for statement in block.statements.iter() { statements.push(self.reduce_statement(statement)?); @@ -439,7 +427,7 @@ impl ReconstructingDirector { } // Program - pub fn reduce_program(&mut self, program: &Program) -> Result { + pub fn reduce_program(&mut self, program: &Program) -> Result { let mut inputs = vec![]; for input in program.expected_input.iter() { inputs.push(self.reduce_function_input(input)?); @@ -469,14 +457,14 @@ impl ReconstructingDirector { pub fn reduce_function_input_variable( &mut self, variable: &FunctionInputVariable, - ) -> Result { + ) -> Result { let identifier = self.reduce_identifier(&variable.identifier)?; let type_ = self.reduce_type(&variable.type_, &variable.span)?; self.reducer.reduce_function_input_variable(variable, identifier, type_) } - pub fn reduce_function_input(&mut self, input: &FunctionInput) -> Result { + pub fn reduce_function_input(&mut self, input: &FunctionInput) -> Result { let new = match input { FunctionInput::Variable(function_input_variable) => { FunctionInput::Variable(self.reduce_function_input_variable(function_input_variable)?) @@ -490,7 +478,7 @@ impl ReconstructingDirector { pub fn reduce_package_or_packages( &mut self, package_or_packages: &PackageOrPackages, - ) -> Result { + ) -> Result { let new = match package_or_packages { PackageOrPackages::Package(package) => PackageOrPackages::Package(Package { name: self.reduce_identifier(&package.name)?, @@ -507,16 +495,13 @@ impl ReconstructingDirector { self.reducer.reduce_package_or_packages(package_or_packages, new) } - pub fn reduce_import(&mut self, import: &ImportStatement) -> Result { + pub fn reduce_import(&mut self, import: &ImportStatement) -> Result { let package_or_packages = self.reduce_package_or_packages(&import.package_or_packages)?; self.reducer.reduce_import(import, package_or_packages) } - pub fn reduce_circuit_member( - &mut self, - circuit_member: &CircuitMember, - ) -> Result { + pub fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember) -> Result { let new = match circuit_member { CircuitMember::CircuitVariable(identifier, type_) => CircuitMember::CircuitVariable( self.reduce_identifier(&identifier)?, @@ -530,7 +515,7 @@ impl ReconstructingDirector { self.reducer.reduce_circuit_member(circuit_member, new) } - pub fn reduce_circuit(&mut self, circuit: &Circuit) -> Result { + pub fn reduce_circuit(&mut self, circuit: &Circuit) -> Result { let circuit_name = self.reduce_identifier(&circuit.circuit_name)?; let mut members = vec![]; @@ -541,13 +526,13 @@ impl ReconstructingDirector { self.reducer.reduce_circuit(circuit, circuit_name, members) } - fn reduce_annotation(&mut self, annotation: &Annotation) -> Result { + fn reduce_annotation(&mut self, annotation: &Annotation) -> Result { let name = self.reduce_identifier(&annotation.name)?; self.reducer.reduce_annotation(annotation, name) } - pub fn reduce_function(&mut self, function: &Function) -> Result { + pub fn reduce_function(&mut self, function: &Function) -> Result { let identifier = self.reduce_identifier(&function.identifier)?; let mut annotations = vec![]; diff --git a/ast/src/reducer/reconstructing_reducer.rs b/ast/src/reducer/reconstructing_reducer.rs index 4fb076fd44..637bad2869 100644 --- a/ast/src/reducer/reconstructing_reducer.rs +++ b/ast/src/reducer/reconstructing_reducer.rs @@ -23,27 +23,23 @@ pub trait ReconstructingReducer { fn in_circuit(&self) -> bool; fn swap_in_circuit(&mut self); - fn reduce_type(&mut self, _type_: &Type, new: Type, _span: &Span) -> Result { + fn reduce_type(&mut self, _type_: &Type, new: Type, _span: &Span) -> Result { Ok(new) } // Expressions - fn reduce_expression( - &mut self, - _expression: &Expression, - new: Expression, - ) -> Result { + fn reduce_expression(&mut self, _expression: &Expression, new: Expression) -> Result { Ok(new) } - fn reduce_identifier(&mut self, identifier: &Identifier) -> Result { + fn reduce_identifier(&mut self, identifier: &Identifier) -> Result { Ok(Identifier { name: identifier.name.clone(), span: identifier.span.clone(), }) } - fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> Result { + fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> Result { Ok(GroupTuple { x: group_tuple.x.clone(), y: group_tuple.y.clone(), @@ -51,11 +47,7 @@ pub trait ReconstructingReducer { }) } - fn reduce_group_value( - &mut self, - _group_value: &GroupValue, - new: GroupValue, - ) -> Result { + fn reduce_group_value(&mut self, _group_value: &GroupValue, new: GroupValue) -> Result { Ok(new) } @@ -63,7 +55,7 @@ pub trait ReconstructingReducer { &mut self, _value: &ValueExpression, new: ValueExpression, - ) -> Result { + ) -> Result { Ok(new) } @@ -73,7 +65,7 @@ pub trait ReconstructingReducer { left: Expression, right: Expression, op: BinaryOperation, - ) -> Result { + ) -> Result { Ok(BinaryExpression { left: Box::new(left), right: Box::new(right), @@ -87,7 +79,7 @@ pub trait ReconstructingReducer { unary: &UnaryExpression, inner: Expression, op: UnaryOperation, - ) -> Result { + ) -> Result { Ok(UnaryExpression { inner: Box::new(inner), op, @@ -101,7 +93,7 @@ pub trait ReconstructingReducer { condition: Expression, if_true: Expression, if_false: Expression, - ) -> Result { + ) -> Result { Ok(TernaryExpression { condition: Box::new(condition), if_true: Box::new(if_true), @@ -115,7 +107,7 @@ pub trait ReconstructingReducer { cast: &CastExpression, inner: Expression, target_type: Type, - ) -> Result { + ) -> Result { Ok(CastExpression { inner: Box::new(inner), target_type, @@ -127,7 +119,7 @@ pub trait ReconstructingReducer { &mut self, array_inline: &ArrayInlineExpression, elements: Vec, - ) -> Result { + ) -> Result { Ok(ArrayInlineExpression { elements, span: array_inline.span.clone(), @@ -138,7 +130,7 @@ pub trait ReconstructingReducer { &mut self, array_init: &ArrayInitExpression, element: Expression, - ) -> Result { + ) -> Result { Ok(ArrayInitExpression { element: Box::new(element), dimensions: array_init.dimensions.clone(), @@ -151,7 +143,7 @@ pub trait ReconstructingReducer { array_access: &ArrayAccessExpression, array: Expression, index: Expression, - ) -> Result { + ) -> Result { Ok(ArrayAccessExpression { array: Box::new(array), index: Box::new(index), @@ -165,7 +157,7 @@ pub trait ReconstructingReducer { array: Expression, left: Option, right: Option, - ) -> Result { + ) -> Result { Ok(ArrayRangeAccessExpression { array: Box::new(array), left: left.map(|expr| Box::new(expr)), @@ -178,7 +170,7 @@ pub trait ReconstructingReducer { &mut self, tuple_init: &TupleInitExpression, elements: Vec, - ) -> Result { + ) -> Result { Ok(TupleInitExpression { elements, span: tuple_init.span.clone(), @@ -189,7 +181,7 @@ pub trait ReconstructingReducer { &mut self, tuple_access: &TupleAccessExpression, tuple: Expression, - ) -> Result { + ) -> Result { Ok(TupleAccessExpression { tuple: Box::new(tuple), index: tuple_access.index.clone(), @@ -202,7 +194,7 @@ pub trait ReconstructingReducer { _variable: &CircuitImpliedVariableDefinition, identifier: Identifier, expression: Option, - ) -> Result { + ) -> Result { Ok(CircuitImpliedVariableDefinition { identifier, expression }) } @@ -211,7 +203,7 @@ pub trait ReconstructingReducer { circuit_init: &CircuitInitExpression, name: Identifier, members: Vec, - ) -> Result { + ) -> Result { Ok(CircuitInitExpression { name, members, @@ -224,7 +216,7 @@ pub trait ReconstructingReducer { circuit_member_access: &CircuitMemberAccessExpression, circuit: Expression, name: Identifier, - ) -> Result { + ) -> Result { Ok(CircuitMemberAccessExpression { circuit: Box::new(circuit), name, @@ -237,7 +229,7 @@ pub trait ReconstructingReducer { circuit_static_fn_access: &CircuitStaticFunctionAccessExpression, circuit: Expression, name: Identifier, - ) -> Result { + ) -> Result { Ok(CircuitStaticFunctionAccessExpression { circuit: Box::new(circuit), name, @@ -250,7 +242,7 @@ pub trait ReconstructingReducer { call: &CallExpression, function: Expression, arguments: Vec, - ) -> Result { + ) -> Result { Ok(CallExpression { function: Box::new(function), arguments, @@ -259,7 +251,7 @@ pub trait ReconstructingReducer { } // Statements - fn reduce_statement(&mut self, _statement: &Statement, new: Statement) -> Result { + fn reduce_statement(&mut self, _statement: &Statement, new: Statement) -> Result { Ok(new) } @@ -267,7 +259,7 @@ pub trait ReconstructingReducer { &mut self, return_statement: &ReturnStatement, expression: Expression, - ) -> Result { + ) -> Result { Ok(ReturnStatement { expression, span: return_statement.span.clone(), @@ -278,7 +270,7 @@ pub trait ReconstructingReducer { &mut self, variable_name: &VariableName, identifier: Identifier, - ) -> Result { + ) -> Result { Ok(VariableName { mutable: variable_name.mutable, identifier, @@ -292,7 +284,7 @@ pub trait ReconstructingReducer { variable_names: Vec, type_: Option, value: Expression, - ) -> Result { + ) -> Result { Ok(DefinitionStatement { declaration_type: definition.declaration_type.clone(), variable_names, @@ -306,7 +298,7 @@ pub trait ReconstructingReducer { &mut self, _access: &AssigneeAccess, new: AssigneeAccess, - ) -> Result { + ) -> Result { Ok(new) } @@ -315,7 +307,7 @@ pub trait ReconstructingReducer { assignee: &Assignee, identifier: Identifier, accesses: Vec, - ) -> Result { + ) -> Result { Ok(Assignee { identifier, accesses, @@ -328,7 +320,7 @@ pub trait ReconstructingReducer { assign: &AssignStatement, assignee: Assignee, value: Expression, - ) -> Result { + ) -> Result { Ok(AssignStatement { operation: assign.operation.clone(), assignee, @@ -343,7 +335,7 @@ pub trait ReconstructingReducer { condition: Expression, block: Block, statement: Option, - ) -> Result { + ) -> Result { Ok(ConditionalStatement { condition, block, @@ -359,7 +351,7 @@ pub trait ReconstructingReducer { start: Expression, stop: Expression, block: Block, - ) -> Result { + ) -> Result { Ok(IterationStatement { variable, start, @@ -373,7 +365,7 @@ pub trait ReconstructingReducer { &mut self, console: &ConsoleStatement, function: ConsoleFunction, - ) -> Result { + ) -> Result { Ok(ConsoleStatement { function, span: console.span.clone(), @@ -384,14 +376,14 @@ pub trait ReconstructingReducer { &mut self, expression_statement: &ExpressionStatement, expression: Expression, - ) -> Result { + ) -> Result { Ok(ExpressionStatement { expression, span: expression_statement.span.clone(), }) } - fn reduce_block(&mut self, block: &Block, statements: Vec) -> Result { + fn reduce_block(&mut self, block: &Block, statements: Vec) -> Result { Ok(Block { statements, span: block.span.clone(), @@ -406,7 +398,7 @@ pub trait ReconstructingReducer { imports: Vec, circuits: IndexMap, functions: IndexMap, - ) -> Result { + ) -> Result { Ok(Program { name: program.name.clone(), expected_input, @@ -421,7 +413,7 @@ pub trait ReconstructingReducer { variable: &FunctionInputVariable, identifier: Identifier, type_: Type, - ) -> Result { + ) -> Result { Ok(FunctionInputVariable { identifier, const_: variable.const_, @@ -435,7 +427,7 @@ pub trait ReconstructingReducer { &mut self, _input: &FunctionInput, new: FunctionInput, - ) -> Result { + ) -> Result { Ok(new) } @@ -443,7 +435,7 @@ pub trait ReconstructingReducer { &mut self, _package_or_packages: &PackageOrPackages, new: PackageOrPackages, - ) -> Result { + ) -> Result { Ok(new) } @@ -451,7 +443,7 @@ pub trait ReconstructingReducer { &mut self, import: &ImportStatement, package_or_packages: PackageOrPackages, - ) -> Result { + ) -> Result { Ok(ImportStatement { package_or_packages, span: import.span.clone(), @@ -462,7 +454,7 @@ pub trait ReconstructingReducer { &mut self, _circuit_member: &CircuitMember, new: CircuitMember, - ) -> Result { + ) -> Result { Ok(new) } @@ -471,15 +463,11 @@ pub trait ReconstructingReducer { _circuit: &Circuit, circuit_name: Identifier, members: Vec, - ) -> Result { + ) -> Result { Ok(Circuit { circuit_name, members }) } - fn reduce_annotation( - &mut self, - annotation: &Annotation, - name: Identifier, - ) -> Result { + fn reduce_annotation(&mut self, annotation: &Annotation, name: Identifier) -> Result { Ok(Annotation { span: annotation.span.clone(), name, @@ -496,7 +484,7 @@ pub trait ReconstructingReducer { input: Vec, output: Option, block: Block, - ) -> Result { + ) -> Result { Ok(Function { identifier, annotations, diff --git a/compiler/src/errors/compiler.rs b/compiler/src/errors/compiler.rs index f66cdd488a..f0da27c838 100644 --- a/compiler/src/errors/compiler.rs +++ b/compiler/src/errors/compiler.rs @@ -16,7 +16,7 @@ use crate::errors::FunctionError; use leo_asg::{AsgConvertError, FormattedError}; -use leo_ast::{CanonicalizeError, LeoError}; +use leo_ast::{LeoError, ReducerError}; use leo_input::InputParserError; use leo_parser::SyntaxError; use leo_state::LocalDataVerificationError; @@ -56,7 +56,7 @@ pub enum CompilerError { AsgConvertError(#[from] AsgConvertError), #[error("{}", _0)] - CanonicalizeError(#[from] CanonicalizeError), + ReducerError(#[from] ReducerError), } impl LeoError for CompilerError {} diff --git a/compiler/src/stages/reducing_director.rs b/compiler/src/stages/reducing_director.rs index ad7cd4b822..69d9a06c49 100644 --- a/compiler/src/stages/reducing_director.rs +++ b/compiler/src/stages/reducing_director.rs @@ -63,7 +63,6 @@ use leo_ast::{ BinaryExpression as AstBinaryExpression, Block as AstBlockStatement, CallExpression as AstCallExpression, - CanonicalizeError, CastExpression as AstCastExpression, Circuit as AstCircuit, CircuitImpliedVariableDefinition, @@ -71,6 +70,7 @@ use leo_ast::{ CircuitMember as AstCircuitMember, CircuitMemberAccessExpression, CircuitStaticFunctionAccessExpression, + CombinerError, ConditionalStatement as AstConditionalStatement, ConsoleFunction as AstConsoleFunction, ConsoleStatement as AstConsoleStatement, @@ -82,6 +82,7 @@ use leo_ast::{ IterationStatement as AstIterationStatement, PositiveNumber, ReconstructingReducer, + ReducerError, ReturnStatement as AstReturnStatement, Span, SpreadOrExpression, @@ -105,7 +106,7 @@ impl CombineAstAsgDirector { Self { ast_reducer, options } } - pub fn reduce_type(&mut self, ast: &AstType, asg: &AsgType, span: &Span) -> Result { + pub fn reduce_type(&mut self, ast: &AstType, asg: &AsgType, span: &Span) -> Result { let new = match (ast, asg) { (AstType::Array(ast_type, ast_dimensions), AsgType::Array(asg_type, asg_dimensions)) => { if self.options.type_inference_enabled { @@ -140,7 +141,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstExpression, asg: &AsgExpression, - ) -> Result { + ) -> Result { let new = match (ast, asg) { // TODO what to do for the following: // Ast::Identifier, Ast::Value, Asg::Constant, Asg::ValueRef @@ -199,7 +200,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstArrayAccessExpression, asg: &AsgArrayAccessExpression, - ) -> Result { + ) -> Result { let array = self.reduce_expression(&ast.array, asg.array.get())?; let index = self.reduce_expression(&ast.index, asg.index.get())?; @@ -210,7 +211,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstArrayInitExpression, asg: &AsgArrayInitExpression, - ) -> Result { + ) -> Result { let element = self.reduce_expression(&ast.element, asg.element.get())?; self.ast_reducer.reduce_array_init(ast, element) @@ -220,7 +221,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstArrayInlineExpression, asg: &AsgArrayInlineExpression, - ) -> Result { + ) -> Result { let mut elements = vec![]; for (ast_element, asg_element) in ast.elements.iter().zip(asg.elements.iter()) { let reduced_element = match ast_element { @@ -242,7 +243,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstArrayRangeAccessExpression, asg: &AsgArrayRangeAccessExpression, - ) -> Result { + ) -> Result { let array = self.reduce_expression(&ast.array, asg.array.get())?; let left = match (ast.left.as_ref(), asg.left.get()) { (Some(ast_left), Some(asg_left)) => Some(self.reduce_expression(ast_left, asg_left)?), @@ -260,7 +261,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstBinaryExpression, asg: &AsgBinaryExpression, - ) -> Result { + ) -> Result { let left = self.reduce_expression(&ast.left, asg.left.get())?; let right = self.reduce_expression(&ast.right, asg.right.get())?; @@ -271,7 +272,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstCallExpression, asg: &AsgCallExpression, - ) -> Result { + ) -> Result { // TODO FIGURE IT OUT // let function = self.reduce_expression(&ast.function, asg.function.get())?; // let target = asg.target.get().map(|exp| self.reduce_expression()) @@ -289,7 +290,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstCastExpression, asg: &AsgCastExpression, - ) -> Result { + ) -> Result { let inner = self.reduce_expression(&ast.inner, &asg.inner.get())?; let target_type = self.reduce_type(&ast.target_type, &asg.target_type, &ast.span)?; @@ -300,7 +301,7 @@ impl CombineAstAsgDirector { &mut self, ast: &ValueExpression, _asg: &AsgConstant, - ) -> Result { + ) -> Result { // TODO REDUCE GV // Is this needed? let new = match ast { @@ -317,7 +318,7 @@ impl CombineAstAsgDirector { &mut self, ast: &CircuitMemberAccessExpression, _asg: &AsgCircuitAccessExpression, - ) -> Result { + ) -> Result { // TODO FIGURE IT OUT // let circuit = self.reduce_expression(&circuit_member_access.circuit)?; // let name = self.reduce_identifier(&circuit_member_access.name)?; @@ -332,7 +333,7 @@ impl CombineAstAsgDirector { &mut self, ast: &CircuitStaticFunctionAccessExpression, _asg: &AsgCircuitAccessExpression, - ) -> Result { + ) -> Result { // TODO FIGURE IT OUT // let circuit = self.reduce_expression(&circuit_member_access.circuit)?; // let name = self.reduce_identifier(&circuit_member_access.name)?; @@ -347,7 +348,7 @@ impl CombineAstAsgDirector { &mut self, ast: &CircuitImpliedVariableDefinition, asg: &AsgExpression, - ) -> Result { + ) -> Result { let expression = ast .expression .as_ref() @@ -362,7 +363,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstCircuitInitExpression, asg: &AsgCircuitInitExpression, - ) -> Result { + ) -> Result { let mut members = vec![]; for (ast_member, asg_member) in ast.members.iter().zip(asg.values.iter()) { members.push(self.reduce_circuit_implied_variable_definition(ast_member, asg_member.1.get())?); @@ -375,7 +376,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstTernaryExpression, asg: &AsgTernaryExpression, - ) -> Result { + ) -> Result { let condition = self.reduce_expression(&ast.condition, asg.condition.get())?; let if_true = self.reduce_expression(&ast.if_true, asg.if_true.get())?; let if_false = self.reduce_expression(&ast.if_false, asg.if_false.get())?; @@ -387,7 +388,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstTupleAccessExpression, asg: &AsgTupleAccessExpression, - ) -> Result { + ) -> Result { let tuple = self.reduce_expression(&ast.tuple, asg.tuple_ref.get())?; self.ast_reducer.reduce_tuple_access(ast, tuple) @@ -397,7 +398,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstTupleInitExpression, asg: &AsgTupleInitExpression, - ) -> Result { + ) -> Result { let mut elements = vec![]; for (ast_element, asg_element) in ast.elements.iter().zip(asg.elements.iter()) { let element = self.reduce_expression(ast_element, asg_element.get())?; @@ -411,7 +412,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstUnaryExpression, asg: &AsgUnaryExpression, - ) -> Result { + ) -> Result { let inner = self.reduce_expression(&ast.inner, asg.inner.get())?; self.ast_reducer.reduce_unary(ast, inner, ast.op.clone()) @@ -421,7 +422,7 @@ impl CombineAstAsgDirector { &mut self, ast: &ValueExpression, _asg: &AsgVariableRef, - ) -> Result { + ) -> Result { // TODO FIGURE IT OUT let new = match ast { // ValueExpression::Group(group_value) => { @@ -438,7 +439,7 @@ impl CombineAstAsgDirector { &mut self, ast_statement: &AstStatement, asg_statement: &AsgStatement, - ) -> Result { + ) -> Result { let new = match (ast_statement, asg_statement) { (AstStatement::Assign(ast), AsgStatement::Assign(asg)) => { AstStatement::Assign(self.reduce_assign(ast, asg)?) @@ -472,7 +473,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstAssignAccess, asg: &AsgAssignAccess, - ) -> Result { + ) -> Result { let new = match (ast, asg) { (AstAssignAccess::ArrayRange(ast_left, ast_right), AsgAssignAccess::ArrayRange(asg_left, asg_right)) => { let left = match (ast_left.as_ref(), asg_left.get()) { @@ -496,7 +497,7 @@ impl CombineAstAsgDirector { self.ast_reducer.reduce_assignee_access(ast, new) } - pub fn reduce_assignee(&mut self, ast: &Assignee, asg: &[AsgAssignAccess]) -> Result { + pub fn reduce_assignee(&mut self, ast: &Assignee, asg: &[AsgAssignAccess]) -> Result { let mut accesses = vec![]; for (ast_access, asg_access) in ast.accesses.iter().zip(asg) { accesses.push(self.reduce_assign_access(ast_access, asg_access)?); @@ -509,7 +510,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstAssignStatement, asg: &AsgAssignStatement, - ) -> Result { + ) -> Result { let assignee = self.reduce_assignee(&ast.assignee, &asg.target_accesses)?; let value = self.reduce_expression(&ast.value, asg.value.get())?; @@ -520,7 +521,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstBlockStatement, asg: &AsgBlockStatement, - ) -> Result { + ) -> Result { let mut statements = vec![]; for (ast_statement, asg_statement) in ast.statements.iter().zip(asg.statements.iter()) { statements.push(self.reduce_statement(ast_statement, asg_statement.get())?); @@ -533,14 +534,15 @@ impl CombineAstAsgDirector { &mut self, ast: &AstConditionalStatement, asg: &AsgConditionalStatement, - ) -> Result { + ) -> Result { let condition = self.reduce_expression(&ast.condition, asg.condition.get())?; let block; if let AsgStatement::Block(asg_block) = asg.result.get() { block = self.reduce_block(&ast.block, asg_block)?; } else { - // TODO throw error? - block = ast.block.clone(); + return Err(ReducerError::from(CombinerError::asg_statement_not_block( + &asg.span.as_ref().unwrap(), + ))); } let next = match (ast.next.as_ref(), asg.next.get()) { (Some(ast_next), Some(asg_next)) => Some(self.reduce_statement(ast_next, asg_next)?), @@ -554,7 +556,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstConsoleStatement, asg: &AsgConsoleStatement, - ) -> Result { + ) -> Result { let function = match (&ast.function, &asg.function) { (AstConsoleFunction::Assert(ast_expression), AsgConsoleFunction::Assert(asg_expression)) => { AstConsoleFunction::Assert(self.reduce_expression(&ast_expression, asg_expression.get())?) @@ -577,7 +579,7 @@ impl CombineAstAsgDirector { AstConsoleFunction::Debug(_) => AstConsoleFunction::Debug(formatted), AstConsoleFunction::Error(_) => AstConsoleFunction::Error(formatted), AstConsoleFunction::Log(_) => AstConsoleFunction::Log(formatted), - _ => unimplemented!(), // impossible + _ => return Err(ReducerError::impossible_console_assert_call(&ast_format.span)), } } _ => ast.function.clone(), @@ -590,7 +592,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstDefinitionStatement, asg: &AsgDefinitionStatement, - ) -> Result { + ) -> Result { let type_; if asg.variables.len() > 1 { @@ -628,7 +630,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstExpressionStatement, asg: &AsgExpressionStatement, - ) -> Result { + ) -> Result { let inner_expression = self.reduce_expression(&ast.expression, asg.expression.get())?; self.ast_reducer.reduce_expression_statement(ast, inner_expression) } @@ -637,14 +639,16 @@ impl CombineAstAsgDirector { &mut self, ast: &AstIterationStatement, asg: &AsgIterationStatement, - ) -> Result { + ) -> Result { let start = self.reduce_expression(&ast.start, asg.start.get())?; let stop = self.reduce_expression(&ast.stop, asg.stop.get())?; let block; if let AsgStatement::Block(asg_block) = asg.body.get() { block = self.reduce_block(&ast.block, asg_block)?; } else { - block = ast.block.clone(); + return Err(ReducerError::from(CombinerError::asg_statement_not_block( + &asg.span.as_ref().unwrap(), + ))); } self.ast_reducer @@ -655,7 +659,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstReturnStatement, asg: &AsgReturnStatement, - ) -> Result { + ) -> Result { let expression = self.reduce_expression(&ast.expression, asg.expression.get())?; self.ast_reducer.reduce_return(ast, expression) @@ -665,7 +669,7 @@ impl CombineAstAsgDirector { &mut self, ast: &leo_ast::Program, asg: &leo_asg::Program, - ) -> Result { + ) -> Result { self.ast_reducer.swap_in_circuit(); let mut circuits = IndexMap::new(); for ((ast_ident, ast_circuit), (_asg_ident, asg_circuit)) in ast.circuits.iter().zip(&asg.circuits) { @@ -687,7 +691,7 @@ impl CombineAstAsgDirector { ) } - pub fn reduce_function(&mut self, ast: &AstFunction, asg: &AsgFunction) -> Result { + pub fn reduce_function(&mut self, ast: &AstFunction, asg: &AsgFunction) -> Result { let output = ast .output .as_ref() @@ -720,7 +724,7 @@ impl CombineAstAsgDirector { &mut self, ast: &AstCircuitMember, asg: &AsgCircuitMember, - ) -> Result { + ) -> Result { let new = match (ast, asg) { (AstCircuitMember::CircuitVariable(identifier, ast_type), AsgCircuitMember::Variable(asg_type)) => { AstCircuitMember::CircuitVariable( @@ -737,7 +741,7 @@ impl CombineAstAsgDirector { self.ast_reducer.reduce_circuit_member(ast, new) } - pub fn reduce_circuit(&mut self, ast: &AstCircuit, asg: &AsgCircuit) -> Result { + pub fn reduce_circuit(&mut self, ast: &AstCircuit, asg: &AsgCircuit) -> Result { let mut members = vec![]; for (ast_member, asg_member) in ast.members.iter().zip(asg.members.borrow().iter()) { members.push(self.reduce_circuit_member(ast_member, asg_member.1)?);