cairo-lang-lowering 2.17.0

Cairo lowering phase.
Documentation
//! > Test function call.

//! > test_runner_name
test_function_lowering(expect_diagnostics: false)

//! > function_code
fn foo(ref a: felt252) -> felt252 {
    let b = true;
    if true {
        bar(ref a, b);
    } else {}
    if false {
        return 6;
    } else {}
    5
}

//! > function_name
foo

//! > module_code
#[inline(never)]
fn bar(ref a: felt252, b: bool) {}

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v1: ()) <- struct_construct()
  (v2: core::bool) <- bool::True(v1)
  (v3: core::felt252) <- test::bar(v0, v2)
  (v4: core::felt252) <- 5
End:
  Return(v3, v4)

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

//! > Test method call.

//! > test_runner_name
test_function_lowering(expect_diagnostics: false)

//! > function_code
fn foo() -> Option<felt252> {
    let x = None;
    let _ = x.is_some();
    x
}

//! > function_name
foo

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:
blk0 (root):
Statements:
  (v0: ()) <- struct_construct()
  (v1: core::option::Option::<core::felt252>) <- Option::None(v0)
End:
  Return(v1)

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

//! > Test ref self method call on expression receiver.

//! > test_runner_name
test_function_lowering(expect_diagnostics: false)

//! > function_code
fn foo() -> u32 {
    // ref self method called on expression (not a variable) should work
    make_counter().increment()
}

//! > function_name
foo

//! > module_code
#[derive(Drop)]
struct Counter {
    value: u32,
}

trait CounterTrait {
    fn increment(ref self: Counter) -> u32;
}

impl CounterImpl of CounterTrait {
    #[inline(never)]
    fn increment(ref self: Counter) -> u32 {
        self.value += 1;
        self.value
    }
}

#[inline(never)]
fn make_counter() -> Counter {
    Counter { value: 0 }
}

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:
blk0 (root):
Statements:
  (v0: test::Counter) <- test::make_counter()
  (v1: core::panics::PanicResult::<(test::Counter, core::integer::u32)>) <- test::CounterImpl::increment(v0)
End:
  Match(match_enum(v1) {
    PanicResult::Ok(v2) => blk1,
    PanicResult::Err(v3) => blk2,
  })

blk1:
Statements:
  (v4: test::Counter, v5: core::integer::u32) <- struct_destructure(v2)
  (v6: (core::integer::u32,)) <- struct_construct(v5)
  (v7: core::panics::PanicResult::<(core::integer::u32,)>) <- PanicResult::Ok(v6)
End:
  Return(v7)

blk2:
Statements:
  (v8: core::panics::PanicResult::<(core::integer::u32,)>) <- PanicResult::Err(v3)
End:
  Return(v8)