[Pitch] Introduce existential `any`

I've actually updated my previous message as I had things wrong interpreted by the pitch. I'm against the meaning of (any P).Type as proposed. This goes against:

And for more context on this issue here are a few examples:

protocol P {}
struct S: P {}

type(of: P.self)      // P.Protocol.Type

let p: P = S()
type(of: p)           // S.Type
type(of: p) is S.Type // true
type(of: p) == S.self // true

P.self is P.Type      // false
P.self is P.Protocol  // true

func whatAmI<T>(_ t: T.Type) {
  print(type(of: t))
}

whatAmI(P.self)              // P.Protocol
whatAmI(P.Type.self)         // P.Type.Protocol
whatAmI(P.Protocol.self)     // P.Protocol.Type
whatAmI(Any.Type.self)       // Any.Type.Protocol
whatAmI(AnyObject.Type.self) // AnyObject.Type.Protocol

// True `P.Type` is not accessible today.

Here are some sub-type relations between existential types and also normal and existential metatypes. Let's say T is a non-protocol type and P is a protocol.

// For non-protocol types those types are sub-types of themselves.
       any T :        any T
(any T).Type : (any T).Type
  any T.Type :   any T.Type

// In case of protocols this is a bit different.
       any P :        any Any
(any P).Type : (any Any).Type
  any P.Type :     any P.Type

I know this topic is mind bending, but it is what it is and we eventually have to talk about it.

2 Likes