Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
d0cd committed Oct 13, 2023
1 parent 8ba2cab commit 1631dd6
Show file tree
Hide file tree
Showing 16 changed files with 19 additions and 92 deletions.
1 change: 0 additions & 1 deletion compiler/passes/src/code_generation/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use leo_ast::{Function, Program, ProgramId};
use leo_span::Symbol;

use indexmap::IndexMap;
use snarkvm_console::program::Access;

pub struct CodeGenerator<'a> {
/// The symbol table for the program.
Expand Down
2 changes: 1 addition & 1 deletion compiler/passes/src/code_generation/visit_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl<'a> CodeGenerator<'a> {
Some(Type::Array(array_type)) => Type::Array(array_type),
_ => unreachable!("All types should be known at this phase of compilation"),
};
let array_type: String = self.visit_type(&array_type);
let array_type: String = Self::visit_type(&array_type);

let array_instruction =
format!(" cast {expression_operands} into {destination_register} as {};\n", array_type);
Expand Down
4 changes: 2 additions & 2 deletions compiler/passes/src/code_generation/visit_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl<'a> CodeGenerator<'a> {

// Construct and append the record variables.
for var in struct_.members.iter() {
writeln!(output_string, " {} as {};", var.identifier, self.visit_type(&var.type_),)
writeln!(output_string, " {} as {};", var.identifier, Self::visit_type(&var.type_),)
.expect("failed to write to string");
}

Expand All @@ -154,7 +154,7 @@ impl<'a> CodeGenerator<'a> {
output_string,
" {} as {}.{mode};", // todo: CAUTION private record variables only.
var.identifier,
self.visit_type(&var.type_)
Self::visit_type(&var.type_)
)
.expect("failed to write to string");
}
Expand Down
11 changes: 6 additions & 5 deletions compiler/passes/src/code_generation/visit_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::CodeGenerator;
use leo_ast::{Mode, Type};

