From eb420b6544554e58611a13249cb86a7fb335b088 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu Date: Sun, 8 Oct 2023 11:27:47 -0400 Subject: [PATCH] Stubs for arrays access expressions in passes --- compiler/compiler/tests/utilities/check_unique_node_ids.rs | 5 +++++ compiler/passes/src/code_generation/visit_expressions.rs | 1 + .../src/dead_code_elimination/eliminate_expression.rs | 7 +++++++ compiler/passes/src/type_checking/check_expressions.rs | 1 + 4 files changed, 14 insertions(+) diff --git a/compiler/compiler/tests/utilities/check_unique_node_ids.rs b/compiler/compiler/tests/utilities/check_unique_node_ids.rs index 0debeb7554..09c9451e34 100644 --- a/compiler/compiler/tests/utilities/check_unique_node_ids.rs +++ b/compiler/compiler/tests/utilities/check_unique_node_ids.rs @@ -62,6 +62,11 @@ impl<'a> ExpressionVisitor<'a> for CheckUniqueNodeIds<'a> { fn visit_access(&mut self, input: &'a AccessExpression, _: &Self::AdditionalInput) -> Self::Output { match input { + AccessExpression::Array(ArrayAccess { array, index, id, .. }) => { + self.visit_expression(array, &Default::default()); + self.visit_expression(index, &Default::default()); + self.check(*id); + } AccessExpression::AssociatedConstant(AssociatedConstant { ty, name, id, .. }) => { self.check_ty(ty); self.visit_identifier(name, &Default::default()); diff --git a/compiler/passes/src/code_generation/visit_expressions.rs b/compiler/passes/src/code_generation/visit_expressions.rs index be41789068..d09a3c4216 100644 --- a/compiler/passes/src/code_generation/visit_expressions.rs +++ b/compiler/passes/src/code_generation/visit_expressions.rs @@ -492,6 +492,7 @@ impl<'a> CodeGenerator<'a> { fn visit_access(&mut self, input: &'a AccessExpression) -> (String, String) { match input { + AccessExpression::Array(array) => todo!(), AccessExpression::Member(access) => self.visit_member_access(access), AccessExpression::AssociatedConstant(constant) => self.visit_associated_constant(constant), AccessExpression::AssociatedFunction(function) => self.visit_associated_function(function), diff --git a/compiler/passes/src/dead_code_elimination/eliminate_expression.rs b/compiler/passes/src/dead_code_elimination/eliminate_expression.rs index b52d33145f..07117e2b11 100644 --- a/compiler/passes/src/dead_code_elimination/eliminate_expression.rs +++ b/compiler/passes/src/dead_code_elimination/eliminate_expression.rs @@ -18,6 +18,7 @@ use crate::DeadCodeEliminator; use leo_ast::{ AccessExpression, + ArrayAccess, AssociatedFunction, Expression, ExpressionReconstructor, @@ -37,6 +38,12 @@ impl ExpressionReconstructor for DeadCodeEliminator<'_> { fn reconstruct_access(&mut self, input: AccessExpression) -> (Expression, Self::AdditionalOutput) { ( Expression::Access(match input { + AccessExpression::Array(array) => AccessExpression::Array(ArrayAccess { + array: Box::new(self.reconstruct_expression(*array.array).0), + index: Box::new(self.reconstruct_expression(*array.index).0), + span: array.span, + id: array.id, + }), AccessExpression::AssociatedFunction(function) => { // If the associated function manipulates a mapping, mark the statement as necessary. match (&function.ty, function.name.name) { diff --git a/compiler/passes/src/type_checking/check_expressions.rs b/compiler/passes/src/type_checking/check_expressions.rs index 03771fed26..317068d8fb 100644 --- a/compiler/passes/src/type_checking/check_expressions.rs +++ b/compiler/passes/src/type_checking/check_expressions.rs @@ -42,6 +42,7 @@ impl<'a> ExpressionVisitor<'a> for TypeChecker<'a> { fn visit_access(&mut self, input: &'a AccessExpression, expected: &Self::AdditionalInput) -> Self::Output { match input { + AccessExpression::Array(array) => todo!(), AccessExpression::AssociatedFunction(access) => { // Check core struct name and function. if let Some(core_instruction) = self.get_core_function_call(&access.ty, &access.name) {