Skip to content

Fix field projections, receivers and with bindings through temporary pointers - #1633

Merged
sbillig merged 4 commits into
masterfrom
fix/call-result-raw-ptr-projection
Sep 29, 2026
Merged

sbillig merged 4 commits into
masterfrom
fix/call-result-raw-ptr-projection

Conversation

@sbillig

@sbillig sbillig commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

A field access through a pointer implicitly dereferences it. A place rooted at a temporary pointer, such as pick(a, b).value or (*f()).next.value, dropped that dereference. Lowering then projected a field of the pointer value itself, which normalization rejected with an internal borrow-check error (16-0004). These now lower like (*f()).field.

Two other sites copied temporary-pointer places instead of using them in place. Both silently lose writes on master:

  • mut self receivers, e.g. (*f()).set(1), borrowed a copy of the receiver.
  • with bindings of root-object providers, e.g. with ((*f()).counter) { incr() }, bound a copy.

Receivers now use the same place lowering as other places. with bindings use a capture-aware version of it, which snapshots pointers and indices as captured binding places already did. The three fixes belong together: the projection fix alone would turn f().field.set(..) and with (f().field) from an internal error into a lost write.

A field access through a pointer implicitly dereferences it. Binding-rooted
places already record that dereference, but temporary-rooted places such as
`pick(..).value` or `(*f()).next.value` dropped it and lowered a field
projection of the pointer value itself, which normalization rejected as an
invalid projection.
Receiver auto-borrows only recognized binding-rooted places, so a receiver
reached through a temporary pointer, such as `(*f()).set(..)` or
`f().field.set(..)`, was copied into a temporary and a `mut self` method
mutated the copy. Lower receivers with the same place lowering as other
places, materializing a temporary only for rvalues.
A `with` binding of a root-object provider captured only binding-rooted
places. A provider reached through a temporary pointer, such as
`with ((*f()).counter)` or `with (f().counter)`, was copied into a
temporary, so effectful calls in the body mutated the copy.

Make place lowering capture-aware and use it for `with` bindings. A
captured place snapshots its pointers and dynamic indices, as captured
binding places already did, so writes in the body cannot retarget it.
@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-29T16:21:23.034252Z 9b21fe1 PR opened
🔒 Security Review ✅ Completed 2026-09-29T16:35:04.336468Z 9b21fe1 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 merged commit 0862fcd into master Sep 29, 2026
9 checks passed
@sbillig
sbillig deleted the fix/call-result-raw-ptr-projection branch September 29, 2026 19:54
cburgdorf added a commit that referenced this pull request Sep 29, 2026
The lowering and type checking for places reached through a temporary
pointer landed on master (#1633, #1634). Keep this branch's extra
coverage on top of it:

- `temporary_pointer_field.fe` exercises reads, writes, compound
  assignment and explicit `mut`/`ref` borrows of fields reached through
  pointer-returning calls such as `orders.ptr_at(0).n`, including
  chained `ptr_at` calls and pointer fields of temporaries.
- `borrow_custom_index_through_pointer.fe` pins that a built-in array
  element below a temporary pointer is borrowable, while a custom
  `Index` call below one is still rejected as a non-place.
sbillig pushed a commit that referenced this pull request Sep 30, 2026
The lowering and type checking for places reached through a temporary
pointer landed on master (#1633, #1634). Keep this branch's extra
coverage on top of it:

- `temporary_pointer_field.fe` exercises reads, writes, compound
  assignment and explicit `mut`/`ref` borrows of fields reached through
  pointer-returning calls such as `orders.ptr_at(0).n`, including
  chained `ptr_at` calls and pointer fields of temporaries.
- `borrow_custom_index_through_pointer.fe` pins that a built-in array
  element below a temporary pointer is borrowable, while a custom
  `Index` call below one is still rejected as a non-place.
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