-
Notifications
You must be signed in to change notification settings - Fork 4
Description
There's a lot of cases where Zac has broken out of the type system for zero benefit. This just harms readability without improving performance, e.g. decompose
is doing a bit decomposition but return in the values as Field
noir_json_parser/src/_string_tools/slice_packed_field.nr
Lines 589 to 601 in d0fdc8d
/** | |
* @brief converts a 16 bit value into 16 fake bools (Field elements that are 0 or 1) | |
**/ | |
unconstrained fn decompose(val: Field) -> [Field; 16] { | |
let mut r: [Field; 16] = [0; 16]; | |
let mut it = val as u32; | |
for i in 0..16 { | |
r[i] = (it & 1) as Field; | |
it >>= 1; | |
} | |
r | |
} |
Rather than using Noir's automatic constraining of return types of unconstrained functions, he's instead injecting a manual boolean check here:
noir_json_parser/src/_string_tools/slice_packed_field.nr
Lines 612 to 613 in d0fdc8d
// we check that the path valid bits are binary | |
assert(path_valid_bits[i] * path_valid_bits[i] - path_valid_bits[i] == 0); |
This is a direct 1:1 with what Noir would do if it was just written with the expected types from the start.
Having written this out, I noticed that Zac is just doing to_le_bits
here so we can remove this function entirely.... That said, there's likely a bunch of different cases of this around the library.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status