Skip to content

Commit d85abdd

Browse files
committed
flow_control: Integrate the new code for simple boolean ifs.
commit-id:827e842e
1 parent e52fd15 commit d85abdd

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

crates/cairo-lang-lowering/src/lower/flow_control/create_graph.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ mod filtered_patterns;
1212
mod patterns;
1313

1414
/// Creates a graph node for [semantic::ExprIf].
15-
#[allow(dead_code)]
1615
pub fn create_graph_expr_if<'db>(
1716
ctx: &LoweringContext<'db, '_>,
1817
expr: &semantic::ExprIf<'db>,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
mod create_graph;
1+
pub mod create_graph;
22
mod graph;
3-
mod lower_graph;
3+
pub mod lower_graph;
44

55
#[cfg(test)]
66
mod graph_test;

crates/cairo-lang-lowering/src/lower/lower_if.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use semantic::{Condition, MatchArmSelector};
77

88
use super::block_builder::{BlockBuilder, SealedBlockBuilder};
99
use super::context::{LoweredExpr, LoweringContext, LoweringFlowError, LoweringResult};
10+
use super::flow_control::create_graph::create_graph_expr_if;
11+
use super::flow_control::lower_graph::lower_graph;
1012
use super::lowered_expr_to_block_scope_end;
1113
use crate::diagnostic::LoweringDiagnosticKind::{self};
1214
use crate::diagnostic::{LoweringDiagnosticsBuilder, MatchDiagnostic, MatchError, MatchKind};
@@ -44,6 +46,11 @@ pub fn lower_expr_if<'db>(
4446
builder: &mut BlockBuilder<'db>,
4547
expr: &semantic::ExprIf<'db>,
4648
) -> LoweringResult<'db, LoweredExpr<'db>> {
49+
if expr.conditions.len() == 1 && matches!(expr.conditions[0], Condition::BoolExpr(_)) {
50+
let graph = create_graph_expr_if(ctx, expr);
51+
return lower_graph(ctx, builder, &graph, ctx.get_location(expr.stable_ptr.untyped()));
52+
}
53+
4754
// Else block is not supported yet for multiple conditions.
4855
if expr.conditions.len() > 1 {
4956
if let Some(else_block) = expr.else_block {

0 commit comments

Comments
 (0)