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: Replace unused ArrayGet/Set with constrain if possibly out of bounds #5691

Merged
merged 29 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
af686e3
Replace unused ArrayGet/Set with constrain if possibly out of bounds
asterite Aug 6, 2024
6f21340
Add some test programs that should fail
asterite Aug 6, 2024
6622719
clippy
asterite Aug 6, 2024
71b33e5
clippy again
asterite Aug 6, 2024
edf6941
Comment failing tests, for now
asterite Aug 6, 2024
3fed72a
Leave for later the case where index might be simplified
asterite Aug 6, 2024
49c80ad
Make it in two passes
asterite Aug 6, 2024
165e183
Fix typo
asterite Aug 6, 2024
4bcecb1
clippy
asterite Aug 6, 2024
0a6bd45
Do it right
asterite Aug 7, 2024
f9fc76e
Better comments
asterite Aug 7, 2024
0e9494c
Consider flattened array length
asterite Aug 7, 2024
d378768
Fix a couple of tests
asterite Aug 7, 2024
ffe067a
Keep track of side effects
asterite Aug 7, 2024
ad812f3
Only deal with array instructions, not slice
asterite Aug 7, 2024
61f2f17
Less nesting
asterite Aug 7, 2024
7bdc227
Handle groups of array_get
asterite Aug 7, 2024
0361700
Better names for test programs
asterite Aug 8, 2024
8bae459
Extract `handle_array_get_group`
asterite Aug 8, 2024
a0d18d1
Continue with DIE if no checks were inserted
asterite Aug 8, 2024
8969fb3
Small adjustments
asterite Aug 8, 2024
55e26b1
Move function down
asterite Aug 8, 2024
0eac5c4
Comment function
asterite Aug 8, 2024
f099ec8
typos
asterite Aug 8, 2024
aa123a8
Remove unused test programs
asterite Aug 8, 2024
4b9538d
Use `Instruction::binary`
asterite Aug 8, 2024
ef07ccb
Extract `replace_unused_array_instructions_with_bounds_checks` optimi…
asterite Aug 9, 2024
b44203f
Revert "Extract `replace_unused_array_instructions_with_bounds_checks…
asterite Aug 9, 2024
be0ef17
Improve formatting
asterite Aug 13, 2024
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
356 changes: 346 additions & 10 deletions compiler/noirc_evaluator/src/ssa/opt/die.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "unused_array_get_known_index_out_of_bounds"
type = "bin"
authors = [""]
compiler_version = ">=0.31.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
let array = [1, 2, 3];
let _ = array[10]; // Index out of bounds
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "unused_array_get_unknown_index_out_of_bounds"
type = "bin"
authors = [""]
compiler_version = ">=0.31.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x = "10"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main(x: Field) {
let array = [1, 2, 3];
let _ = array[x]; // Index out of bounds
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "unused_array_set_known_index_out_of_bounds"
type = "bin"
authors = [""]
compiler_version = ">=0.31.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
let mut array = [1, 2, 3];
array[10] = 1; // Index out of bounds
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "unused_array_set_unknown_index_out_of_bounds"
type = "bin"
authors = [""]
compiler_version = ">=0.31.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x = "10"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main(x: Field) {
let mut array = [1, 2, 3];
array[x] = 1; // Index out of bounds
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "unused_slice_get_known_index_out_of_bounds"
type = "bin"
authors = [""]
compiler_version = ">=0.31.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
let slice = &[1, 2, 3];
let _ = slice[10]; // Index out of bounds
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "unused_slice_get_unknown_index_out_of_bounds"
type = "bin"
authors = [""]
compiler_version = ">=0.31.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x = "10"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main(x: Field) {
let slice = &[1, 2, 3];
let _ = slice[x]; // Index out of bounds
}
Loading