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

Fix possibly missed optimization. #6660

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 14 additions & 7 deletions crates/cairo-lang-lowering/src/optimizations/match_optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,22 @@ impl<'a> Analyzer<'a> for MatchOptimizerContext {
return;
};

let Some(var_usage) = remapping.get(&candidate.match_variable) else {
// Revoke the candidate.
info.candidate = None;
return;
};
let orig_match_variable = candidate.match_variable;
candidate.match_variable = var_usage.var_id;

if remapping.len() > 1 {
// The term 'additional_remappings' refers to remappings for variables other than the match
// variable.
let goto_has_additional_remappings =
if let Some(var_usage) = remapping.get(&candidate.match_variable) {
candidate.match_variable = var_usage.var_id;
remapping.len() > 1
} else {
// Note that remapping.is_empty() is false here.
true
};

if goto_has_additional_remappings {
// here, we have remappings for variables other than the match variable.

if candidate.future_merge || candidate.additional_remappings.is_some() {
// TODO(ilya): Support multiple remappings with future merges.

Expand Down