[swift-evolution] [Proposal] Refactor Metatypes, repurpose T[dot]self and Mirror

Adrian Zubarev adrian.zubarev at devandartist.com
Wed Jul 20 03:49:17 CDT 2016

I’m not sure about the name “Metatype” and the relationship with “Type”
About the name. Metatypes are documented but they are types of its own kind and are mostly used in cases like:

// Current Swift 2.2

metatype.staticFunction // also equivalent to T.staticFunction
metatype.staticComputedProperty // also equivalent to T.staticComputedProperty
metatype.init // also equivalent to T.init

// And without metatypes like they are build in Swift (at least T.Type variant):
// We couldn't build these neat looking api's like
struct A {
    static var neat: SomethingNeat.Type {
        return SomethingNeat.self
struct SomethingNeat {
    init() {}

let neat: SomethingNeat = A.neat.init()
With this proposal we would like to discourage the most (not every) use of metatypes and make their existence and functionality crystal clear for everyone.

However, Type<T> captures the type literal, it’s lightweight because it’s completely lazy and has no stored properties. It also provides an access to the metatype whenever you may need it (mostly in cases of API design, so do I believe) and type related footprints like size, stride and alignment which are calculated internally from the metatype of the captured T literal.

And something like Int.self will finally become Hashable which is really handy.

Adrian Zubarev
Sent with Airmail

Am 20. Juli 2016 um 04:30:38, Karl (razielim at gmail.com) schrieb:

I’m not sure about the name “Metatype” and the relationship with “Type”
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160720/77d995c5/attachment.html>

More information about the swift-evolution mailing list