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: Consider constants as used values to keep their rc ops #6122

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions compiler/noirc_evaluator/src/ssa/opt/die.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,17 @@ impl Context {
self.used_values.insert(value_id);
}
Value::Array { array, .. } => {
self.used_values.insert(value_id);
for elem in array {
self.mark_used_instruction_results(dfg, *elem);
}
}
Value::Param { .. } => {
self.used_values.insert(value_id);
}
Value::NumericConstant { .. } => {
self.used_values.insert(value_id);
}
_ => {
// Does not comprise of any instruction results
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "brillig_constant_reference_regression"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sorted_index = ["1", "0"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
unconstrained fn main(sorted_index: [u32; 2]) {
let original = [
55,
11
];

let mut sorted = original; // Stores the constant "original" into the sorted reference

for i in 0..2 {
let index = sorted_index[i];
let value = original[index];
sorted[i] = value; // On first iteration, we should not mutate the original constant array, RC should be > 1
}

assert_eq(sorted[1], 55);
}
Loading