Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Arrays. #2888

Merged
merged 51 commits into from
Oct 27, 2023
Merged
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
3fda5aa
Introduce Array type
d0cd Oct 7, 2023
25b7d5c
Rename types::Tuple to types::TupleType
d0cd Oct 7, 2023
c3b92d1
Add Array type to Type
d0cd Oct 7, 2023
0792191
Add test cases
d0cd Oct 8, 2023
d8a7f74
Add support for parsing the array type
d0cd Oct 8, 2023
e372710
Introduce ArrayExpression
d0cd Oct 8, 2023
5f75ae8
Support array expressions in AST and visitors
d0cd Oct 8, 2023
f189531
Stubs for arrays in passes
d0cd Oct 8, 2023
c94acde
Support array access expressions in AST and visitors
d0cd Oct 8, 2023
eb420b6
Stubs for arrays access expressions in passes
d0cd Oct 8, 2023
2edc7aa
Parse array access expressions
d0cd Oct 8, 2023
13e1704
Parse array init expressions
d0cd Oct 8, 2023
22766a4
Fix test cases
d0cd Oct 8, 2023
7e471b7
Add type checking for arrays
d0cd Oct 9, 2023
072ab7b
Change PositiveNumber to NonzeroNumber
d0cd Oct 9, 2023
5b2e73d
Refactor TupleTyple
d0cd Oct 10, 2023
d3209da
Cleanup
d0cd Oct 10, 2023
4b9a96e
Update passes
d0cd Oct 10, 2023
82ad245
WIP flattening
d0cd Oct 10, 2023
7e5a6e9
WIP flattening for arrays
d0cd Oct 10, 2023
d1a5283
WIP
d0cd Oct 10, 2023
2fc1557
Add the type map to the symbol table
d0cd Oct 11, 2023
621a2f2
Add expressions to the type map
d0cd Oct 11, 2023
a3446d3
Introduce TypeTable
d0cd Oct 11, 2023
93aca5c
Ensure type consistency in SSA pass
d0cd Oct 11, 2023
3e59672
Cleanup
d0cd Oct 11, 2023
edcc1a6
Update RenameTable
d0cd Oct 11, 2023
c193b1d
Ensure type consistency during loop unrolling
d0cd Oct 11, 2023
6455055
Ensure type consistency during function inlining
d0cd Oct 11, 2023
17cdda2
Refactor TypeTable
d0cd Oct 12, 2023
3b72000
Update SSA pass
d0cd Oct 12, 2023
b36966d
Clean up passes
d0cd Oct 12, 2023
f494a89
Add TypeTable to compiler
d0cd Oct 12, 2023
cacc215
Update flattener
d0cd Oct 12, 2023
992f0b8
Redesign flattening
d0cd Oct 13, 2023
b1096f1
Introduce destructuring pass
d0cd Oct 13, 2023
a3c0892
Add Destructuring pass to the compiler
d0cd Oct 13, 2023
8ca1de3
Refactor Reconstructor
d0cd Oct 13, 2023
08d3997
Update TYC
d0cd Oct 13, 2023
044933c
Update loop unrolling
d0cd Oct 13, 2023
c80aee0
Update DCE
d0cd Oct 13, 2023
49a0c7a
Support codegen for arrays
d0cd Oct 13, 2023
144ef44
Update errors
d0cd Oct 13, 2023
630508c
Update tests
d0cd Oct 13, 2023
6756320
Regen expectations
d0cd Oct 20, 2023
59dfeb9
Regen expectations
d0cd Oct 13, 2023
0dcd156
Cleanup
d0cd Oct 13, 2023
b3c1723
Add tests and fixes
d0cd Oct 17, 2023
34f2dd6
Clippy
d0cd Oct 17, 2023
bdd0f78
Regen expectations
d0cd Oct 20, 2023
54566c0
Regen expectations
d0cd Oct 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update loop unrolling
d0cd committed Oct 27, 2023
commit 044933c0fbdd84468462ec18d9edf77454c7c07d
20 changes: 20 additions & 0 deletions compiler/passes/src/loop_unrolling/unroll_expression.rs
Original file line number Diff line number Diff line change
@@ -15,12 +15,32 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.

use leo_ast::*;
use leo_errors::LoopUnrollerError;

use crate::Unroller;

impl ExpressionReconstructor for Unroller<'_> {
type AdditionalOutput = bool;

fn reconstruct_array_access(&mut self, input: ArrayAccess) -> (Expression, Self::AdditionalOutput) {
// Reconstruct the index.
let index = self.reconstruct_expression(*input.index).0;
// If the index is not a literal, then emit an error.
if !matches!(index, Expression::Literal(_)) {
self.emit_err(LoopUnrollerError::variable_array_access(input.span));
}

(
Expression::Access(AccessExpression::Array(ArrayAccess {
array: Box::new(self.reconstruct_expression(*input.array).0),
index: Box::new(index),
span: input.span,
id: input.id,
})),
Default::default(),
)
}

fn reconstruct_identifier(&mut self, input: Identifier) -> (Expression, Self::AdditionalOutput) {
// Substitute the identifier with the constant value if it is a constant.
if let Some(expr) = self.constant_propagation_table.borrow().lookup_constant(input.name) {