Clarify the function of `__SwiftValue` (used when casting to AnyObject) but remove the actual name.
The name and layout of this type is an internal implementation detail that is not guaranteed and should not be relied on by any code outside of the runtime.
A previous PR collected the various existential types into a single
section of the document.
This PR takes advantage of that structure to clarify the discussion of existential and protocol casting:
* Adds a general discussion of existential casting
* Introduces the "strong existential invariant" and "weak existential invariant" that are common to all existential types
* Makes a more precise distinction between protocols and existential types
This last point involves a number of careful wording nuances based on the following:
* A "protocol" is a syntactic construct defining a collection of requirements and default implementations (the latter via "protocol extensions")
* Some protocol definitions (those without associated types or `Self` references) have an associated "protocol witness" existential type
* A protocol witness existential type has the same name as the protocol definition from which it is derived but they are conceptually different notions
* Existential types such as `Any`, `AnyObject`, and `Error` are not protocols -- for example, they cannot be extended.
* `AnyHashable` is a type-erased container type but is not an existential. It does however behave like an existential for casting purposes.
This only rearranges the existing sections; it does not change any technical points.
This attempts to make the spec a little clearer by grouping the individual type discussions under four main headings:
* Classes and Foreign Types. This includes Swift classes, Obj-C classes, and CF types.
* Other Concrete Types. Struct, Enum, Tuple, Function, Optional, and Set/Dict/Array
* Existential Types. Any, AnyObject, Error, Protocol types, and AnyHashable(*)
* Metatypes & Existential Metatypes (*)
This organization seems to flow a little better.
In particular, it gives me a place to discuss issues common to all Existential types, which I'll work through in a subsequent PR.
Footnotes: This organization isn't perfect, of course:
* AnyHashable isn't really an Existential type, but it behaves as such for casting purposes, so it makes the most sense to discuss it in the Existentials section.
* Metatypes are technically concrete types, but it seems to make more sense to discuss them after discussing Existential types.
* AnyObject behaves as if every class type implicitly conformed to it as a protocol.
* Protocols "inherit" from other protocols, and this has implications for casting to existential metatypes
I also moved the Any self-conformance invariant
to the self-conformance subsection and added a
couple of explanatory sentences.
A specification for Swift's dynamic casting operations.
This specification tries to reflect the _intent_ of the current implementation, defining a consistent behavior that reflects as far as possible the behavior of the current implementation. Deviations from this specification will generally be treated as bugs in the current implementation.