Skip to content

Commit 5211290

Browse files
committedSep 14, 2023
Fixing issue #4034. Removing unused vars goto mappings.
commit-id:9ee1e548
1 parent 165ae69 commit 5211290

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed
 

‎crates/cairo-lang-lowering/src/db.rs

+3
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ fn concrete_function_with_body_lowered(
357357
optimize_remappings(&mut lowered);
358358
reorder_statements(db, &mut lowered);
359359
reorganize_blocks(&mut lowered);
360+
// Removed blocks may have caused some remappings to be redundent, so they need to be removed,
361+
// as SierraGen drop additions assumes all remappings are of used variables.
362+
optimize_remappings(&mut lowered);
360363
Ok(Arc::new(lowered))
361364
}
362365

‎crates/cairo-lang-lowering/src/test_data/lowering_phases

+46-1
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,52 @@ Statements:
10951095
End:
10961096
Return(v34, v35, v25)
10971097

1098-
//! > after_reorganize_blocks (final)
1098+
//! > after_reorganize_blocks
1099+
Parameters: v26: core::RangeCheck, v27: core::gas::GasBuiltin
1100+
blk0 (root):
1101+
Statements:
1102+
(v16: core::gas::BuiltinCosts) <- core::gas::get_builtin_costs()
1103+
End:
1104+
Match(match core::gas::withdraw_gas_all(v26, v27, v16) {
1105+
Option::Some(v28, v29) => blk1,
1106+
Option::None(v30, v31) => blk4,
1107+
})
1108+
1109+
blk1:
1110+
Statements:
1111+
(v34: core::RangeCheck, v35: core::gas::GasBuiltin, v17: core::panics::PanicResult::<((),)>) <- test::foo(v28, v29)
1112+
End:
1113+
Match(match_enum(v17) {
1114+
PanicResult::Ok(v18) => blk2,
1115+
PanicResult::Err(v20) => blk3,
1116+
})
1117+
1118+
blk2:
1119+
Statements:
1120+
(v19: ()) <- struct_destructure(v18)
1121+
(v21: ((),)) <- struct_construct(v19)
1122+
(v22: core::panics::PanicResult::<((),)>) <- PanicResult::Ok(v21)
1123+
End:
1124+
Return(v34, v35, v22)
1125+
1126+
blk3:
1127+
Statements:
1128+
(v25: core::panics::PanicResult::<((),)>) <- PanicResult::Err(v20)
1129+
End:
1130+
Return(v34, v35, v25)
1131+
1132+
blk4:
1133+
Statements:
1134+
(v11: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
1135+
(v12: core::felt252) <- 375233589013918064796019u
1136+
(v14: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v11, v12)
1137+
(v13: core::panics::Panic) <- struct_construct()
1138+
(v15: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v13, v14)
1139+
(v24: core::panics::PanicResult::<((),)>) <- PanicResult::Err(v15)
1140+
End:
1141+
Return(v30, v31, v24)
1142+
1143+
//! > after_optimize_remappings3 (final)
10991144
Parameters: v26: core::RangeCheck, v27: core::gas::GasBuiltin
11001145
blk0 (root):
11011146
Statements:

‎tests/bug_samples/issue4034.cairo

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#[test]
2+
fn var_dropped_after_merge_remapping() {
3+
let mut x: u32 = 0;
4+
if (x == 0 && x != 1 && false) {
5+
x = x + 1;
6+
}
7+
}

‎tests/bug_samples/lib.cairo

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ mod issue3345;
2626
mod issue3658;
2727
mod issue3863;
2828
mod issue4007;
29+
mod issue4034;
2930
mod issue4036;
3031
mod loop_only_change;
3132
mod inconsistent_gas;

0 commit comments

Comments
 (0)