mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Make protocol methods generic over <Self>.
Pull the implicit 'Self' associated type out of the protocol and into
an implicitly-declared generic parameter list for the protocol. This
makes all of the methods of a protocol polymorphic, e.g., given
protocol P {
typealias Assoc
func getAssoc() -> Assoc
}
the type of P.getAssoc is:
<Self : P> (self : @inout P) -> () -> Self.Assoc
This directly expresses the notion that protocol methods are
polymorphic, even though 'Self' is always implicitly bound. It can be
used to simplify IRgen and some parts of the type checker, as well as
laying more of the groundwork for default definitions within
protocols as well as sundry other improvements to the generics
system.
There are a number of moving parts that needed to be updated in tandem
for this. In no particular order:
- Protocols always get an implicit generic parameter list, with a
single generic parameter 'Self' that conforms to the protocol itself.
- The 'Self' archetype type now knows which protocol it is
associated with (since we can no longer point it at the Self
associated type declaration).
- Protocol methods now get interface types (i.e., canonicalizable
dependent function types).
- The "all archetypes" list for a polymorphic function type does not
include the Self archetype nor its nested types, because they are
handled implicitly. This avoids the need to rework IRGen's handling
of archetypes for now.
- When (de-)serializing a XREF for a function type that has an
interface type, use the canonicalized interface type, which can be
meaningfully compared during deserialization (unlike the
PolymorphicFunctionType we'd otherwise be dealing with).
- Added a SIL-specific type attribute @sil_self, which extracts the
'Self' archetype of a protocol, because we can no longer refer to
the associated type "P.Self".
Swift SVN r9066
This commit is contained in:
@@ -402,7 +402,7 @@ namespace decls_block {
|
||||
IdentifierIDField, // name
|
||||
BCFixed<1>, // primary?
|
||||
TypeIDField, // index if primary, parent if non-primary
|
||||
DeclIDField, // associated type decl
|
||||
DeclIDField, // associated type or protocol decl
|
||||
TypeIDField, // superclass
|
||||
BCArray<DeclIDField> // conformances
|
||||
// Trailed by the nested types record.
|
||||
@@ -506,6 +506,7 @@ namespace decls_block {
|
||||
GENERIC_TYPE_PARAM_DECL,
|
||||
IdentifierIDField, // name
|
||||
DeclIDField, // context decl
|
||||
BCFixed<1>, // implicit flag
|
||||
BCVBR<4>, // depth
|
||||
BCVBR<4>, // index
|
||||
TypeIDField, // superclass type
|
||||
@@ -564,6 +565,7 @@ namespace decls_block {
|
||||
BCFixed<1>, // class protocol?
|
||||
BCFixed<1>, // objc?
|
||||
BCArray<DeclIDField> // protocols
|
||||
// Trailed by the generic parameters (if any) and the decl context record
|
||||
>;
|
||||
|
||||
using ConstructorLayout = BCRecordLayout<
|
||||
|
||||
Reference in New Issue
Block a user