Skip to content

Support emission of locally constant arrays with dynamic contents - #3537

Open
Stefan J. Wernli (swernli) wants to merge 1 commit into
swernli/rca-coerce-dynamic-constantfrom
swernli/locally-constant-arrays
Open

Support emission of locally constant arrays with dynamic contents#3537
Stefan J. Wernli (swernli) wants to merge 1 commit into
swernli/rca-coerce-dynamic-constantfrom
swernli/locally-constant-arrays

Conversation

@swernli

Copy link
Copy Markdown
Contributor

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant