Skip to content

Commit

Permalink
Add temporary local for array creation
Browse files Browse the repository at this point in the history
The local is used as the array index, although is constant
  • Loading branch information
JulianGCalderon committed Apr 24, 2024
1 parent d7ae83e commit 308010c
Showing 1 changed file with 70 additions and 2 deletions.
72 changes: 70 additions & 2 deletions crates/concrete_ir/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,17 +974,85 @@ fn lower_expression(
kind: StatementKind::StorageLive(array_local),
});

let first_idx_local = {
let idx_kind = TyKind::Uint(UintTy::U64);

let first_idx_local = builder.add_temp_local(idx_kind.clone());
builder.statements.push(Statement {
span: None,
kind: StatementKind::StorageLive(first_idx_local),
});

let first_idx_place = Place {
local: first_idx_local,
projection: Default::default(),
};

builder.statements.push(Statement {
span: None,
kind: StatementKind::Assign(
first_idx_place,
Rvalue::Use(Operand::Const(ConstData {
ty: Ty {
span: None,
kind: idx_kind,
},
data: ConstKind::Value(ValueTree::Leaf(ConstValue::U64(
first_idx as u64,
))),
})),
),
});

first_idx_local
};

let mut first_place = place.clone();
first_place.projection.push(PlaceElem::Index(first_idx));
first_place
.projection
.push(PlaceElem::Index(first_idx_local));

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

for (idx, element) in values {
let idx_local = {
let idx_kind = TyKind::Uint(UintTy::U64);

let idx_local = builder.add_temp_local(idx_kind.clone());
builder.statements.push(Statement {
span: None,
kind: StatementKind::StorageLive(first_idx_local),
});

let idx_place = Place {
local: first_idx_local,
projection: Default::default(),
};

builder.statements.push(Statement {
span: None,
kind: StatementKind::Assign(
idx_place,
Rvalue::Use(Operand::Const(ConstData {
ty: Ty {
span: None,
kind: idx_kind,
},
data: ConstKind::Value(ValueTree::Leaf(ConstValue::U64(
idx as u64,
))),
})),
),
});

idx_local
};

let mut element_place = place.clone();
element_place.projection.push(PlaceElem::Index(idx));
element_place.projection.push(PlaceElem::Index(idx_local));

let (value, _value_ty, _field_span) =
lower_expression(builder, element, Some(element_type.clone()))?;
Expand Down

0 comments on commit 308010c

Please sign in to comment.