cairo-lang-lowering 2.4.1

Cairo lowering phase.
Documentation
//! > Test calling trait function.

//! > test_runner_name
test_function_lowering

//! > function
fn foo() {
    immovable(5.foo(true));
    immovable(MyTrait::foo(6, false));
}

//! > function_name
foo

//! > module_code
trait MyTrait<T> {
    fn foo<S>(self: T, y: S) -> (T, S);
}
impl MyImpl of MyTrait::<felt252> {
    #[inline(always)]
    fn foo<S>(self: felt252, y: S) -> (felt252, S) {
        (self, y)
    }
}

extern fn immovable<T>(t: T) -> T nopanic;

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:
blk0 (root):
Statements:
  (v0: core::felt252) <- 5u
  (v1: ()) <- struct_construct()
  (v2: core::bool) <- bool::True(v1)
  (v13: (core::felt252, core::bool)) <- struct_construct(v0, v2)
  (v4: core::felt252, v5: core::bool) <- test::immovable::<(core::felt252, core::bool)>(v13)
  (v6: core::felt252) <- 6u
  (v7: ()) <- struct_construct()
  (v8: core::bool) <- bool::False(v7)
  (v14: (core::felt252, core::bool)) <- struct_construct(v6, v8)
  (v10: core::felt252, v11: core::bool) <- test::immovable::<(core::felt252, core::bool)>(v14)
  (v12: ()) <- struct_construct()
End:
  Return(v12)

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

//! > Test generic structs.

//! > test_runner_name
test_function_lowering

//! > function
fn foo() -> felt252 {
  let q = Query { data: 1 };
  let Query { data } = q;
  Query { data: 2 }.data + data
}

//! > function_name
foo

//! > module_code
struct Query<V> {
  data: V,
}

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:
blk0 (root):
Statements:
  (v0: core::felt252) <- 1u
  (v1: test::Query::<core::felt252>) <- struct_construct(v0)
  (v2: core::felt252) <- struct_destructure(v1)
  (v3: core::felt252) <- 2u
  (v4: test::Query::<core::felt252>) <- struct_construct(v3)
  (v5: core::felt252) <- struct_destructure(v4)
  (v7: core::felt252) <- core::felt252_add(v5, v2)
End:
  Return(v7)

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

//! > Test generic impls.

//! > test_runner_name
test_function_lowering

//! > function
fn foo() {
  bar::<MyImpl>()
}

//! > function_name
foo

//! > module_code
fn bar<impl Imp: MyTrait>(){Imp::foo()}
trait MyTrait {
  fn foo();
}
impl MyImpl of MyTrait {
  fn foo(){}
}

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:
blk0 (root):
Statements:
  (v1: ()) <- test::MyImpl::foo()
End:
  Return(v1)

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

//! > Test generic impls for type info.

//! > test_runner_name
test_function_lowering

//! > function
fn foo() {
  MyTrait::bar(5);
}

//! > function_name
foo

//! > module_code
trait MyTrait<T> {
  fn bar(x: T);
}
impl MyImpl<T, impl TDrop: Drop::<T>> of MyTrait::<T> {
  fn bar(x: T){}
}

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:
blk0 (root):
Statements:
  (v0: core::felt252) <- 5u
  (v1: ()) <- test::MyImpl::<core::felt252, core::felt252Drop>::bar(v0)
  (v2: ()) <- struct_construct()
End:
  Return(v2)