Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made match optimizer handle future remappings. #6669

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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