Static memory layout for "Non-allocating Embedded Swift"?

I just read Embedded Swift vision document, and got a question.

It says in Non-allocating Embedded Swift, we cannot allocate dynamic memory, therefore we cannot use even Array or Dictionary. Which are fundamental building block for most programs.

I like that idea and it seems possible to build some sort of static containers, but for that, it seems we need static memory layout support in Swift, which does not exist at this point. For example, like this C struct.

#pragma pack(1)
struct Sample1 {
    int[100] field1;
    char[100] field2;

Does that imply static memory layout feature will eventually be introduced in Swift?
Also, I am pretty sure that explicit memory layout control is a required feature in any kind of low level programming. As many interfaces require certain data layout.

What's core team direction for this?
Do we have any proposal for this?
I'd like to see the potential future direction. If core team is willing to push it, I think it would make Swift to be more considered as a viable option for low-level programmings.


Fixed memory layouts do kind-of exist today embodied in tuples; however that is far from ergonomic or safe to use them as that. During the bringup and validation phases for embedded mode, we did hit pretty early on this limitation and needed exactly the types you mentioned (as well as String). Some of those needs have started to percolate into discussions around additional types that have a "fixed size" type and some experiments have been started to investigate what would be a sustainable direction to propose, however that is not fully ready yet to pitch.

Some parts of that are ready to pitch, for example [Pitch #2] Safe Access to Contiguous Storage. That is one key feature that would needed by a fixed size type.

1 Like