Repository navigation
Project CTFE constants without copying their siblings - #1620
Merged
Merged
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
Security findingsAdvisory findings (1)ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: e92cba4101
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
The fix and its regressions landed with #1582, which carried the same borrow validation, but no release note describes the bug it fixes: forming a method-receiver borrow in CTFE skipped the index bounds check.
SemConstId::value cloned the whole value on every read, so looking at one child of an aggregate constant copied the slice of all its children. Return it by reference. Callers that build a new value clone only the parts they keep.
Every CTFE projection through an interned aggregate expanded all of its children first, so reading or borrowing one element of an N-element constant cost O(N) while the step meter charged one step. Forming a borrow checks its projections, so even an unused borrow paid that cost, and a const fn looping over a large constant array ran in quadratic time within its step budget: 20000 u256 elements took over a minute. Follow a path by borrowing from the frame value or interned constant it lives in, and materialize only the value a load returns. A borrow is checked without loading anything, so the check costs no more than resolving the place did. Field, index, variant-field and enum-tag reads select the one child they need.
sbillig
force-pushed
the
fix/ctfe-borrow-bounds
branch
from
September 29, 2026 21:56
e92cba4 to
f8cf80c
Compare
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.
Reading or borrowing one element of an interned constant expanded and copied its siblings. Repeated projections therefore took quadratic time while consuming only a linear number of CTFE steps.
Return interned values by reference and follow only the requested projection path, materializing the final value when a load needs it. Borrow validation preserves bounds checks without loading the target. Regression coverage exercises scaling and projections through interned aggregates.
Also retains the release note for the receiver-borrow bounds fix, which already landed through #1582.