Skip to content

Borrow-check an operation-preserving semantic body - #1649

Merged
sbillig merged 4 commits into
masterfrom
fix/const-fold-ownership
Sep 30, 2026
Merged

sbillig merged 4 commits into
masterfrom
fix/const-fold-ownership

Conversation

@sbillig

@sbillig sbillig commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

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-Copy local twice, matching the same Option<Boxed> local by value twice, using a value after moving it into a tuple, or reading a local while a mut borrow of it is live.

  • Borrow checking (final and provisional) and definite assignment now run on a normalized body where const references are resolved but no operation is folded. Layout evidence and runtime lowering keep the folded body (normalize_runtime_semantic_body), which reuses the analysis body when folding changes nothing. The folder's non-Copy carrier exception, an earlier workaround for this bug, is removed.
  • Function item values (let f = answer) are lowered as constants rather than a fieldless AggregateMake, which normalization and the borrow solver reject for function types. It only worked because folding always removed it.
  • Implicit moves are decided after type inference. A string literal's type stays an inference variable until its fallback resolves it to String<N>, so passing an unannotated literal to a generic own T parameter was recorded as a move of a Copy value. This was already a false positive on master for calls that don't fold.

semantic_borrowck/constant_operand_ownership.fe covers the rejected cases and Copy, tag-only, borrowed-match, and reinitialization controls. Its constant and runtime-valued twins now get identical verdicts.

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 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:51:41.355664Z cd0eee8 PR opened
🔒 Security Review ✅ Completed 2026-09-29T22:58:41.126618Z cd0eee8 PR opened
ℹ️ 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 force-pushed the fix/const-fold-ownership branch from cd0eee8 to 0bf5702 Compare September 30, 2026 04:24
@sbillig
sbillig merged commit 1329ce2 into master Sep 30, 2026
9 checks passed
@sbillig
sbillig deleted the fix/const-fold-ownership branch September 30, 2026 13:33
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