Lazyweb: citation for "stored globals have stable addresses"?

In writing my blog series (Blog series: The Swift Runtime), I want to cite when I'm relying on a property that I and others have talked about before: the inout-to-pointer conversion for a stored global will always use the actual address of the global instead of making a local copy. This guarantee is only provided for globals and static stored properties right now, and even then only in modules compiled without library evolution support (plus non-const globals imported from C, of course).

I know we want to do better here, with @lorentey and others having mentioned a hypothetical "addressable" attribute that could be applied to class instance properties (and elsewhere?), and the previous thread "Passing an extern const C struct by pointer possible?". However, right now I'm just looking for a citation (Apple or swift.org docs, WWDC presentation, compiler docs) of the guarantee I stated above.

Here's the earliest forum post I can find (from me, actually):

But that's not really a good citation in the same way as "Guarantee (in-memory) tuple layout…or don't" doesn't have a good citation. Anyone know of something better?

(see also The state of Swift documentation :-( )

It's not spelled out as clearly as it could be, but https://github.com/apple/swift/blob/master/userdocs/diagnostics/temporary-pointers.md touches on this:

Not all inout-to-pointer conversions result in a temporary pointer. Passing global variables and static properties inout can produce non-ephemeral pointers, as long as they are stored and have no observers. Additionally, if they are of a tuple or struct type, their stored members without observers may also be passed inout as non-ephemeral pointers.

1 Like

Note that even then, only the physical value of the pointer is guaranteed to be the same. You can't load or store from a pointer to a global outside of the with* block or pointer-to-inout call that created the pointer.