Skip to content

Commit

Permalink
feat: Only check array bounds in brillig if index is unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
sirasistant committed Sep 5, 2024
1 parent 416b293 commit b05f741
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,11 @@ impl<'block> BrilligBlock<'block> {
};

let index_variable = self.convert_ssa_single_addr_value(*index, dfg);
self.validate_array_index(array_variable, index_variable);

if !dfg.is_safe_index(*index, *array) {
self.validate_array_index(array_variable, index_variable);
}

self.retrieve_variable_from_array(
array_pointer,
index_variable,
Expand All @@ -652,7 +656,11 @@ impl<'block> BrilligBlock<'block> {
result_ids[0],
dfg,
);
self.validate_array_index(source_variable, index_register);

if !dfg.is_safe_index(*index, *array) {
self.validate_array_index(source_variable, index_register);
}

self.convert_ssa_array_set(
source_variable,
destination_variable,
Expand Down

0 comments on commit b05f741

Please sign in to comment.