Have WitnessBuilder awkwardly ask SIL's TypeConverter to uncurry witness types, so that polymorphic arguments get emitted in the right order consistent with lowered SILFunctions, instead of doing the uncurrying itself directly from the Swift type. This is layer-violating as hell but gets generic witness codegen working. I have a feeling SILGen will want to take over witness thunk emission at some point.
Swift SVN r6401
If a protocol requirement is satisfied by a generic method, we'll need to save the substitutions necessary to call that method from the witness thunk. This patch adds the spot in the ProtocolConformance::Mapping to save the substitutions; for now, always leave it empty and update the code for the type change.
Swift SVN r6399
When an existential's contained type is used as a generic parameter, unwrap the existential container and save its metadata and witnesses to be used as polymorphic arguments.
Our AST representation can't quite express the distinction between a type parameter being satisfied by the existential type itself from being satisfied by the existential's contained yet. I use a goofy heuristic where I assume a protocol type bound to a type variable with no requirements is satisfied by the protocol type itself; this covers all of the existing <T> (Slice<T>, T) cases that come up in the library, while enabling the <T:Foo> (T) cases. This hopefully addresses <rdar://problem/14470097> well enough to unblock library work until we get a solid AST representation of this difference.
Swift SVN r6352
The idea for now is that this is a SIL-only type used for
representing the storage of a weak or unowned reference.
Having it be its own type is pretty vital for reasonable
behavior in SIL and IR-generation, and it's likely that
this will surface into runtime metadata as well (hence
the mangling).
I've implemented a bunch of things that technically I don't
think are necessary if this stays out of the typechecker,
but it's easier to implement half-a-dozen "recurse into
the child type" methods now that it would be to find them
all later if we change our minds.
Swift SVN r6091
Improve our representations of casts in the AST and SIL so that 'as!' and 'is' (and eventually 'as?') can share almost all of the same type-checking, SILGen, and IRGen code.
In the AST, we now represent 'as!' and 'is' as UnconditionalCheckedCastExpr and IsaExpr, respectively, with the semantic variations of cast (downcast, super-to-archetype, archetype-to-concrete, etc.) discriminated by an enum field. This keeps the user-visible syntactic and type behavior differences of the two forms cleanly separated for AST consumers.
At the SIL level, we transpose the representation so that the different cast semantics get their own instructions and the conditional/unconditional cast behavior is indicated by an enum, making it easy for IRGen to discriminate the different code paths for the different semantics. We also add an 'IsNonnull' instruction to cover the conditional-cast-result-to-boolean conversion common to all the forms of 'is'.
The upshot of all this is that 'x is T' now works for all the new archetype and existential cast forms supported by 'as!'.
Swift SVN r5737
Use the new swift_dynamicCastIndirect runtime functions to implement casts from opaque archetype and existential types to concrete types.
Swift SVN r5684
Just refer to "class archetypes" and "class protocols". Change 'isClassBounded' methods to 'requiresClass', which is a character shorter.
Swift SVN r5674
If an archetype has a superclass bound, we can assume the superclass's
retain semantics for the type. We can also use the superclass's storage pointer type to cut down on some bitcast IR noise when calling superclass methods on the archetype value.
Swift SVN r5642
Provide a lowering for the DeinitExistential instruction to deallocate the buffer in an existential container with an uninitialized value, using its deallocateBuffer witness.
Swift SVN r5623
In the implementation of class-bounded archetypes and existentials, instead of referring to ObjC pointer types and retain/release operations directly, use an 'UnknownRefCountedPtrTy' and 'emitUnknownRetain/Release' functions.
Swift SVN r5619
Don't try to emit witness tables for protocols that don't need them when emitting a protocol erasure. (We'll need to eventually ensure that ObjC method metadata gets generated for the conforming methods, but we don't yet, so this will only work for types that already have ObjC-dispatchable methods.)
Swift SVN r5610
Since the type metadata for the underlying method will be taken from the class instance, the witness entry point for a class-bounded protocol conformance doesn't need to pass on an extra metatype parameter for the 'This' archetype.
Swift SVN r5595
Provide TypeInfo for class-bounded existentials, which represents them as an explosion comprising one witness table per subscribed protocol and then the class instance pointer as an ObjC-refcounted pointer. Provide lowerings for the SIL instructions that manipulate class-bounded existentials (except for existential-to-existential erasures, which aren't critical to getting basic operations working and will need some abstraction remapping to deal with class-bounded-to-opaque upcasts aside from the representation change).
Swift SVN r5579
Handle the case of a 'this' parameter of 'This' type not being an LValueType or MetaTypeType, which happens for class-bounded protocols. This gets witness emission working for class-bounded archetypes.
Some abstraction remapping still needs to be implemented when non-class-bounded methods are accessed from a class-bounded archetype with a mix of class-bounded and non-class-bounded protocol constraints, to remap the class-bounded archetype to its opaque representation.
Swift SVN r5573
Split ArchetypeTypeInfo into ClassBoundedArchetypeTypeInfo, for class-bounded archetypes, and OpaqueArchetypeTypeInfo, for fully generalized archetypes (the existing case). ClassBoundedArchetypeTypeInfo is represented using a single refcounted ObjCPointer. Implement abstraction remapping from class instances to class-bounded archetypes and back, and from class-bounded archetypes to non-class-bounded and back.
Witness tables are still generated only for opaque archetypes, so method calls on class-bounded archetypes won't work just yet.
Swift SVN r5569
Remove uncurry level as a property of SILType/SILFunctionTypeInfo. During SIL type lowering, map a (Type, UncurryLevel) pair to a Swift CanType with the uncurried arguments as a Swift tuple. For example, T -> (U, V) -> W at uncurry level 1 becomes ((U, V), T) -> W--in reverse order to match the low-level calling convention. Update SILGen and IRGen all over the place for this representation change.
SILFunctionTypeInfo is still used in the SILType representation, but it's no longer load-bearing. Everything remaining in it can be derived from a Swift type.
This is an ABI break. Be sure to rebuild clean!
Swift SVN r5296
Add overloads of getFragileTypeInfo and getFunctionType that take a SILType instead of a Swift CanType, and use them where it's easy to do so. Right now they just forward to the CanType versions, but we'll want to do SILType-specific type conversion soon. Clean up some IRGenSILFunction interfaces now that SILFunction carries most of the information IRGen needs intrinsically. No functionality change.
Swift SVN r5141
storage in a flags word in the value witness table. Pack the
alignment into only 16 bits of this word. Optimize tuple value
witnesses based on whether they're POD and inline.
Swift SVN r5138
Just because we only want the value witness table for an archetype
doesn't mean that the archetype can't have any other requirements; we
just end up ignoring those requirements. Fixes <rdar://problem/13817115>.
Swift SVN r5060
When looking for type metadata for bound generic types, consider all of the BoundGenericType's substitutions instead of just its type parameters. This lets us correctly find the associated type metadata from class instances. We still fail to pass associated type metadata alongside value types.
Swift SVN r5054
A generic NominalTypeDecl can have more archetypes than a BoundGenericType referencing that decl if the requirements of its type parameters introduce associated types. This still doesn't quite fix codegen for class methods that use associated types (e.g. <rdar://problem/13793646>) because we still fail to actually bind metadata for the archetypes of those associated types.
Swift SVN r5035
Represent protocol 'P.metatype' types using the type metadata of the contained metatype. Emit 'typeof' value witnesses for protocol types that project the existential container buffer and then call the 'typeof' witness for the contained value. Implement the SIL protocol_metatype instruction the same way.
You can't quite call static methods on protocols yet because protocol_method doesn't know how to look up static methods from an existential metatype yet.
This breaks references to protocol names—they will try to create an existential metatype that refers to the metadata of the protocol type itself, rather than to the metadata of a conforming type. <rdar://problem/13438779> would fix them.
Swift SVN r5033
To be able to get the dynamic type of a generic value, the 'typeof' operation needs to be part of the value witness for the type. Add 'typeof' to the value witness table layout, and in the runtime, provide standard typeof witnesses for static, Swift class, and ObjC class values.
Swift SVN r5013