Skip to content

Commit

Permalink
Add simple comments explaining the array init
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianGCalderon committed Apr 26, 2024
1 parent 3c18e15 commit 62d1257
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions crates/concrete_ir/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,7 @@ fn lower_expression(

let mut values = info.values.iter().enumerate();

// Extract the first value from the array init. It's type will be used as type hint for the following elements.
let (first_idx, first_element) = values.next().expect("array init cannot be empty");
let (first_value, element_type, _element_span) =
lower_expression(builder, first_element, element_type_hint)?;
Expand All @@ -1084,28 +1085,28 @@ fn lower_expression(
),
};

// Create and init local for the array init expression.
let array_local = builder.add_local(Local::temp(ty.clone()));

let place = Place {
local: array_local,
projection: Default::default(),
};

builder.statements.push(Statement {
span: None,
kind: StatementKind::StorageLive(array_local),
});

// Assign the first value of the expression
let mut first_place = place.clone();
first_place
.projection
.push(PlaceElem::ConstantIndex(first_idx as u64));

builder.statements.push(Statement {
span: Some(info.span),
kind: StatementKind::Assign(first_place, first_value),
});

// Loop over the remaining values and assign them
for (idx, element) in values {
let mut element_place = place.clone();
element_place
Expand Down

0 comments on commit 62d1257

Please sign in to comment.