External Publication
Visit Post

A read only no alias reference

Rust Internals [Unofficial] June 24, 2026
Source

NotPppp1116:

The syntax is only a placeholder, names like &uniq T, &noalias T, or something else may be better.

NotPppp1116:

  • the compiler can optimize based on that exclusivity.

NotPppp1116:

This is somewhat similar to C’s const T * restrict

This motivation/explanation is probably missing the fact that &T is already fully compatible with noalias in LLVM?

↝ compiler explorer demo ⮺


Edit: In fact, looking at your list

NotPppp1116:

ptr noalias readonly nonnull noundef align N dereferenceable(M)

and checking what actually happens for something like &(i32, i32) in the linked code

ptr noalias noundef readonly align 4 captures(none) dereferenceable(8) %x

that’s essentially the exact same list already. (Minus nonnull, but nonnull is implied by dereferenceable anyway!)

however dereferenceable(<n>) does imply nonnull in addrspace(0) (which is the default address space), except if the null_pointer_is_valid function attribute is present (from the LLVM Manual)

Edit2: Actually, those were the things left after LLM was done optimizing. What Rustc produced was apparently

ptr noalias noundef readonly align 4 captures(address, read_provenance) dereferenceable(8) %0

containing these extra captures(address, read_provenance) annotations[1].


  1. by the looks of it, these make the guarantees actually weaker - the deduction of captures(none) happened by LLVM during its own analysis of the function body ↩︎

Discussion in the ATmosphere

Loading comments...