Skip to content

Native memory pointers and noalias access parameters - #1892

Open
sbillig wants to merge 3 commits into
masterfrom
native-memory-pointers
Open

sbillig wants to merge 3 commits into
masterfrom
native-memory-pointers

Conversation

@sbillig

@sbillig sbillig commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Native memory addresses reach Sonatina as pointers, so its alias analysis can track them instead of treating every heap access as unknown.

  • MIR gives a memory *T ScalarRole::Pointer instead of a plain usize. Allocations and PtrOffsetBytes produce it, PtrEq compares it, and only it converts to a memory RawAddr. The init ABI steps its buffers with PtrOffsetBytes instead of a checked add.
  • Native lowering represents memory pointers, raw addresses and native reference carriers as *i8, steps them with gep, and converts through ptr_to_int only for comparisons, casts and range checks. Host externs take their pointer types from MIR, so the special case for declared host pointers goes away; sizes passed to malloc and memmove stay integers.
  • mut and view access parameters are marked noalias.

Stacked on #1891.

@sbillig
sbillig added this pull request to stack #1893 October 29, 2026 06:26
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 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-10-29T16:34:03.389765Z f2f6b00 New commits
ℹ️ 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 sonatina-native-tail-calls to master October 29, 2026 16:31
Sonatina assumed any two object arguments may overlap and that opaque
calls and raw stores may write them. Fe's access rules say more: a `mut`
parameter's place belongs to the call alone, and nothing writes a view
or read effect's place during the call. Mark every object argument that
is an access of its caller's place (a view, `mut` or effect parameter,
or an access part of a product) `noalias`. Owned parameters stay
unmarked, since their objects may be shared.
MIR classed a memory `*T` as a plain `usize` scalar, so codegen could not
tell a pointer from an integer. Give it `ScalarRole::Pointer`. Allocations
and `PtrOffsetBytes` produce it, `PtrEq` compares it as is, and only it
converts to a memory `RawAddr`. The init ABI steps its buffers with
`PtrOffsetBytes` instead of a checked word add; both offsets stay inside
an allocation whose size was checked.
Native memory addresses were `i64`s, so every heap pointer passed to
`free`, `memmove` or `write` went through `int_to_ptr`, and Sonatina saw
no provenance. Lower memory pointers, raw addresses and native reference
carriers as `*i8`, step them with `gep`, and convert through `ptr_to_int`
only for comparisons, casts and range checks. Host externs take their
pointer types from MIR, and the panic helpers address their buffers as
pointers.
@sbillig
sbillig force-pushed the native-memory-pointers branch from b99019f to f2f6b00 Compare October 29, 2026 16:31

This branch has not been deployed

No deployments
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