//! > Test loop.
//! > test_runner_name
test_generated_function
//! > function
fn foo(y: felt252) -> felt252 {
let mut x = 5;
while x != 0 {
x = x - 1;
};
x
}
//! > function_name
foo
//! > module_code
//! > semantic_diagnostics
//! > lowering_diagnostics
//! > lowering_flat
Parameters:
//! > lowering
Main:
Parameters: v0: core::felt252
blk0 (root):
Statements:
(v1: core::felt252) <- 5
(v3: core::felt252, v2: ()) <- test::foo[expr12](v1)
End:
Return(v3)
Final lowering:
Parameters: v12: core::RangeCheck, v13: core::gas::GasBuiltin, v0: core::felt252
blk0 (root):
Statements:
(v1: core::felt252) <- 5
(v14: core::RangeCheck, v15: core::gas::GasBuiltin, v4: core::panics::PanicResult::<(core::felt252, ())>) <- test::foo[expr12](v12, v13, v1)
End:
Match(match_enum(v4) {
PanicResult::Ok(v5) => blk1,
PanicResult::Err(v8) => blk2,
})
blk1:
Statements:
(v6: core::felt252, v7: ()) <- struct_destructure(v5)
(v9: (core::felt252,)) <- struct_construct(v6)
(v10: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Ok(v9)
End:
Return(v14, v15, v10)
blk2:
Statements:
(v11: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v8)
End:
Return(v14, v15, v11)
Generated lowering for source location:
while x != 0 {
^************^
Parameters: v0: core::felt252
blk0 (root):
Statements:
(v1: core::felt252, v2: @core::felt252) <- snapshot(v0)
(v3: core::felt252) <- 0
(v4: core::felt252, v5: @core::felt252) <- snapshot(v3)
(v6: core::bool) <- core::Felt252PartialEq::ne(v2, v5)
End:
Match(match_enum(v6) {
bool::False(v12) => blk2,
bool::True(v7) => blk1,
})
blk1:
Statements:
(v8: core::felt252) <- 1
(v9: core::felt252) <- core::Felt252Sub::sub(v1, v8)
(v11: core::felt252, v10: ()) <- test::foo[expr12](v9)
End:
Goto(blk3, {v11 -> v14, v10 -> v13})
blk2:
Statements:
(v15: ()) <- struct_construct()
End:
Goto(blk3, {v1 -> v14, v15 -> v13})
blk3:
Statements:
End:
Return(v14, v13)
Final lowering:
Parameters: v43: core::RangeCheck, v44: core::gas::GasBuiltin, v0: core::felt252
blk0 (root):
Statements:
End:
Match(match core::gas::withdraw_gas(v43, v44) {
Option::Some(v45, v46) => blk1,
Option::None(v47, v48) => blk4,
})
blk1:
Statements:
End:
Match(match core::felt252_is_zero(v0) {
IsZeroResult::Zero => blk2,
IsZeroResult::NonZero(v34) => blk3,
})
blk2:
Statements:
(v15: ()) <- struct_construct()
(v26: (core::felt252, ())) <- struct_construct(v0, v15)
(v27: core::panics::PanicResult::<(core::felt252, ())>) <- PanicResult::Ok(v26)
End:
Return(v45, v46, v27)
blk3:
Statements:
(v8: core::felt252) <- 1
(v30: core::felt252) <- core::felt252_sub(v0, v8)
(v49: core::RangeCheck, v50: core::gas::GasBuiltin, v21: core::panics::PanicResult::<(core::felt252, ())>) <- test::foo[expr12](v45, v46, v30)
End:
Return(v49, v50, v21)
blk4:
Statements:
(v16: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
(v17: core::felt252) <- 375233589013918064796019
(v19: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v16, v17)
(v18: core::panics::Panic) <- struct_construct()
(v20: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v18, v19)
(v28: core::panics::PanicResult::<(core::felt252, ())>) <- PanicResult::Err(v20)
End:
Return(v47, v48, v28)
//! > ==========================================================================
//! > Test while-let.
//! > test_runner_name
test_generated_function
//! > function
fn foo(ref arr: Array<felt252>) -> felt252 {
let mut x = 5;
while let true = (x != 0) {
x = x - 1;
break;
};
x
}
//! > function_name
foo
//! > module_code
//! > semantic_diagnostics
//! > lowering_diagnostics
//! > lowering_flat
Parameters:
//! > lowering
Main:
Parameters: v0: core::array::Array::<core::felt252>
blk0 (root):
Statements:
(v1: core::felt252) <- 5
(v3: core::felt252, v2: ()) <- test::foo[expr13](v1)
End:
Return(v0, v3)
Final lowering:
Parameters: v0: core::array::Array::<core::felt252>
blk0 (root):
Statements:
(v1: core::felt252) <- 5
End:
Match(match core::felt252_is_zero(v1) {
IsZeroResult::Zero => blk1,
IsZeroResult::NonZero(v4) => blk2,
})
blk1:
Statements:
End:
Return(v0, v1)
blk2:
Statements:
(v5: core::felt252) <- 1
(v6: core::felt252) <- core::felt252_sub(v1, v5)
End:
Return(v0, v6)
Generated lowering for source location:
while let true = (x != 0) {
^*************************^
Parameters: v0: core::felt252
blk0 (root):
Statements:
(v1: core::felt252, v2: @core::felt252) <- snapshot(v0)
(v3: core::felt252) <- 0
(v4: core::felt252, v5: @core::felt252) <- snapshot(v3)
(v6: core::bool) <- core::Felt252PartialEq::ne(v2, v5)
End:
Match(match_enum(v6) {
bool::False(v7) => blk1,
bool::True(v8) => blk2,
})
blk1:
Statements:
End:
Goto(blk3, {})
blk2:
Statements:
(v9: core::felt252) <- 1
(v10: core::felt252) <- core::Felt252Sub::sub(v1, v9)
(v11: ()) <- struct_construct()
End:
Return(v10, v11)
blk3:
Statements:
(v12: ()) <- struct_construct()
End:
Return(v1, v12)
Final lowering:
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
Match(match core::felt252_is_zero(v0) {
IsZeroResult::Zero => blk1,
IsZeroResult::NonZero(v16) => blk2,
})
blk1:
Statements:
End:
Return(v0)
blk2:
Statements:
(v9: core::felt252) <- 1
(v23: core::felt252) <- core::felt252_sub(v0, v9)
End:
Return(v23)
//! > ==========================================================================
//! > Test while-let extern enum.
//! > test_runner_name
test_generated_function
//! > function
fn foo() -> felt252 {
let mut y = 0;
while let myEnum::A(x) = a() {
y = y + x
};
y = y + 1;
return y;
}
//! > function_name
foo
//! > module_code
enum myEnum {
A: felt252,
B,
C,
}
extern fn a() -> myEnum nopanic;
//! > semantic_diagnostics
//! > lowering_diagnostics
//! > lowering_flat
//! > lowering
Main:
Parameters:
blk0 (root):
Statements:
(v0: core::felt252) <- 0
(v2: core::felt252, v1: ()) <- test::foo[expr8](v0)
(v3: core::felt252) <- 1
(v4: core::felt252) <- core::Felt252Add::add(v2, v3)
End:
Return(v4)
Final lowering:
Parameters: v14: core::RangeCheck, v15: core::gas::GasBuiltin
blk0 (root):
Statements:
(v0: core::felt252) <- 0
(v16: core::RangeCheck, v17: core::gas::GasBuiltin, v5: core::panics::PanicResult::<(core::felt252, ())>) <- test::foo[expr8](v14, v15, v0)
End:
Match(match_enum(v5) {
PanicResult::Ok(v6) => blk1,
PanicResult::Err(v9) => blk2,
})
blk1:
Statements:
(v7: core::felt252, v8: ()) <- struct_destructure(v6)
(v3: core::felt252) <- 1
(v13: core::felt252) <- core::felt252_add(v7, v3)
(v10: (core::felt252,)) <- struct_construct(v13)
(v11: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Ok(v10)
End:
Return(v16, v17, v11)
blk2:
Statements:
(v12: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v9)
End:
Return(v16, v17, v12)
Generated lowering for source location:
while let myEnum::A(x) = a() {
^****************************^
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
Match(match test::a() {
myEnum::A(v1) => blk1,
myEnum::B => blk2,
myEnum::C => blk3,
})
blk1:
Statements:
(v2: core::felt252) <- core::Felt252Add::add(v0, v1)
(v4: core::felt252, v3: ()) <- test::foo[expr8](v2)
End:
Goto(blk6, {v4 -> v6, v3 -> v5})
blk2:
Statements:
End:
Goto(blk5, {})
blk3:
Statements:
End:
Goto(blk5, {})
blk4:
Statements:
End:
Match(match test::a() {
})
blk5:
Statements:
(v7: ()) <- struct_construct()
End:
Goto(blk6, {v0 -> v6, v7 -> v5})
blk6:
Statements:
End:
Return(v6, v5)
Final lowering:
Parameters: v23: core::RangeCheck, v24: core::gas::GasBuiltin, v0: core::felt252
blk0 (root):
Statements:
End:
Match(match core::gas::withdraw_gas(v23, v24) {
Option::Some(v25, v26) => blk1,
Option::None(v27, v28) => blk6,
})
blk1:
Statements:
End:
Match(match test::a() {
myEnum::A(v1) => blk2,
myEnum::B => blk3,
myEnum::C => blk4,
})
blk2:
Statements:
(v22: core::felt252) <- core::felt252_add(v0, v1)
(v29: core::RangeCheck, v30: core::gas::GasBuiltin, v13: core::panics::PanicResult::<(core::felt252, ())>) <- test::foo[expr8](v25, v26, v22)
End:
Return(v29, v30, v13)
blk3:
Statements:
End:
Goto(blk5, {})
blk4:
Statements:
End:
Goto(blk5, {})
blk5:
Statements:
(v7: ()) <- struct_construct()
(v18: (core::felt252, ())) <- struct_construct(v0, v7)
(v19: core::panics::PanicResult::<(core::felt252, ())>) <- PanicResult::Ok(v18)
End:
Return(v25, v26, v19)
blk6:
Statements:
(v8: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
(v9: core::felt252) <- 375233589013918064796019
(v11: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v8, v9)
(v10: core::panics::Panic) <- struct_construct()
(v12: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v10, v11)
(v20: core::panics::PanicResult::<(core::felt252, ())>) <- PanicResult::Err(v12)
End:
Return(v27, v28, v20)