Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-3723] Determine if the layout algorithm for structs should layout fields in a different order than declared #46308

Open
ematejska mannequin opened this issue Jan 25, 2017 · 4 comments
Labels
affects ABI Flag: Affects ABI

Comments

@ematejska
Copy link
Mannequin

ematejska mannequin commented Jan 25, 2017

Previous ID SR-3723
Radar rdar://problem/31411220
Original Reporter @ematejska
Type Sub-task
Additional Detail from JIRA
Votes 0
Component/s
Labels Sub-task, AffectsABI
Assignee None
Priority Medium

md5: a416a15ebb462bf1f07d78415242bde1

Parent-Task:

  • SR-7809 Define layout algorithm for structs

is duplicated by:

  • SR-3724 Evaluate a fully declaration-order-agnostic layout algorithm for structs

Issue Description:

The layout algorithm for structs should result in an efficient use of space, possibly by laying out fields in a different order than declared. This needs to be figured out ahead of ABI stability.

@bob-wilson
Copy link
Contributor

@swift-ci create

@dabrahams
Copy link
Contributor

Here's an example that I would like to work:

import Swift
struct X { var a: Builtin.Int120, b: UInt8 }
assert(MemoryLayout<X>.size * 8 == 128)

The alternative, in the general case, is some really dangerous unsafeBitcast’ing.

Note that this works:

struct X { var a: (Int64,Int32,Int16,Int8), b: UInt8 }
assert(MemoryLayout<X>.size * 8 == 128)

@swift-ci
Copy link
Contributor

Comment by Andrew (JIRA)

Another example which would be nice ...

import Swift
struct X { var a : UInt32, b : UInt8  }
struct Y { var a : UInt8,  b : UInt32 }
assert(MemoryLayout<X>.size * 8 == 40)
assert(MemoryLayout<Y>.size * 8 == 40) 

@bob-wilson
Copy link
Contributor

We are not currently planning to make changes to the struct layout algorithm for Swift 5, either to minimize alignment padding or to define a declaration-order-agnostic layout (see SR-3724). Future versions of Swift might still make those changes if the layouts are versioned.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects ABI Flag: Affects ABI
Projects
None yet
Development

No branches or pull requests

3 participants