[swift-evolution] [Pitch] Renaming sizeof, sizeofValue, strideof, strideofValue

Matthew Johnson matthew at anandabits.com
Fri Jun 3 07:31:15 CDT 2016

Sent from my iPad

On Jun 3, 2016, at 7:08 AM, Brent Royal-Gordon <brent at architechies.com> wrote:

>> This might be silly, but what if there were a struct with all of the relevant fields (not sure what the best name would be):
>> struct MemoryLayout {
>> let size: Int
>> let alignment: Int
>> let stride: Int
>> // etc
>> }
>> Then you’d only maybe need two functions:
>> memoryLayout(of:) and memoryLayout(ofType:)
> Could the `memoryLayout` functions just return `(size: Int, alignment: Int, spacing: Int)` tuples? It's hard to tell because it goes into Builtin land, but I get the impression that these values are calculated at compile time anyway, and if you only used one of them the optimizer could throw the others away.

What would be the advantage of this over returning a value of a MemoryLayout type?  Obviously tuples can be destructured, but I can't think of any others.  I would like to see struct destructuring someday.  I'm not sure destructuring is a strong enough argument to go with a tuple here.  If there is a good reason to have a MemoryLayout type we shouldn't drop it just for destructuring, which may eventually be possible anyway (I hope anyway).

> -- 
> Brent Royal-Gordon
> Architechies

More information about the swift-evolution mailing list