Uploaded image for project: 'Swift'
  1. Swift
  2. SR-3726

Define layout algorithm for tuples



    • Type: Task
    • Status: Resolved
    • Priority: Medium
    • Resolution: Won't Do
    • Component/s: None
    • Labels:


      Ahead of ABI stability, consider if tuple elements are bit-packed to save space.


      This issue should track the overall data layout for tuples. Here is the relevant text from the ABI manifesto:

      Tuples are similar to anonymous structs, but they differ in that they exhibit structural subtyping: a tuple of type e.g. (Bool, Bool) can be passed anywhere expecting generic types (T, U). But, the type (T, U) exists at a higher abstraction level than (Bool, Bool). Due to this, tuples may face more expensive reabstraction costs if their layout is aggressively packed. Reabstracting such a tuple would involve splitting and promoting each element into their own addresses.

      This may be an argument for a simple, declaration-order, non bit-packed layout algorithm for tuples. Tuples are often used for small local values and rarely persisted across ABI boundaries in a way that aggressive packing is performance-critical. This would also be more consistent with how fixed-size C arrays are presented in Swift, which are imported as tuples.

      We should investigate whether to aggressively bit-pack tuple elements similarly to structs, paying the reabstraction costs, or if the benefits are not worth the costs SR-3726.

      Tuples should be binary compatible between labeled and unlabeled tuples of the same type and structure.




            • Assignee:
              ematejska Ewa Matejska
            • Votes:
              0 Vote for this issue
              9 Start watching this issue


              • Created: