[swift-evolution] MemoryLayout for a value

Anton Zhilin antonyzhilin at gmail.com
Thu Aug 4 12:51:33 CDT 2016

2016-08-04 10:31 GMT+03:00 Xiaodi Wu via swift-evolution <
swift-evolution at swift.org>:

> On Thu, Aug 4, 2016 at 2:29 AM, Karl <razielim at gmail.com> wrote:
>> It’s confusing because metatypes in Swift are pretty confusing in
>> general: Int.self returns Int.Type which is not the same as `type(of: <some
>> Int>)` (that would be Int).
>> If a novice wants to jump in, they’ll have to know that MemoryLayout(of:
>> Int.self) would return a MemoryLayout<Int.Type>.
> Yes, here, I agree Dave is absolutely right. You and Dave have convinced
> me that neither `MemoryLayout(of: x)` nor `MemoryLayout.of(x)`, where x is
> an instance, would be appropriate.

Two weeks ago Adrian and I suggested adding dynamic 'size', 'stride',
'alignment' to Mirror, which definition would look like:

public struct Mirror {
    internal metatype_: Any.Type

    public init<T>(_: T.Type)

    public var size: Int { get }
    public var stride: Int { get }
    public var align: Int { get }

    // ...

There are some problems with it right now, but I do believe that reflection
API is where dynamic `size`, `stride`, `alignment` belong.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160804/ae4c1f23/attachment.html>

More information about the swift-evolution mailing list