Skip to content

Commit

Permalink
Abstract to function lower_constant_ref
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianGCalderon committed May 10, 2024
1 parent c3c8aee commit 350d3f6
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions crates/concrete_ir/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1636,33 +1636,41 @@ fn lower_value_expr(
let (place, place_ty, _span) = lower_path(builder, info)?;
(Rvalue::Use(Operand::Place(place.clone())), place_ty)
} else {
let mod_body = builder.get_module_body();

let Some(&constant_id) = mod_body.symbols.constants.get(&info.first.name) else {
return Err(LoweringError::UseOfUndeclaredVariable {
span: info.span,
name: info.first.name.clone(),
program_id: builder.local_module.program_id,
});
};

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

let ty = constant_value.ty.clone();

let (constant_value, ty) = lower_constant_ref(builder, info)?;
(Rvalue::Use(Operand::Const(constant_value)), ty)
}
}
})
}

fn lower_constant_ref(
builder: &mut FnBodyBuilder,
info: &PathOp,
) -> Result<(ConstData, Ty), LoweringError> {
let mod_body = builder.get_module_body();

let Some(&constant_id) = mod_body.symbols.constants.get(&info.first.name) else {
return Err(LoweringError::UseOfUndeclaredVariable {
span: info.span,
name: info.first.name.clone(),
program_id: builder.local_module.program_id,
});
};

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

let ty = constant_value.ty.clone();

Ok((constant_value, ty))
}

pub fn lower_path(
builder: &mut FnBodyBuilder,
info: &PathOp,
Expand Down

0 comments on commit 350d3f6

Please sign in to comment.