impl<'a> CodeGenerator<'a> {
pub(crate) fn visit_type(&mut self, input: &Type) -> String {
pub(crate) fn visit_type(input: &Type) -> String {
match input {
Type::Address
| Type::Boolean
Expand All @@ -31,7 +31,8 @@ impl<'a> CodeGenerator<'a> {
| Type::Identifier(..)
| Type::Integer(..) => format!("{input}"),
Type::Array(array_type) => {
format!("[{}; {}u32]", self.visit_type(&array_type.element_type()), array_type.length())
let element_type = Self::visit_type(array_type.element_type());
format!("[{element_type}; {}u32]", array_type.length())
}
Type::Mapping(_) => {
unreachable!("Mapping types are not supported at this phase of compilation")
Expand All @@ -44,16 +45,16 @@ impl<'a> CodeGenerator<'a> {
}
}

pub(crate) fn visit_type_with_visibility(&mut self, type_: &'a Type, visibility: Mode) -> String {
pub(crate) fn visit_type_with_visibility(&self, type_: &'a Type, visibility: Mode) -> String {
match type_ {
// When the type is a record.
// Note that this unwrap is safe because all composite types have been added to the mapping.
Type::Identifier(identifier) if self.composite_mapping.get(&identifier.name).unwrap().0 => {
format!("{identifier}.record")
}
_ => match visibility {
Mode::None => self.visit_type(type_),
_ => format!("{}.{visibility}", self.visit_type(type_)),
Mode::None => Self::visit_type(type_),
_ => format!("{}.{visibility}", Self::visit_type(type_)),
},
}
}
Expand Down
5 changes: 1 addition & 4 deletions compiler/passes/src/common/type_table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
use leo_ast::{NodeID, Type};

use indexmap::IndexMap;
use std::{
cell::{Ref, RefCell},
fmt::Display,
};
use std::cell::RefCell;

/// A mapping between node IDs and their types.
#[derive(Debug, Default, Clone)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ use crate::DeadCodeEliminator;

use leo_ast::{
AccessExpression,
ArrayAccess,
AssociatedFunction,
Expression,
ExpressionReconstructor,
Identifier,
MemberAccess,
StructExpression,
StructVariableInitializer,
TupleAccess,
Type,
};
use leo_span::sym;
Expand Down
18 changes: 1 addition & 17 deletions compiler/passes/src/destructuring/destructure_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,8 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.

use crate::Destructurer;
use itertools::Itertools;

use leo_ast::{
AccessExpression,
ArrayAccess,
AssociatedFunction,
Expression,
ExpressionReconstructor,
Member,
MemberAccess,
Node,
Statement,
StructExpression,
StructVariableInitializer,
TernaryExpression,
TupleAccess,
Type,
};
use leo_ast::{Expression, ExpressionReconstructor, Statement, TupleAccess};

impl ExpressionReconstructor for Destructurer<'_> {
type AdditionalOutput = Vec<Statement>;
Expand Down
2 changes: 1 addition & 1 deletion compiler/passes/src/destructuring/destructure_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

use crate::Destructurer;

use leo_ast::{Finalize, Function, ProgramReconstructor, StatementReconstructor, Type};
use leo_ast::ProgramReconstructor;

impl ProgramReconstructor for Destructurer<'_> {}
10 changes: 0 additions & 10 deletions compiler/passes/src/destructuring/destructure_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,9 @@

use crate::Destructurer;
use itertools::Itertools;
use std::borrow::Borrow;

use leo_ast::{
AccessExpression,
AssertStatement,
AssertVariant,
AssignStatement,
AssociatedFunction,
BinaryExpression,
BinaryOperation,
Block,
ConditionalStatement,
ConsoleStatement,
Expand All @@ -40,10 +33,7 @@ use leo_ast::{
StatementReconstructor,
TupleExpression,
Type,
UnaryExpression,
UnaryOperation,
};
use leo_span::sym;

impl StatementReconstructor for Destructurer<'_> {
/// Flattens an assign statement, if necessary.
Expand Down
32 changes: 2 additions & 30 deletions compiler/passes/src/destructuring/destructurer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.

use crate::{Assigner, SymbolTable, TypeTable};
use crate::{Assigner, TypeTable};

use leo_ast::{
AccessExpression,
ArrayAccess,
ArrayExpression,
ArrayType,
BinaryExpression,
BinaryOperation,
Block,
Expression,
ExpressionReconstructor,
Identifier,
IntegerType,
Literal,
Member,
MemberAccess,
Node,
NodeBuilder,
NonzeroNumber,
ReturnStatement,
Statement,
Struct,
StructExpression,
StructVariableInitializer,
TernaryExpression,
TupleAccess,
TupleExpression,
TupleType,
Type,
};
use leo_ast::{Expression, Identifier, Node, NodeBuilder, Statement, TupleExpression};
use leo_span::Symbol;

use indexmap::IndexMap;
Expand Down
2 changes: 1 addition & 1 deletion compiler/passes/src/destructuring/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod destructure_statement;
pub mod destructurer;
pub use destructurer::*;

use crate::{Assigner, Pass, SymbolTable, TypeTable};
use crate::{Assigner, Pass, TypeTable};

use leo_ast::{Ast, NodeBuilder, ProgramReconstructor};
use leo_errors::Result;
Expand Down
7 changes: 0 additions & 7 deletions compiler/passes/src/flattening/flatten_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,15 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.

use crate::Flattener;
use itertools::Itertools;

use leo_ast::{
AccessExpression,
ArrayAccess,
AssociatedFunction,
Expression,
ExpressionReconstructor,
Member,
MemberAccess,
Node,
Statement,
StructExpression,
StructVariableInitializer,
TernaryExpression,
TupleAccess,
Type,
};

Expand Down
2 changes: 1 addition & 1 deletion compiler/passes/src/flattening/flatten_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use crate::Flattener;

use leo_ast::{Finalize, Function, ProgramReconstructor, StatementReconstructor, Type};
use leo_ast::{Finalize, Function, ProgramReconstructor, StatementReconstructor};

impl ProgramReconstructor for Flattener<'_> {
/// Flattens a function's body and finalize block, if it exists.
Expand Down
8 changes: 1 addition & 7 deletions compiler/passes/src/flattening/flatten_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@

use crate::Flattener;
use itertools::Itertools;
use std::borrow::Borrow;

use leo_ast::{
AccessExpression,
AssertStatement,
AssertVariant,
AssignStatement,
AssociatedFunction,
BinaryExpression,
BinaryOperation,
Block,
Expand All @@ -32,18 +29,15 @@ use leo_ast::{
DefinitionStatement,
Expression,
ExpressionReconstructor,
Identifier,
IterationStatement,
Node,
ReturnStatement,
Statement,
StatementReconstructor,
TupleExpression,
Type,
UnaryExpression,
UnaryOperation,
};
use leo_span::sym;

impl StatementReconstructor for Flattener<'_> {
/// Rewrites an assert statement into a flattened form.
Expand Down Expand Up @@ -172,7 +166,7 @@ impl StatementReconstructor for Flattener<'_> {
/// Otherwise, the statement is returned as is.
fn reconstruct_assign(&mut self, assign: AssignStatement) -> (Statement, Self::AdditionalOutput) {
// Flatten the rhs of the assignment.
let (value, mut statements) = self.reconstruct_expression(assign.value);
let (value, statements) = self.reconstruct_expression(assign.value);
match (assign.place, &value) {
(Expression::Identifier(identifier), _) => (self.simple_assign_statement(identifier, value), statements),
(Expression::Tuple(tuple), expression) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use crate::{Assigner, RenameTable, SymbolTable, TypeTable};

use leo_ast::{AssignStatement, Expression, Identifier, Node, NodeBuilder, Statement};
use leo_ast::{Expression, Identifier, Node, NodeBuilder, Statement};

pub struct StaticSingleAssigner<'a> {
/// A counter used to generate unique node IDs.
Expand Down
2 changes: 1 addition & 1 deletion compiler/passes/src/type_checking/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use crate::{CallGraph, StructGraph, SymbolTable, TypeTable};

use leo_ast::{ArrayType, CoreConstant, CoreFunction, Identifier, IntegerType, MappingType, Node, Type, Variant};
use leo_ast::{CoreConstant, CoreFunction, Identifier, IntegerType, MappingType, Node, Type, Variant};
use leo_errors::{emitter::Handler, TypeCheckerError};
use leo_span::{Span, Symbol};

Expand Down

0 comments on commit 1631dd6

Please sign in to comment.