Skip to content

Project CTFE constants without copying their siblings - #1620

Merged
sbillig merged 3 commits into
masterfrom
fix/ctfe-borrow-bounds
Oct 1, 2026
Merged

sbillig merged 3 commits into
masterfrom
fix/ctfe-borrow-bounds

Conversation

@sbillig

@sbillig sbillig commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-29T22:04:48.326915Z f8cf80c New commits
🔒 Security Review ✅ Completed 2026-09-29T22:07:15.970030Z f8cf80c New commits

Security findings

Advisory findings (1)

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ 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
sbillig force-pushed the fix/ctfe-borrow-bounds branch from e92cba4 to f8cf80c Compare September 29, 2026 21:56
@sbillig sbillig changed the title Preserve bounds checks when CTFE forms receiver borrows Project CTFE constants without copying their siblings Sep 30, 2026
@sbillig
sbillig merged commit ea06c81 into master Oct 1, 2026
9 checks passed
@sbillig
sbillig deleted the fix/ctfe-borrow-bounds branch October 1, 2026 03:47
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