[swift-dev] What can you change in a fixed-contents struct?

Slava Pestov spestov at apple.com
Tue Sep 5 20:40:28 CDT 2017

> On Sep 5, 2017, at 6:37 PM, Nevin Brackett-Rozinsky via swift-dev <swift-dev at swift.org> wrote:
> On Tue, Sep 5, 2017 at 6:08 PM, Slava Pestov via swift-dev <swift-dev at swift.org <mailto:swift-dev at swift.org>> wrote:
> We expect that “define your struct in C” is still the way to go for layout compatibility with other languages and systems.
> Are there plans (however tentative) to eventually make it possible to specify the exact memory layout of a struct in Swift?

It’s not clear what ‘exact memory layout’ means. In C, you don’t get to specify the exact layout either — there are rules around alignment and padding and some non-standard attributes for controlling them, but that’s not quite the same thing.

> It seems like something we will have to tackle in order for Swift to become a serious systems-level programming language.

We do plan on documenting Swift’s struct (and tuple) layout algorithms as part of ABI stability, because we will need to freeze them (at least for types that cross resilience boundaries) to actually have a stable ABI. So you could, with knowledge of the layout algorithm, define a struct and make assumptions about it’s layout in memory, based on your knowledge of the algorithm as it is implemented in the version of Swift you are using. Not quite the same as explicitly specifying a layout, though.


> Nevin
> _______________________________________________
> swift-dev mailing list
> swift-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20170905/1d5ebcea/attachment.html>

More information about the swift-dev mailing list