From 308010cf5b429d10e2fcf3d5499a2e9325268194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Wed, 24 Apr 2024 10:49:28 -0300 Subject: [PATCH] Add temporary local for array creation The local is used as the array index, although is constant --- crates/concrete_ir/src/lowering.rs | 72 +++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/crates/concrete_ir/src/lowering.rs b/crates/concrete_ir/src/lowering.rs index 1fcf72d..424c685 100644 --- a/crates/concrete_ir/src/lowering.rs +++ b/crates/concrete_ir/src/lowering.rs @@ -974,8 +974,43 @@ 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), @@ -983,8 +1018,41 @@ fn lower_expression( }); 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()))?;