Repository navigation
perf(ast): read local variables in place when evaluating selects - #3
Merged
Merged
Conversation
Element, range and member selects evaluated their value operand by copying it, so every read of one element of a large local array or packed vector in a constant function copied the whole variable. Hsiao ECC matrix generation, for example, reads single bits of a 20,880-bit packed local and single elements of a 22,800-element unpacked local in its inner loops. When the value operand names a local variable of the current frame and the selectors can't write to any variable, the select now reads the variable in place. Selectors with side effects keep the copy, so the value is still read before the selector's side effects. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
ElementSelectExpression,RangeSelectExpressionandMemberAccessExpressionevaluate their value operand withvalue().eval(). For a local variable, that returns a copy of the entire variable. Each read of one element of a large local array or packed vector in a constant function copies the whole local. Hsiao ECC matrix generation, for example, reads single bits of a 20,880-bit packed local and single elements of a 22,800-element unpacked local in its inner loops.When the value operand names a local of the current frame, the select now reads the variable in place, through the new
NamedValueExpression::evalLocalRef. This only happens when every selector is side-effect free: literals, names, unary operators other than++/--, binary operators, conversions, and nested selects of those. Any other selector keeps the copy, so the value is still read before the selector's side effects (a[a[0]++]reads the olda).checkConstantdiagnostics are issued exactly as before.Measured with the boson native-elab driver setup,
getAllDiagnostics, 1 thread:The rendered diagnostics are byte-identical in every column. The new
EvalTests.cppcase covers unpacked, packed and struct selects of locals, a side-effecting selector, and an out-of-bounds read. The full unittests pass: 22082 assertions in 2204 test cases.Ships to boson as
scripts/patches/slang/0011-read-locals-in-place-in-const-eval-selects.patch(partcleda/boson#13187).🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need.