I tried to understand the ABI manifesto yet I failed to understand whether or not refactoring metatypes would affect ABI. From my perspective metatypes is an underestimated topic. No one really cares about metatypes, yet most of us use them. Furthermore I don't understand why metatypes almost in every conversation are only associated with reflections, where the truth is that metatypes can do a lot more than just allow new possibilities for reflections. In fact I'm more interested in the smaller things:
-
Fixing magical
type(of:)
function -
Allowing
subtype(of:named:)
function (there was some work done letely that could be re-used for that) -
Removing the last value-style syntax
.Type
and.Protocol
from the language (not counting.self
here) -
Allowing custom nested types to be called
Type
andProtocol
-
Making the difference between static and dynamic metatypes and their partly covariant relation clear
-
Merging
MemoryLayout
directly into static matatypes -
We could allow extensions on static metatype and perhaps on dynamic metatype to add members or conform them to protocols. This could allow us to remove some standard library hacks, like the non-
Equatable
-related==
operators for types. -
Conforming static metatypes to
Hashable
would allow us to use metatypes for concrete types as hashable keys.let dict: [AnyHashable: String] = [ Int.self: "so cool", String.self, "even cooler" ]
-
Fixing issues in generic and associated type contexts
-
Allowing new generic constraints where one can describe the relationship of a concrete existentials
-
Removing a boundary which was the source for a lot of confusion:
-
Support for protocols as parameters for constrained generics
-
SR-6109:
AnyObject
as associated type constraint causes EXC_BAD_ACCESS -
Some conversations from Twitter (I hope you guys don't mind for linking it here, if you do mind I'll remove it):
-
Extending with reflection capabilities in the future
I'm sure there are more topics and issues related to metatypes. That is the reason why I call metatypes the underestimated topic. It would be really great if someone could clarify the main question about ABI, because I have a feeling that after ABI is declared stable that the chance to fix all those issues will be gone forever.
Decisions about the ABI will have long-term ramifications and may limit the ways in which the language can grow and evolve in the future. Future Swift versions can add new, orthogonal aspects to the ABI, but any inefficiencies or inflexibilities present when stability is declared will (effectively) persist forever for that platform.
Edit:
Here is the proposal where @beccadax helped us a lot revising it after we withdrew our first rushed attempt two years ago before Swift 3 came out. The revised version is mostly theoretical and can be a little confusing at first glance, so be prepared when reading. If you have any questions regarding the proposal you can always ask. I will try to answer them as good as I can.
Short version of the proposal (click to unfold)
- static metatype
Type<T>
(wasT.Type
andT.Protocol
before) - dynamic metatype
AnyType<T>
(wasT.Type
before) - in current Swift static and dynamic metatype are more or less merged
- partly covariant relation:
- for protocols and existentials:
Type<SomeProto> : AnyType<Any>
(this mimicsT.Protocol
behavior)AnyType<SomeProto> : AnyType<Any>
- other types (except functions - please read the proposal to find out why functions are a little different)
Type<T> : AnyType<T>
(note the difference to protocols and existentials)AnyType<T> : AnyType<Any>
AnyType<T>
is a subtype of itself, so the following is true:AnyType<T> : AnyType<T>
- for protocols and existentials: