# SE-0334: Pointer Usability Improvements

**URL:** <https://forums.swift.org/t/se-0334-pointer-usability-improvements/53800>\
**Category:** Proposal Reviews\
**Created:** [December 1, 2021, 5:11am UTC](https://forums.swift.org/t/se-0334-pointer-usability-improvements/53800 "2021-12-01T05:11:10Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![Karl](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@Karl](https://forums.swift.org/u/Karl)\
**Post date:** [January 4, 2022, 10:56am UTC](https://forums.swift.org/t/se-0334-pointer-usability-improvements/53800/17 "2022-01-04T10:56:58Z")

</div>

> [@Michael\_Ilseman](#):
>
> For the purposes of `UP` family of types, IIUC, we're only talking about rules as they pertain to things that are already addressable and with already-defined layout.

Right, but what I'm wondering is whether addressable fields need to be properly aligned. If not (i.e. if we still want the ability to pack structs as an optimisation, without explicit opt-in), then it might not be safe to construct a typed pointer to a field.

We could perhaps just say that we'll return `nil` if the compiler decides to pack the field in a way that leaves it non-aligned. @John_McCall said in another thread that this is also possible if the compiler decides to make a field non-addressable:

> [@Race condition behaviors](https://forums.swift.org/t/race-condition-behaviors/54322/22):
>
> > [@Race condition behaviors](https://forums.swift.org/t/race-condition-behaviors/54322/15):
> >
> > Is it actually permitted? That would mean `MemoryLayout.offset(of:)` could return nil or not based on the whims of the optimiser, or the target platform.
> 
> That’s correct, it can, at least for Swift-defined types. If this isn’t documented, it should be.

I'm a little uneasy about that (for both cases, struct-packing and bit-packing). It means that the optimiser can change the observable semantics of a program, and that both the proposed pointer-to-field and existing address-of-field APIs are inherently unreliable. The optimiser is built on heuristics which can change at any time.

---

_[View the full topic](https://forums.swift.org/t/se-0334-pointer-usability-improvements/53800)._
