cairo-lang-lowering 2.4.1

Cairo lowering phase.
Documentation
//! > Test boolean if.

//! > test_runner_name
test_function_lowering

//! > function
fn foo(a: bool, x: felt252) -> felt252 {
    if a {
        1
    } else {
        x
    }
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters: v0: core::bool, v1: core::felt252
blk0 (root):
Statements:
End:
  Match(match_enum(v0) {
    bool::False(v4) => blk1,
    bool::True(v2) => blk2,
  })

blk1:
Statements:
End:
  Goto(blk3, {v1 -> v5})

blk2:
Statements:
  (v3: core::felt252) <- 1u
End:
  Goto(blk3, {v3 -> v5})

blk3:
Statements:
End:
  Return(v5)

//! > ==========================================================================

//! > Test if analyzer.

//! > test_runner_name
test_function_lowering

//! > function
fn foo(x: felt252) -> felt252 {
    if x == 0 {
        1
    } else {
        x
    }
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
  Match(match core::felt252_is_zero(v0) {
    IsZeroResult::Zero => blk1,
    IsZeroResult::NonZero(v2) => blk2,
  })

blk1:
Statements:
  (v1: core::felt252) <- 1u
End:
  Goto(blk3, {v1 -> v3})

blk2:
Statements:
End:
  Goto(blk3, {v0 -> v3})

blk3:
Statements:
End:
  Return(v3)

//! > ==========================================================================

//! > Test if without else.

//! > test_runner_name
test_function_lowering

//! > function
fn foo(x: felt252) -> felt252 {
    if 0 == x {
        return 10;
    }
    20
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
  Match(match core::felt252_is_zero(v0) {
    IsZeroResult::Zero => blk1,
    IsZeroResult::NonZero(v2) => blk2,
  })

blk1:
Statements:
  (v1: core::felt252) <- 10u
End:
  Return(v1)

blk2:
Statements:
  (v3: core::felt252) <- 20u
End:
  Return(v3)

//! > ==========================================================================

//! > Test if x == y

//! > test_runner_name
test_function_lowering

//! > function
fn foo(x: felt252, y: felt252, z: felt252, w: felt252) -> felt252 {
    if x + y == z - w {
        0
    } else {
        1
    }
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters: v0: core::felt252, v1: core::felt252, v2: core::felt252, v3: core::felt252
blk0 (root):
Statements:
  (v11: core::felt252) <- core::felt252_add(v0, v1)
  (v12: core::felt252) <- core::felt252_sub(v2, v3)
  (v13: core::felt252) <- core::felt252_sub(v11, v12)
End:
  Match(match core::felt252_is_zero(v13) {
    IsZeroResult::Zero => blk1,
    IsZeroResult::NonZero(v8) => blk2,
  })

blk1:
Statements:
  (v7: core::felt252) <- 0u
End:
  Goto(blk3, {v7 -> v10})

blk2:
Statements:
  (v9: core::felt252) <- 1u
End:
  Goto(blk3, {v9 -> v10})

blk3:
Statements:
End:
  Return(v10)