Repository navigation
Borrow-check an operation-preserving semantic body - #1649
Merged
Merged
Conversation
A function item value is the fieldless record of its item type. Semantic lowering emitted it as a fieldless AggregateMake, which normalization and the borrow checker reject for function types. It only worked because constant canonicalization always replaced it with this constant first.
Type checking recorded an owned-context move whenever the expected type was not yet known to be Copy. A string literal's type stays an inference variable until its fallback resolves it to `String<N>`, so passing an inferred literal to a generic owned parameter recorded a move of a Copy value, and normalization then consumed it. Record the type each value is moved as and decide Copy when inference finishes.
Admission constant folding ran before borrow checking and replaced moves, borrows, reads, and calls of constant operands with their values. Code rejected with runtime values was accepted with constants: double moves, repeated by-value matches, use after move, and reads under a live mutable borrow. Semantic analyses now consume a body whose const references are resolved but whose operations are preserved. Layout evidence and runtime lowering share a separately admitted folded body, which reuses the analysis body when folding changes nothing. This supersedes the folder's exception for non-Copy carriers.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ 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. |
sbillig
force-pushed
the
fix/const-fold-ownership
branch
from
September 30, 2026 04:24
cd0eee8 to
0bf5702
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.
Constant folding ran before borrow checking, so the moves, borrows, and reads of constant operands were gone by the time the checker saw the body. Code that is rejected with runtime values was accepted with constants: moving a constant non-
Copylocal twice, matching the sameOption<Boxed>local by value twice, using a value after moving it into a tuple, or reading a local while amutborrow of it is live.normalize_runtime_semantic_body), which reuses the analysis body when folding changes nothing. The folder's non-Copycarrier exception, an earlier workaround for this bug, is removed.let f = answer) are lowered as constants rather than a fieldlessAggregateMake, which normalization and the borrow solver reject for function types. It only worked because folding always removed it.String<N>, so passing an unannotated literal to a genericown Tparameter was recorded as a move of aCopyvalue. This was already a false positive on master for calls that don't fold.semantic_borrowck/constant_operand_ownership.fecovers the rejected cases andCopy, tag-only, borrowed-match, and reinitialization controls. Its constant and runtime-valued twins now get identical verdicts.