Skip to content

Accept writes and borrows through temporary-pointer places - #1634

Merged
sbillig merged 2 commits into
masterfrom
fix/pointer-place-writes
Sep 29, 2026
Merged

sbillig merged 2 commits into
masterfrom
fix/pointer-place-writes

Conversation

@sbillig

@sbillig sbillig commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #1633.

*f() = v and ref *f() were accepted. Assigning or borrowing a field or element reached through a temporary pointer was rejected: f().value = 5, (*f()).items[i] += 1, mut f().inner. Semantic lowering already supports these places. Only the frontend admission checks insisted on a binding-rooted place or a bare dereference.

A shared is_pointer_place_expr now recognizes memory addressed through a pointer:

  • *e
  • a field that implicitly dereferences a pointer
  • fields or array elements projected from such memory

The following use it, replacing their bare-dereference special cases:

  • assignment and compound assignment
  • ref/mut borrows
  • call-argument borrows
  • SMIR admission

These borrows use the Memory provider, as ref *f() already did. Projections of non-pointer rvalues, such as make().value = 1, remain rejected.

The frontend treated a location as assignable or borrowable only when it
had a binding-rooted place or was a bare pointer dereference. So
`*f() = v` and `ref *f()` were accepted, but `f().field = v`,
`(*f()).field += 1` and `mut f().field` were rejected, although lowering
already supports these places.

Recognize memory addressed through a pointer, including fields and array
elements projected from it, as a place for assignment, compound
assignment, explicit borrows and call-argument borrows. Such borrows use
the Memory provider, as a bare dereference already did. Projections of
rvalues that are not pointers remain rejected.
@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:10:32.926073Z e599d1e PR opened
🔒 Security Review ✅ Completed 2026-09-29T16:23:48.927089Z e599d1e 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.

Base automatically changed from fix/call-result-raw-ptr-projection to master September 29, 2026 19:54
@sbillig
sbillig merged commit 73f1928 into master Sep 29, 2026
9 checks passed
@sbillig
sbillig deleted the fix/pointer-place-writes branch September 29, 2026 19:55
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