Currently Swift types arent Hashable. This is a problem e.g. in SwiftUI Environment, where theres a subscript<K: EnvironmentKey>(type: K.Type) but it cant be used directly @Environment(\.[MyKey.self]). The result is needless boilerplate (proxy property) in one of SwiftUI's core features.
With how easy the solution seems to be (struct HashableType<Type>: Hashable { }), arguably it would be easy to add to Swift (the only thing stopping users from doing it is the fact that you cant extend metatypes). Im not a compiler expert and am ready to be educated. But stil, is this worth pursuing?
This is an example of wrapping metatypes and using ObjectIdentifier for hashing. This is quite useful when you want to use metatypes as keys for dictionary (which requires Hashable). Perhaps you can adapt this to what you want to do?
Nice, I think this is another solution (this time AnyMetatypeWrapper isnt generic over the type, unlike my solution).
But the problem is that your subscript still cant be used in a KeyPath, which is what I was going for all along and perhaps didnt make it clear enough with the @Environment example.
I am aware that you can make a version of the subscript that takes something hashable, instead of Any.Type. But thats what Im trying to avoid (and why Im on Swift evolution forums, since I believe it needs to be a Swift feature).
I would really love to see this as a language feature as well. Is this something that seems viable to implement, or are there complications that would make this difficult?
Provide global func ==<T>(lhs: T, rhs: T) handling any type, including meta types, tuples, existential containers and functions. Similar for hashing.
Move equality and hashability witness to VWT.
Replace Equatable/Hashable with CustomEquatable/CustomHashable similar to CustomStringConvertible and CustomReflectable.
Drop === and use == to compare references. Disallow classes to conform to CustomEquatable/CustomHashable.
Reasoning for the last one - if reference equality is not what you need, then your entity should not be modeled as a reference type, but rather a value type that uses heap allocation as its implementation detail.
EDIT:
And it also requires stable weak reference - currently references to zombie side tables are dropped during copying.