On Jun 2, 2016, at 16:57, Sean Heber via swift-evolution
<[email protected] <mailto:[email protected]>> 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:)
>
> Or perhaps just a single property on all types named “memoryLayout” (or
> whatever) that returns the MemoryLayout struct:
>
> Int.memory.size
> type(of: 42).memoryLayout.size
> // etc
>
> Or just a single property on UnsafePointer if we went that route..
>
> It seems like this sort of approach would keep namespace pollution down, at
> least?
I was about to suggest the something very much like that.
In addition to reducing namespace "pollution", I like that it kinda moves
implementation and target-level details into their own little "type
terrarium"... I might suggest renaming "MemoryLayout" to something like
"ImplementationDetails". The latter seems more to-the-point, but, aside from
endianness, I'm not sure if any such details wouldn't fall under the umbrella
of "memory layout" anyway.
Hmm… If all the details of a type’s memory layout can be represented in this
“MemoryLayout" type, could we use it to manually construct a type "in-code"
instead of going through the compiler? I’m not sure it works "that way”… Nor am
I sure what the point would be, but it might be handy if you have clever idea
that the compiler can’t understand.
I clearly shouldn’t be up this early.
- Dave Sweeris_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution