You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fn main() -> pub Field {
let mut x = 0;
for i in 0..10 {
x += i;
}
x
}
Expected Behavior
The compiler is generating a comparison of i with the range 0..10 as can be seen in the following SSA:
Initial SSA:
acir fn main f0 {
b0():
v1 = allocate
store Field 0 at v1
jmp b1(Field 0)
b1(v2: Field):
v4 = lt v2, Field 10
jmpif v4 then: b2, else: b3
b2():
v5 = load v1
v6 = add v5, v2
store v6 at v1
v8 = add v2, Field 1
jmp b1(v8)
b3():
v9 = load v1
return v9
}
Which is a comparison with field operands, but the compiler does not allow the user to perform a similar kind of comparison themselves:
error: Comparisons are invalid on Field types. Try casting the operands to a sized integer type first
┌─ src/main.nr:5:12
│
5 │ if i > 1 {
│ -----
Bug
Since loops are unrolled for ACIR, this field comparison never reaches ACIR gen and is simplified away before. But for brillig, loops are runtime and the field comparison reaches brillig gen. This makes brillig having to handle Field comparisons generated by the compiler itself via casting to integer types.
To Reproduce
Installation Method
None
Nargo Version
No response
Additional Context
No response
Would you like to submit a PR for this Issue?
No
Support Needs
No response
The text was updated successfully, but these errors were encountered:
sirasistant
changed the title
The compiler issues field comparisons for loops
The compiler issues field comparisons for loops at the SSA level
Jul 19, 2023
Aim
Consider the following code:
Expected Behavior
The compiler is generating a comparison of i with the range 0..10 as can be seen in the following SSA:
Which is a comparison with field operands, but the compiler does not allow the user to perform a similar kind of comparison themselves:
Bug
Since loops are unrolled for ACIR, this field comparison never reaches ACIR gen and is simplified away before. But for brillig, loops are runtime and the field comparison reaches brillig gen. This makes brillig having to handle Field comparisons generated by the compiler itself via casting to integer types.
To Reproduce
Installation Method
None
Nargo Version
No response
Additional Context
No response
Would you like to submit a PR for this Issue?
No
Support Needs
No response
The text was updated successfully, but these errors were encountered: