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 typing for loop bounds #4290

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 5 additions & 1 deletion compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@
/// br loop_entry(v0)
/// loop_entry(i: Field):
/// v2 = lt i v1
/// brif v2, then: loop_body, else: loop_end

Check warning on line 461 in compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (brif)
/// loop_body():
/// v3 = ... codegen body ...
/// v4 = add 1, i
Expand All @@ -472,10 +472,12 @@

// this is the 'i' in `for i in start .. end { block }`
let index_type = Self::convert_non_tuple_type(&for_expr.index_type);
let loop_index = self.builder.add_block_parameter(loop_entry, index_type);
let loop_index = self.builder.add_block_parameter(loop_entry, index_type.clone());

self.builder.set_location(for_expr.start_range_location);
let start_index = self.codegen_non_tuple_expression(&for_expr.start_range)?;
// The frontend does not unify the types of the start range. We do this here.
let start_index = self.builder.insert_cast(start_index, index_type.clone());

self.builder.set_location(for_expr.end_range_location);
let end_index = self.codegen_non_tuple_expression(&for_expr.end_range)?;
Expand All @@ -492,6 +494,8 @@
// end range. These are the instructions used to issue an error if the end of the range
// cannot be determined at compile-time.
self.builder.set_location(for_expr.end_range_location);
// The frontend does not unify the types of the end range. We do this here.
let end_index = self.builder.insert_cast(end_index, index_type);
let jump_condition = self.builder.insert_binary(loop_index, BinaryOp::Lt, end_index);
self.builder.terminate_with_jmpif(jump_condition, loop_body, loop_end);

Expand All @@ -512,7 +516,7 @@
/// For example, the expression `if cond { a } else { b }` is codegen'd as:
///
/// v0 = ... codegen cond ...
/// brif v0, then: then_block, else: else_block

Check warning on line 519 in compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (brif)
/// then_block():
/// v1 = ... codegen a ...
/// br end_if(v1)
Expand All @@ -525,7 +529,7 @@
/// As another example, the expression `if cond { a }` is codegen'd as:
///
/// v0 = ... codegen cond ...
/// brif v0, then: then_block, else: end_block

Check warning on line 532 in compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (brif)
/// then_block:
/// v1 = ... codegen a ...
/// br end_if()
Expand Down
Loading