Consider what I said above, I feel like we should tackle this:
- drop init(_ copy: Type<T>) - to keep equality of Type<T> references
Agreed.
- make all initializer internal and as exchange make sharedInstance
public.
This would ensure that you will always get a reference from the type
storage, and that there can only exist one for each (dynamic) metatype.
I have another idea:
// No uniqueness guarantee
internal class _Type<T> {
var _metatype: Metatype<T>
init()
init(_: AnyMetatype)
init?<U>(casting: Type<U>)
// Instead of a global dictionary
class var sharedInstance: _Type<T>
}
// Uniqueness guarantee
public struct Type<T> {
internal var impl: _Type<T>
public init()
public init(_: AnyMetatype)
public init?<U>(casting: Type<U>)
}
I can’t foresee the future, so I’m wondering if the type may mutate somehow
when reflections are added?
I don’t think so. If added at all, types should only be able to be created
using some kind of builder:
let builder = TypeBuilder(name: "Person", kind:
.struct)builder.addField(name: "", type: Int.self)
//...let typeRef = builder.create()
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution