Skip to content

Fix CTFE evaluation of symbolic array repeats - #1556

Merged
sbillig merged 9 commits into
masterfrom
fix/symbolic-array-repeat-ctfe
Sep 24, 2026
Merged

sbillig merged 9 commits into
masterfrom
fix/symbolic-array-repeat-ctfe

Conversation

@sbillig

@sbillig sbillig commented Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator

Generic constants such as const VALUES: [u8; N] = [7; N] were rejected while N was still symbolic. Preserve repeat elements and lengths as abstract constants, then materialize them after specialization. Deferred indexing keeps its bounds check, and empty arrays still evaluate their element expressions, including deferred faults.

Add HIR coverage for generic records, nested and empty arrays, trait-associated lengths/elements, runtime reification, and invalid expressions. Add an execution fixture covering specialized arrays and independent mutation of repeated nested arrays.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 18, 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-24T03:16:59.768177Z 455b318 Manual request
🔒 Security Review ✅ Completed 2026-09-24T03:20:24.652778Z 455b318 Manual request
ℹ️ 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.

@sbillig
sbillig marked this pull request as draft September 19, 2026 03:26
@sbillig
sbillig force-pushed the fix/symbolic-array-repeat-ctfe branch from ab67f04 to 6406c60 Compare September 20, 2026 16:42
@sbillig
sbillig force-pushed the fix/symbolic-array-repeat-ctfe branch from 6406c60 to f419954 Compare September 20, 2026 16:45
@sbillig
sbillig added this pull request to stack #1558 September 20, 2026 22:44
@sbillig
sbillig marked this pull request as ready for review September 20, 2026 22:44

@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 Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f41995483d

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/hir/src/analysis/semantic/ctfe/machine.rs Outdated

@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 Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d2267c7ded

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/hir/src/analysis/semantic/ctfe/machine.rs Outdated
Comment thread crates/hir/src/analysis/semantic/ctfe/machine.rs Outdated

@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 Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 170d6d2a8a

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/hir/src/analysis/semantic/consts.rs Outdated
Base automatically changed from semantic-borrow-restart to master September 21, 2026 18:00
@sbillig
sbillig force-pushed the fix/symbolic-array-repeat-ctfe branch from a6ee335 to 338e194 Compare September 21, 2026 18:00
@sbillig

sbillig commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@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 Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 338e194151

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/hir/src/analysis/semantic/ctfe/machine.rs Outdated
@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 338e194151

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ 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.

@sbillig

sbillig commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@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 Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e1c02fed82

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/hir/src/analysis/semantic/ctfe/machine.rs Outdated
Comment thread crates/hir/src/analysis/semantic/ctfe/machine.rs Outdated
@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: e1c02fed82

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ 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.

Preserve repeat elements and extents in abstract constants until specialization.
Retain deferred bounds checks and evaluate repeat operands before materializing
arrays, including zero-length arrays with deferred element failures.

Cover nested and record constants, associated lengths, substitution, runtime
reification, invalid elements, and independent mutation of repeated arrays.

Validation: nightly workspace formatting; strict all-target/all-feature workspace
Clippy with warnings denied; full all-feature release nextest suite (3,357 passed,
one existing ignored test).
Separate dependent descriptions, verified values, and formal runtime evidence.
Replay blocked computations from immutable requests, preserve generic ownership
and source diagnostics, and share primitive semantics and resource accounting.

Consolidate retained-term forcing and immutable payloads, remove independent
runtime evaluation and fallback success, and add differential and regression
coverage across type checking, specialization, and runtime materialization.
Record the phase 0–8 implementation, regression traceability, retained adapters,
full verification results, measured workloads, and separately scoped borrowing.
@sbillig
sbillig force-pushed the fix/symbolic-array-repeat-ctfe branch from e1c02fe to 455b318 Compare September 24, 2026 02:30
@sbillig

sbillig commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 455b3189ff

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 455b3189ff

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ 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.

@sbillig
sbillig merged commit 40ab81c into master Sep 24, 2026
9 checks passed
@sbillig
sbillig deleted the fix/symbolic-array-repeat-ctfe branch September 24, 2026 03:31
micahscopes added a commit that referenced this pull request Sep 25, 2026
Const evaluation rejected every borrow that carries address-space
metadata. Explicit borrows of locals (`mut x`, `ref x`, and `mut`
arguments) carry `Memory` metadata too, so a const fn that updated a
local in place, or passed one to a helper by `mut`, failed to evaluate.

Accept a `Memory` borrow whose place is rooted in a frame local and does
not go through a dereference. Borrows through pointers and of
provider-backed locals still fail with `InvalidProviderUse`, since
constant evaluation has no memory outside its frames. A request cannot
carry a pointer argument (request inputs are verified before
execution), so the pointer case is tested inside the machine tests.

When a frame returns a reference into itself, the value is read out if
the declared result type is not a borrow, and the evaluation fails with
`InvalidBorrow` if it is, so a dangling reference cannot escape. A
reference into a caller's frame is returned unchanged.

This fits the transactional evaluator from #1556 as is: machine
references stay private to one attempt, and a blocked attempt discards
its frames, so a replay after specialization starts from the original
locals. #1556 recorded the borrowing restriction as intentionally kept
(`docs/ctfe-deferral-audit.md`, "Borrowing scope") and pinned it with
`ctfe_typed_read_preserves_provider_borrow_rejection`. That test now
checks that the typed read through `ref value` evaluates to 7, under
the name `ctfe_typed_read_through_frame_local_borrow_evaluates`, and the
audit's borrowing paragraph describes the admitted borrows.
micahscopes added a commit that referenced this pull request Sep 25, 2026
Const functions could not use effects at all: a `uses` clause on a
`const fn` was an error, a call to any function with effects was an
error, and every `with` expression in a `const fn` was rejected. A
trait provider is an ordinary value, so an immutable one can be
evaluated at compile time like any other argument.

Allow a `const fn` to declare immutable trait effects and to supply
them with `with`. During evaluation a call passes each provider as a
value into the callee's effect slot, matched by the effect's binding
index rather than by its position among ordinary arguments. A `with`
provider that lowering captured as a place (#1564) is read from that
place. The checker still rejects mutable effects, type-keyed (storage)
effects, and extern functions with effects.

Deferral needs no special case. Since #1556, a call whose input is
still generic blocks the whole attempt, which is discarded and replayed
after specialization; the replay recomputes the providers from the
caller's body. Term extraction already declines calls with effect
arguments, so a provider never enters a retained term. A test checks
that an effectful call blocks while generic and evaluates with its
provider once specialized, like a pure call.

Effect slots follow the same rules as ordinary argument slots: a
request that supplies no providers for an effectful function is
unsupported (`NotConstEvaluable`), and a slot count or index mismatch
is an invalid operation, like the existing argument arity check.

The `with`-in-const-fn diagnostic (8-0056) is removed, and the two
remaining const-effect messages now say what is supported.
micahscopes added a commit that referenced this pull request Sep 28, 2026
Const evaluation rejected every borrow that carries address-space
metadata. Explicit borrows of locals (`mut x`, `ref x`, and `mut`
arguments) carry `Memory` metadata too, so a const fn that updated a
local in place, or passed one to a helper by `mut`, failed to evaluate.

Accept a `Memory` borrow whose place is rooted in a frame local and does
not go through a dereference. Borrows through pointers and of
provider-backed locals still fail with `InvalidProviderUse`, since
constant evaluation has no memory outside its frames. A request cannot
carry a pointer argument (request inputs are verified before
execution), so the pointer case is tested inside the machine tests.

When a frame returns a reference into itself, the value is read out if
the declared result type is not a borrow, and the evaluation fails with
`InvalidBorrow` if it is, so a dangling reference cannot escape. A
reference into a caller's frame is returned unchanged.

This fits the transactional evaluator from #1556 as is: machine
references stay private to one attempt, and a blocked attempt discards
its frames, so a replay after specialization starts from the original
locals. #1556 recorded the borrowing restriction as intentionally kept
(`docs/ctfe-deferral-audit.md`, "Borrowing scope") and pinned it with
`ctfe_typed_read_preserves_provider_borrow_rejection`. That test now
checks that the typed read through `ref value` evaluates to 7, under
the name `ctfe_typed_read_through_frame_local_borrow_evaluates`, and the
audit's borrowing paragraph describes the admitted borrows.
micahscopes added a commit that referenced this pull request Sep 28, 2026
Const functions could not use effects at all: a `uses` clause on a
`const fn` was an error, a call to any function with effects was an
error, and every `with` expression in a `const fn` was rejected. A
trait provider is an ordinary value, so an immutable one can be
evaluated at compile time like any other argument.

Allow a `const fn` to declare immutable trait effects and to supply
them with `with`. During evaluation a call passes each provider as a
value into the callee's effect slot, matched by the effect's binding
index rather than by its position among ordinary arguments. A `with`
provider that lowering captured as a place (#1564) is read from that
place. The checker still rejects mutable effects, type-keyed (storage)
effects, and extern functions with effects.

Deferral needs no special case. Since #1556, a call whose input is
still generic blocks the whole attempt, which is discarded and replayed
after specialization; the replay recomputes the providers from the
caller's body. Term extraction already declines calls with effect
arguments, so a provider never enters a retained term. A test checks
that an effectful call blocks while generic and evaluates with its
provider once specialized, like a pure call.

Effect slots follow the same rules as ordinary argument slots: a
request that supplies no providers for an effectful function is
unsupported (`NotConstEvaluable`), and a slot count or index mismatch
is an invalid operation, like the existing argument arity check.

The `with`-in-const-fn diagnostic (8-0056) is removed, and the two
remaining const-effect messages now say what is supported.
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