//! > Test loop.
//! > test_runner_name
test_generated_function
//! > function
fn foo() -> bool {
let mut x = 5;
loop {
let y = x + 1;
x = y;
if y == 10 {
break true;
};
}
}
//! > function_name
foo
//! > module_code
//! > semantic_diagnostics
//! > lowering_diagnostics
//! > lowering_flat
Parameters:
//! > lowering
Main:
Parameters:
blk0 (root):
Statements:
(v0: core::felt252) <- 5
(v2: core::felt252, v1: core::bool) <- test::foo[expr17](v0)
End:
Return(v1)
Final lowering:
Parameters: v11: core::RangeCheck, v12: core::gas::GasBuiltin
blk0 (root):
Statements:
(v0: core::felt252) <- 5
(v13: core::RangeCheck, v14: core::gas::GasBuiltin, v3: core::panics::PanicResult::<(core::felt252, core::bool)>) <- test::foo[expr17](v11, v12, v0)
End:
Match(match_enum(v3) {
PanicResult::Ok(v4) => blk1,
PanicResult::Err(v7) => blk2,
})
blk1:
Statements:
(v5: core::felt252, v6: core::bool) <- struct_destructure(v4)
(v8: (core::bool,)) <- struct_construct(v6)
(v9: core::panics::PanicResult::<(core::bool,)>) <- PanicResult::Ok(v8)
End:
Return(v13, v14, v9)
blk2:
Statements:
(v10: core::panics::PanicResult::<(core::bool,)>) <- PanicResult::Err(v7)
End:
Return(v13, v14, v10)
Generated lowering for source location:
loop {
^****^
Parameters: v0: core::felt252
blk0 (root):
Statements:
(v1: core::felt252) <- 1
(v2: core::felt252) <- core::Felt252Add::add(v0, v1)
(v3: core::felt252, v4: @core::felt252) <- snapshot(v2)
(v5: core::felt252) <- 10
(v6: core::felt252, v7: @core::felt252) <- snapshot(v5)
(v8: core::bool) <- core::Felt252PartialEq::eq(v4, v7)
End:
Match(match_enum(v8) {
bool::False(v12) => blk2,
bool::True(v9) => blk1,
})
blk1:
Statements:
(v10: ()) <- struct_construct()
(v11: core::bool) <- bool::True(v10)
End:
Return(v2, v11)
blk2:
Statements:
End:
Goto(blk3, {})
blk3:
Statements:
(v14: core::felt252, v13: core::bool) <- test::foo[expr17](v2)
End:
Return(v14, v13)
Final lowering:
Parameters: v42: core::RangeCheck, v43: core::gas::GasBuiltin, v0: core::felt252
blk0 (root):
Statements:
End:
Match(match core::gas::withdraw_gas(v42, v43) {
Option::Some(v44, v45) => blk1,
Option::None(v46, v47) => blk4,
})
blk1:
Statements:
(v1: core::felt252) <- 1
(v31: core::felt252) <- core::felt252_add(v0, v1)
(v5: core::felt252) <- 10
(v34: core::felt252) <- core::felt252_sub(v31, v5)
End:
Match(match core::felt252_is_zero(v34) {
IsZeroResult::Zero => blk2,
IsZeroResult::NonZero(v35) => blk3,
})
blk2:
Statements:
(v10: ()) <- struct_construct()
(v11: core::bool) <- bool::True(v10)
(v20: (core::felt252, core::bool)) <- struct_construct(v31, v11)
(v21: core::panics::PanicResult::<(core::felt252, core::bool)>) <- PanicResult::Ok(v20)
End:
Return(v44, v45, v21)
blk3:
Statements:
(v48: core::RangeCheck, v49: core::gas::GasBuiltin, v22: core::panics::PanicResult::<(core::felt252, core::bool)>) <- test::foo[expr17](v44, v45, v31)
End:
Return(v48, v49, v22)
blk4:
Statements:
(v15: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
(v16: core::felt252) <- 375233589013918064796019
(v18: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v15, v16)
(v17: core::panics::Panic) <- struct_construct()
(v19: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v17, v18)
(v27: core::panics::PanicResult::<(core::felt252, core::bool)>) <- PanicResult::Err(v19)
End:
Return(v46, v47, v27)
//! > ==========================================================================
//! > Test loop with duplicate member path.
//! > test_runner_name
test_generated_function
//! > function
fn foo() -> bool {
let mut x = 5;
loop {
x = x + 1;
if x == 10 {
break true;
};
}
}
//! > function_name
foo
//! > module_code
//! > semantic_diagnostics
//! > lowering_diagnostics
//! > lowering_flat
Parameters:
//! > lowering
Main:
Parameters:
blk0 (root):
Statements:
(v0: core::felt252) <- 5
(v2: core::felt252, v1: core::bool) <- test::foo[expr16](v0)
End:
Return(v1)
Final lowering:
Parameters: v11: core::RangeCheck, v12: core::gas::GasBuiltin
blk0 (root):
Statements:
(v0: core::felt252) <- 5
(v13: core::RangeCheck, v14: core::gas::GasBuiltin, v3: core::panics::PanicResult::<(core::felt252, core::bool)>) <- test::foo[expr16](v11, v12, v0)
End:
Match(match_enum(v3) {
PanicResult::Ok(v4) => blk1,
PanicResult::Err(v7) => blk2,
})
blk1:
Statements:
(v5: core::felt252, v6: core::bool) <- struct_destructure(v4)
(v8: (core::bool,)) <- struct_construct(v6)
(v9: core::panics::PanicResult::<(core::bool,)>) <- PanicResult::Ok(v8)
End:
Return(v13, v14, v9)
blk2:
Statements:
(v10: core::panics::PanicResult::<(core::bool,)>) <- PanicResult::Err(v7)
End:
Return(v13, v14, v10)
Generated lowering for source location:
loop {
^****^
Parameters: v0: core::felt252
blk0 (root):
Statements:
(v1: core::felt252) <- 1
(v2: core::felt252) <- core::Felt252Add::add(v0, v1)
(v3: core::felt252, v4: @core::felt252) <- snapshot(v2)
(v5: core::felt252) <- 10
(v6: core::felt252, v7: @core::felt252) <- snapshot(v5)
(v8: core::bool) <- core::Felt252PartialEq::eq(v4, v7)
End:
Match(match_enum(v8) {
bool::False(v12) => blk2,
bool::True(v9) => blk1,
})
blk1:
Statements:
(v10: ()) <- struct_construct()
(v11: core::bool) <- bool::True(v10)
End:
Return(v3, v11)
blk2:
Statements:
End:
Goto(blk3, {})
blk3:
Statements:
(v14: core::felt252, v13: core::bool) <- test::foo[expr16](v3)
End:
Return(v14, v13)
Final lowering:
Parameters: v42: core::RangeCheck, v43: core::gas::GasBuiltin, v0: core::felt252
blk0 (root):
Statements:
End:
Match(match core::gas::withdraw_gas(v42, v43) {
Option::Some(v44, v45) => blk1,
Option::None(v46, v47) => blk4,
})
blk1:
Statements:
(v1: core::felt252) <- 1
(v31: core::felt252) <- core::felt252_add(v0, v1)
(v5: core::felt252) <- 10
(v34: core::felt252) <- core::felt252_sub(v31, v5)
End:
Match(match core::felt252_is_zero(v34) {
IsZeroResult::Zero => blk2,
IsZeroResult::NonZero(v35) => blk3,
})
blk2:
Statements:
(v10: ()) <- struct_construct()
(v11: core::bool) <- bool::True(v10)
(v20: (core::felt252, core::bool)) <- struct_construct(v31, v11)
(v21: core::panics::PanicResult::<(core::felt252, core::bool)>) <- PanicResult::Ok(v20)
End:
Return(v44, v45, v21)
blk3:
Statements:
(v48: core::RangeCheck, v49: core::gas::GasBuiltin, v22: core::panics::PanicResult::<(core::felt252, core::bool)>) <- test::foo[expr16](v44, v45, v31)
End:
Return(v48, v49, v22)
blk4:
Statements:
(v15: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
(v16: core::felt252) <- 375233589013918064796019
(v18: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v15, v16)
(v17: core::panics::Panic) <- struct_construct()
(v19: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v17, v18)
(v27: core::panics::PanicResult::<(core::felt252, core::bool)>) <- PanicResult::Err(v19)
End:
Return(v46, v47, v27)
//! > ==========================================================================
//! > Test loop with member path borrowing.
//! > test_runner_name
test_generated_function
//! > function
fn foo(mut a: A, ref b: A) {
let c = 5_usize;
loop {
let mut h = 0;
a.b.c = c;
if true {
h = 1;
let mut x = 4;
x = 5;
b = A { b: a.b, x };
break b;
};
};
}
//! > function_name
foo
//! > module_code
#[derive(Copy,Drop)]
struct A {
b: B,
x: felt252,
}
#[derive(Copy,Drop)]
struct B {
c: usize,
y: u128,
}
//! > semantic_diagnostics
//! > lowering_diagnostics
//! > lowering_flat
Parameters:
//! > lowering
Main:
Parameters: v0: test::A, v1: test::A
blk0 (root):
Statements:
(v2: core::integer::u32) <- 5
(v3: test::B, v4: core::felt252) <- struct_destructure(v0)
(v6: core::integer::u32, v7: test::A, v5: test::A) <- test::foo[expr26](v2, v3, v1)
(v8: core::integer::u32, v9: core::integer::u128) <- struct_destructure(v3)
(v10: ()) <- struct_construct()
End:
Return(v7, v10)
Final lowering:
Parameters: v20: core::RangeCheck, v21: core::gas::GasBuiltin, v0: test::A, v1: test::A
blk0 (root):
Statements:
(v2: core::integer::u32) <- 5
(v3: test::B, v4: core::felt252) <- struct_destructure(v0)
(v22: core::RangeCheck, v23: core::gas::GasBuiltin, v11: core::panics::PanicResult::<(core::integer::u32, test::A, test::A)>) <- test::foo[expr26](v20, v21, v2, v3, v1)
End:
Match(match_enum(v11) {
PanicResult::Ok(v12) => blk1,
PanicResult::Err(v16) => blk2,
})
blk1:
Statements:
(v13: core::integer::u32, v14: test::A, v15: test::A) <- struct_destructure(v12)
(v10: ()) <- struct_construct()
(v17: (test::A, ())) <- struct_construct(v14, v10)
(v18: core::panics::PanicResult::<(test::A, ())>) <- PanicResult::Ok(v17)
End:
Return(v22, v23, v18)
blk2:
Statements:
(v19: core::panics::PanicResult::<(test::A, ())>) <- PanicResult::Err(v16)
End:
Return(v22, v23, v19)
Generated lowering for source location:
loop {
^****^
Parameters: v0: core::integer::u32, v1: test::B, v2: test::A
blk0 (root):
Statements:
(v3: core::felt252) <- 0
(v4: core::integer::u32, v5: core::integer::u128) <- struct_destructure(v1)
(v6: ()) <- struct_construct()
(v7: core::bool) <- bool::True(v6)
End:
Match(match_enum(v7) {
bool::False(v16) => blk2,
bool::True(v8) => blk1,
})
blk1:
Statements:
(v9: core::felt252) <- 1
(v10: core::felt252) <- 4
(v11: core::felt252) <- 5
(v12: test::B) <- struct_construct(v0, v5)
(v13: test::A) <- struct_construct(v12, v11)
(v14: core::integer::u32, v15: core::integer::u128) <- struct_destructure(v12)
End:
Return(v14, v13, v13)
blk2:
Statements:
End:
Goto(blk3, {})
blk3:
Statements:
(v17: test::B) <- struct_construct(v0, v5)
(v19: core::integer::u32, v20: test::A, v18: test::A) <- test::foo[expr26](v0, v17, v2)
(v21: core::integer::u32, v22: core::integer::u128) <- struct_destructure(v17)
End:
Return(v19, v20, v18)
Final lowering:
Parameters: v40: core::RangeCheck, v41: core::gas::GasBuiltin, v0: core::integer::u32, v1: test::B, v2: test::A
blk0 (root):
Statements:
End:
Match(match core::gas::withdraw_gas(v40, v41) {
Option::Some(v42, v43) => blk1,
Option::None(v44, v45) => blk2,
})
blk1:
Statements:
(v4: core::integer::u32, v5: core::integer::u128) <- struct_destructure(v1)
(v11: core::felt252) <- 5
(v12: test::B) <- struct_construct(v0, v5)
(v13: test::A) <- struct_construct(v12, v11)
(v28: (core::integer::u32, test::A, test::A)) <- struct_construct(v0, v13, v13)
(v29: core::panics::PanicResult::<(core::integer::u32, test::A, test::A)>) <- PanicResult::Ok(v28)
End:
Return(v42, v43, v29)
blk2:
Statements:
(v23: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
(v24: core::felt252) <- 375233589013918064796019
(v26: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v23, v24)
(v25: core::panics::Panic) <- struct_construct()
(v27: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v25, v26)
(v36: core::panics::PanicResult::<(core::integer::u32, test::A, test::A)>) <- PanicResult::Err(v27)
End:
Return(v44, v45, v36)
//! > ==========================================================================
//! > Test loop with continue.
//! > test_runner_name
test_generated_function
//! > function
fn foo() -> bool {
let mut x = 5;
loop {
let y = x + 1;
x = y;
if y == 7 {
continue;
}
if y == 10 {
break true;
};
}
}
//! > function_name
foo
//! > module_code
//! > semantic_diagnostics
//! > lowering_diagnostics
//! > lowering_flat
Parameters:
//! > lowering
Main:
Parameters:
blk0 (root):
Statements:
(v0: core::felt252) <- 5
(v2: core::felt252, v1: core::bool) <- test::foo[expr24](v0)
End:
Return(v1)
Final lowering:
Parameters: v11: core::RangeCheck, v12: core::gas::GasBuiltin
blk0 (root):
Statements:
(v0: core::felt252) <- 5
(v13: core::RangeCheck, v14: core::gas::GasBuiltin, v3: core::panics::PanicResult::<(core::felt252, core::bool)>) <- test::foo[expr24](v11, v12, v0)
End:
Match(match_enum(v3) {
PanicResult::Ok(v4) => blk1,
PanicResult::Err(v7) => blk2,
})
blk1:
Statements:
(v5: core::felt252, v6: core::bool) <- struct_destructure(v4)
(v8: (core::bool,)) <- struct_construct(v6)
(v9: core::panics::PanicResult::<(core::bool,)>) <- PanicResult::Ok(v8)
End:
Return(v13, v14, v9)
blk2:
Statements:
(v10: core::panics::PanicResult::<(core::bool,)>) <- PanicResult::Err(v7)
End:
Return(v13, v14, v10)
Generated lowering for source location:
loop {
^****^
Parameters: v0: core::felt252
blk0 (root):
Statements:
(v1: core::felt252) <- 1
(v2: core::felt252) <- core::Felt252Add::add(v0, v1)
(v3: core::felt252, v4: @core::felt252) <- snapshot(v2)
(v5: core::felt252) <- 7
(v6: core::felt252, v7: @core::felt252) <- snapshot(v5)
(v8: core::bool) <- core::Felt252PartialEq::eq(v4, v7)
End:
Match(match_enum(v8) {
bool::False(v12) => blk2,
bool::True(v9) => blk1,
})
blk1:
Statements:
(v11: core::felt252, v10: core::bool) <- test::foo[expr24](v2)
End:
Return(v11, v10)
blk2:
Statements:
End:
Goto(blk3, {})
blk3:
Statements:
(v13: core::felt252, v14: @core::felt252) <- snapshot(v3)
(v15: core::felt252) <- 10
(v16: core::felt252, v17: @core::felt252) <- snapshot(v15)
(v18: core::bool) <- core::Felt252PartialEq::eq(v14, v17)
End:
Match(match_enum(v18) {
bool::False(v22) => blk5,
bool::True(v19) => blk4,
})
blk4:
Statements:
(v20: ()) <- struct_construct()
(v21: core::bool) <- bool::True(v20)
End:
Return(v2, v21)
blk5:
Statements:
End:
Goto(blk6, {})
blk6:
Statements:
(v24: core::felt252, v23: core::bool) <- test::foo[expr24](v2)
End:
Return(v24, v23)
Final lowering:
Parameters: v70: core::RangeCheck, v71: core::gas::GasBuiltin, v0: core::felt252
blk0 (root):
Statements:
End:
Match(match core::gas::withdraw_gas(v70, v71) {
Option::Some(v72, v73) => blk1,
Option::None(v74, v75) => blk6,
})
blk1:
Statements:
(v1: core::felt252) <- 1
(v57: core::felt252) <- core::felt252_add(v0, v1)
(v5: core::felt252) <- 7
(v60: core::felt252) <- core::felt252_sub(v57, v5)
End:
Match(match core::felt252_is_zero(v60) {
IsZeroResult::Zero => blk2,
IsZeroResult::NonZero(v61) => blk3,
})
blk2:
Statements:
(v76: core::RangeCheck, v77: core::gas::GasBuiltin, v30: core::panics::PanicResult::<(core::felt252, core::bool)>) <- test::foo[expr24](v72, v73, v57)
End:
Return(v76, v77, v30)
blk3:
Statements:
(v15: core::felt252) <- 10
(v51: core::felt252) <- core::felt252_sub(v57, v15)
End:
Match(match core::felt252_is_zero(v51) {
IsZeroResult::Zero => blk4,
IsZeroResult::NonZero(v52) => blk5,
})
blk4:
Statements:
(v20: ()) <- struct_construct()
(v21: core::bool) <- bool::True(v20)
(v35: (core::felt252, core::bool)) <- struct_construct(v57, v21)
(v36: core::panics::PanicResult::<(core::felt252, core::bool)>) <- PanicResult::Ok(v35)
End:
Return(v72, v73, v36)
blk5:
Statements:
(v78: core::RangeCheck, v79: core::gas::GasBuiltin, v37: core::panics::PanicResult::<(core::felt252, core::bool)>) <- test::foo[expr24](v72, v73, v57)
End:
Return(v78, v79, v37)
blk6:
Statements:
(v25: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
(v26: core::felt252) <- 375233589013918064796019
(v28: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v25, v26)
(v27: core::panics::Panic) <- struct_construct()
(v29: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v27, v28)
(v42: core::panics::PanicResult::<(core::felt252, core::bool)>) <- PanicResult::Err(v29)
End:
Return(v74, v75, v42)
//! > ==========================================================================
//! > Test loop with break;
//! > test_runner_name
test_generated_function
//! > function
fn foo() {
loop {
break;
}
}
//! > function_name
foo
//! > module_code
//! > semantic_diagnostics
//! > lowering_diagnostics
//! > lowering_flat
Parameters:
//! > lowering
Main:
Parameters:
blk0 (root):
Statements:
(v0: ()) <- test::foo[expr1]()
End:
Return(v0)
Final lowering:
Parameters:
blk0 (root):
Statements:
End:
Return()
Generated lowering for source location:
loop {
^****^
Parameters:
blk0 (root):
Statements:
(v0: ()) <- struct_construct()
End:
Return(v0)
Final lowering:
Parameters:
blk0 (root):
Statements:
End:
Return()
//! > ==========================================================================
//! > Change in block merge in loop.
//! > test_runner_name
test_generated_function
//! > function
fn foo() {
let mut x = A { a: 3, b: 4 };
loop {
if (true) {
x.a = 0;
} else {
x.a = 0;
}
if x.a == 0 {
break;
};
};
}
//! > function_name
foo
//! > module_code
#[derive(Copy, Drop, Debug)]
struct A {
a: u8,
b: u8,
}
//! > semantic_diagnostics
//! > lowering_diagnostics
//! > lowering_flat
Parameters:
//! > lowering
Main:
Parameters:
blk0 (root):
Statements:
(v0: core::integer::u8) <- 3
(v1: core::integer::u8) <- 4
(v2: test::A) <- struct_construct(v0, v1)
(v3: core::integer::u8, v4: core::integer::u8) <- struct_destructure(v2)
(v6: core::integer::u8, v5: ()) <- test::foo[expr25](v3)
(v7: ()) <- struct_construct()
End:
Return(v7)
Final lowering:
Parameters: v16: core::RangeCheck, v17: core::gas::GasBuiltin
blk0 (root):
Statements:
(v0: core::integer::u8) <- 3
(v18: core::RangeCheck, v19: core::gas::GasBuiltin, v8: core::panics::PanicResult::<(core::integer::u8, ())>) <- test::foo[expr25](v16, v17, v0)
End:
Match(match_enum(v8) {
PanicResult::Ok(v9) => blk1,
PanicResult::Err(v12) => blk2,
})
blk1:
Statements:
(v7: ()) <- struct_construct()
(v13: ((),)) <- struct_construct(v7)
(v14: core::panics::PanicResult::<((),)>) <- PanicResult::Ok(v13)
End:
Return(v18, v19, v14)
blk2:
Statements:
(v15: core::panics::PanicResult::<((),)>) <- PanicResult::Err(v12)
End:
Return(v18, v19, v15)
Generated lowering for source location:
loop {
^****^
Parameters: v0: core::integer::u8
blk0 (root):
Statements:
(v1: ()) <- struct_construct()
(v2: core::bool) <- bool::True(v1)
End:
Match(match_enum(v2) {
bool::False(v5) => blk2,
bool::True(v3) => blk1,
})
blk1:
Statements:
(v4: core::integer::u8) <- 0
End:
Goto(blk3, {v4 -> v7})
blk2:
Statements:
(v6: core::integer::u8) <- 0
End:
Goto(blk3, {v6 -> v7})
blk3:
Statements:
(v8: core::integer::u8, v9: @core::integer::u8) <- snapshot(v7)
(v10: core::integer::u8) <- 0
(v11: core::integer::u8, v12: @core::integer::u8) <- snapshot(v10)
(v13: core::bool) <- core::integer::U8PartialEq::eq(v9, v12)
End:
Match(match_enum(v13) {
bool::False(v16) => blk5,
bool::True(v14) => blk4,
})
blk4:
Statements:
(v15: ()) <- struct_construct()
End:
Return(v8, v15)
blk5:
Statements:
End:
Goto(blk6, {})
blk6:
Statements:
(v18: core::integer::u8, v17: ()) <- test::foo[expr25](v8)
End:
Return(v18, v17)
Final lowering:
Parameters: v43: core::RangeCheck, v44: core::gas::GasBuiltin, v0: core::integer::u8
blk0 (root):
Statements:
End:
Match(match core::gas::withdraw_gas(v43, v44) {
Option::Some(v45, v46) => blk1,
Option::None(v47, v48) => blk4,
})
blk1:
Statements:
(v4: core::integer::u8) <- 0
(v10: core::integer::u8) <- 0
End:
Match(match core::integer::u8_eq(v4, v10) {
bool::False => blk2,
bool::True => blk3,
})
blk2:
Statements:
(v49: core::RangeCheck, v50: core::gas::GasBuiltin, v26: core::panics::PanicResult::<(core::integer::u8, ())>) <- test::foo[expr25](v45, v46, v4)
End:
Return(v49, v50, v26)
blk3:
Statements:
(v15: ()) <- struct_construct()
(v24: (core::integer::u8, ())) <- struct_construct(v4, v15)
(v25: core::panics::PanicResult::<(core::integer::u8, ())>) <- PanicResult::Ok(v24)
End:
Return(v45, v46, v25)
blk4:
Statements:
(v19: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
(v20: core::felt252) <- 375233589013918064796019
(v22: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v19, v20)
(v21: core::panics::Panic) <- struct_construct()
(v23: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v21, v22)
(v31: core::panics::PanicResult::<(core::integer::u8, ())>) <- PanicResult::Err(v23)
End:
Return(v47, v48, v31)