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(ssa refactor): Fix ssa-gen of nested ifs #1406

Merged
merged 1 commit into from
May 25, 2023
Merged
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
14 changes: 6 additions & 8 deletions crates/noirc_evaluator/src/ssa_refactor/ssa_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,24 +304,22 @@ impl<'a> FunctionContext<'a> {
let mut result = self.unit_value();

if let Some(alternative) = &if_expr.alternative {
let end_block = self.builder.insert_block();
let then_values = then_value.into_value_list(self);
self.builder.terminate_with_jmp(end_block, then_values);

self.builder.switch_to_block(else_block);
let else_value = self.codegen_expression(alternative);

let end_block = self.builder.insert_block();
let else_values = else_value.into_value_list(self);
self.builder.terminate_with_jmp(end_block, else_values);

// Create block arguments for the end block as needed to branch to
// with our then and else value.
result = Self::map_type(&if_expr.typ, |typ| {
self.builder.add_block_parameter(end_block, typ).into()
});

let else_values = else_value.into_value_list(self);
self.builder.terminate_with_jmp(end_block, else_values);

// Must also set the then block to jmp to the end now
self.builder.switch_to_block(then_block);
let then_values = then_value.into_value_list(self);
self.builder.terminate_with_jmp(end_block, then_values);
self.builder.switch_to_block(end_block);
} else {
// In the case we have no 'else', the 'else' block is actually the end block.
Expand Down