Terrible struct layout with Never? and [Never], why?

S1 is expected to be 16 bytes in size and stride because an array is always 8 bytes in size/stride no matter what the element is. S2 is problematic because your layout may lead to lots of padding. S2 can be rewritten as:

struct S2<Element> {
  let x: Int
  let elements: Element?
}

and now MemoryLayout<S2<Never>>.size is 9, but stride will still be 16 for alignment reasons. An optional will always be at least 1 byte large in order to remember whether it is .some/.none.

1 Like