Support emission of locally constant arrays with dynamic contents - #3537
Open
Stefan J. Wernli (swernli) wants to merge 1 commit into
Open
Conversation
This change adds additional handling in partial eval for arrays on entry to a new scope during function calls. Specificaly, any arguments that are arrays are recursively checked for contents that are `Value::Var` which indicates that the contents of the array are dynamic at runtime. However, since Q# callable arguments are read-only, these arrays can be treated as "locally constant" and emitted as stored values on scope entry. This then allows later instructions that might need to refer to those arrays (for now, just index instructions) to use those stored values in the same manner that globally constant arrays are used from the data section of the program. Since the existing RIR passes are already capable of eliminating unused store instructions, these stored arrays only persist into the final emitted program when they are actually needed for program functionality. Notably, this unblocks the emission of `Adjoint Std.TableLookup.Select` callable when using the `Adaptive` profile.
Stefan J. Wernli (swernli)
requested review from
Andrew Casey (amcasey) and
Ian Davis (idavis)
as code owners
July 31, 2026 15:45
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This change adds additional handling in partial eval for arrays on entry to a new scope during function calls. Specificaly, any arguments that are arrays are recursively checked for contents that are
Value::Varwhich indicates that the contents of the array are dynamic at runtime. However, since Q# callable arguments are read-only, these arrays can be treated as "locally constant" and emitted as stored values on scope entry. This then allows later instructions that might need to refer to those arrays (for now, just index instructions) to use those stored values in the same manner that globally constant arrays are used from the data section of the program. Since the existing RIR passes are already capable of eliminating unused store instructions, these stored arrays only persist into the final emitted program when they are actually needed for program functionality. Notably, this unblocks the emission ofAdjoint Std.TableLookup.Selectcallable when using theAdaptiveprofile.