[Idea] Pointer to Field

Or alternative three:

  • Convincing those involved int the current raw RFC that the surface syntax for it should have a form that is compatible with other, future, forms of pointer traversal without reference. Sort of planning for the Deref equivalent beforehand may be useful.

As far as I have been involved the RFC for &[mut] raw evolved from a pure MIR level change to one that affects surface language over time. I've been a proponent of embracing, at least in the surface syntax, an explicit pointer-traversal-only form that can not be mistaken for a dereferencing read, see also this other post for details .

The open question for your first option seems like a good reason for extending traversal to user-defined types as well. If that is possible then may the stdlib could provide a pointer wrapper that provides safe wrapping projection without the inbounds llvm annotations (potentially by just casting to usize and arithmetic math internally, not 100% on the soundness details). That would then be orthogonal to the issues of an initial support of builtin raw pointers that is surely focussed on performance conerns due to its immediate use in the standard library for lack of alternatives (and UB avoidance, pointers created from live references must only be used to access the memory inbounds of the intial object if I understood correctly).

At the same time I'm aware that the whole raw pointer is under a bit of perceived time pressure due to obviously wanting to rectify soundness concerns quickly. However, all ways of receiving an inital valid pointer seem perfectly fine to me. It's only traversing that currently requires temporarily referring to an invalid place and subsequently implicitly creating a reference to that, and has strictly speaking UB. My hope would thus be that a good RFC for simple pointer traversal, restricted to only raw pointers initially, would be open enough to permit customizations with user pointer types and a field representation as an extension and we could then define that extension based on whatever outcome this here yields.

5 Likes