Skip to content

Commit

Permalink
Add reference to constant in function body
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianGCalderon committed May 9, 2024
1 parent 478c64d commit b2f12bd
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion crates/concrete_ir/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,29 @@ fn lower_value_expr(
ValueExpr::ConstStr(_, _) => todo!(),
ValueExpr::Path(info) => match lower_path(builder, info) {
Ok((place, place_ty, _span)) => (Rvalue::Use(Operand::Place(place.clone())), place_ty),
Err(err @ LoweringError::UseOfUndeclaredVariable { .. }) => return Err(err),
Err(err @ LoweringError::UseOfUndeclaredVariable { .. }) => {
let mod_body = builder.get_module_body();

let constant_id =
if let Some(constant_id) = mod_body.symbols.constants.get(&info.first.name) {
*constant_id
} else {
return Err(err);
};

let constant_value = builder
.ctx
.body
.constants
.get(&constant_id)
.expect("constant should exist")
.value
.clone();

let ty = constant_value.ty.clone();

(Rvalue::Use(Operand::Const(constant_value)), ty)
}
Err(err) => return Err(err),
},
})
Expand Down

0 comments on commit b2f12bd

Please sign in to comment.