Skip to content

Commit

Permalink
Made match optimizer handle future remappings.
Browse files Browse the repository at this point in the history
Previously additional_remappings were not properly remapped due to the
order of `fix` application.
  • Loading branch information
orizi committed Nov 17, 2024
1 parent e9f3b1b commit 46d647b
Show file tree
Hide file tree
Showing 3 changed files with 468 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ pub fn optimize_matches(lowered: &mut FlatLowered) {
// If there is another fix for the same match arm, the same variable will be used.
let mut var_renaming = UnorderedHashMap::<(VariableId, usize), VariableId>::default();

// Fixes were added in reverse order, so we apply them in reverse.
// Either order will result in correct code, but this way variables with smaller ids appear
// earlier.
// Fixes were added in reverse order and need to be applied in that order.
// This is because `additional_remapping` in later blocks may need to be renamed by fixes from
// earlier blocks.
for FixInfo {
statement_location,
match_block,
Expand All @@ -89,7 +89,7 @@ pub fn optimize_matches(lowered: &mut FlatLowered) {
remapping,
reachable_blocks,
additional_remapping,
} in ctx.fixes.into_iter().rev()
} in ctx.fixes
{
// Choose new variables for each destination of the additional remappings (see comment
// above).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ blk9:
Statements:
End:
Match(match_enum(v24) {
MyEnum::a(v56) => blk19,
MyEnum::b(v57) => blk20,
MyEnum::c(v58) => blk21,
MyEnum::d(v59) => blk22,
MyEnum::e(v60) => blk23,
MyEnum::f(v61) => blk24,
MyEnum::g(v62) => blk25,
MyEnum::h(v63) => blk26,
MyEnum::a(v63) => blk26,
MyEnum::b(v62) => blk25,
MyEnum::c(v61) => blk24,
MyEnum::d(v60) => blk23,
MyEnum::e(v59) => blk22,
MyEnum::f(v58) => blk21,
MyEnum::g(v57) => blk20,
MyEnum::h(v56) => blk19,
})

blk10:
Expand Down Expand Up @@ -295,39 +295,39 @@ End:
blk19:
Statements:
End:
Goto(blk10, {v56 -> v38})
Goto(blk17, {v56 -> v45})

blk20:
Statements:
End:
Goto(blk11, {v57 -> v39})
Goto(blk16, {v57 -> v44})

blk21:
Statements:
End:
Goto(blk12, {v58 -> v40})
Goto(blk15, {v58 -> v43})

blk22:
Statements:
End:
Goto(blk13, {v59 -> v41})
Goto(blk14, {v59 -> v42})

blk23:
Statements:
End:
Goto(blk14, {v60 -> v42})
Goto(blk13, {v60 -> v41})

blk24:
Statements:
End:
Goto(blk15, {v61 -> v43})
Goto(blk12, {v61 -> v40})

blk25:
Statements:
End:
Goto(blk16, {v62 -> v44})
Goto(blk11, {v62 -> v39})

blk26:
Statements:
End:
Goto(blk17, {v63 -> v45})
Goto(blk10, {v63 -> v38})
Loading

0 comments on commit 46d647b

Please sign in to comment.