-
Notifications
You must be signed in to change notification settings - Fork 381
fix: Use get_local_or_global_instruction in try_optimize_array_set_from_previous_get
#8200
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
test_programs/compile_success_no_bug/regression_8199/Nargo.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [package] | ||
| name = "regression_8199" | ||
| type = "bin" | ||
| authors = [""] | ||
|
|
||
| [dependencies] |
6 changes: 6 additions & 0 deletions
6
test_programs/compile_success_no_bug/regression_8199/src/main.nr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| global G_C: [[str<0>; 4]; 4] = | ||
| [["", "", "", ""], ["", "", "", ""], ["", "", "", ""], ["", "", "", ""]]; | ||
| unconstrained fn main(a: [[str<0>; 4]; 4]) { | ||
| let mut f = a; | ||
| f[0] = G_C[3]; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This worries me that we could have code elsewhere using
dfg[global_instruction_id]and it'd be silently resolving to the wrong instruction. @vezenovm do you know of anything we could do to help prevent this in the future?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is basically to use
get_local_or_global_instructionby default for fetching instructions. I didn't want to make the change everywhere originally as it should only affect arrays, but I obviously missed a couple spots. See #8185 (comment) for some more info. Perhaps we should just lean into usingget_local_or_global_instructionfor all fetching of instructions not just array instructions.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could make the indices used by the global DFG invalid for other dfgs?
E.g. fill all those indices with
Instruction::Noop.I'm worried about code written like this in the future as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had thought about something like this as well when originally making globals. Wouldn't
Noopbe removed upon simplifying which may eventually still lead to overlapping IDs? I think we would need a persistent placeholder likeValue::Globalthat would be used in a similar manner. At the time I thought the trade-off would be extra instructions duplicated across function DFGs. This would theoretically not be too bad but could lead to a compilation memory increase for programs with lots of array globals. Also a compilation time cost from having to iterate (and skip) those filled instructions.The only time we can access a global instruction is when looking at an array value or iterating the globals graph directly. Iterating over the blocks instructions should always not give us any global instructions. That is why I ultimately chose to lean into only relying on
Value::Globalandget_local_or_global_instruction.I do agree though that filling the instructions would be the safest to prevent this code being written in the future. I'm not sure how else we can guarantee it as we still need to be able to index the DFG by InstructionId.