Commit Graph

816 Commits

Author SHA1 Message Date
Joe Groff
4ff8cd27dd IRGen: Abstract out an "unknown refcounted" concept.
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
2013-06-17 18:31:49 +00:00
Joe Groff
34dc94679d IRGen: Get objc protocol erasure working.
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
2013-06-16 05:06:28 +00:00
Joe Groff
61292d7993 IRGen: Leave ObjC protocols out of existential type layout.
ObjC protocols don't require witness tables and so don't need to be included in protocol existential container layout.

Swift SVN r5602
2013-06-15 22:29:43 +00:00
Joe Groff
24acecc0d3 IRGen: Fix uninitialized "needs metatype" flag in WitnessTableBuilder.
Move the initialization of NeedsExtraMetatype before an early exit from the constructor that I missed. Oops.

Swift SVN r5597
2013-06-15 17:40:46 +00:00
Joe Groff
d4f9579eac IRGen: Class-bounded generics don't need extra metatype data.
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
2013-06-15 16:10:04 +00:00
Joe Groff
b1aff68da9 Allow [class_protocol] protocols to be [objc].
Swift SVN r5591
2013-06-15 00:41:32 +00:00
Joe Groff
f678700dce IRGen: Implement class-bounded existential containers.
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
2013-06-14 14:52:47 +00:00
Joe Groff
5c8c9f9fb1 IRGen: Tweak witness 'This' binding to allow class-bounded archetypes.
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
2013-06-11 16:40:08 +00:00
Joe Groff
087803f5b0 IRGen: Implement type info for class-bounded archetypes.
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
2013-06-11 00:19:34 +00:00
Joe Groff
5e2779b51e SIL: Uncurry function types within the Swift type system.
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
2013-05-24 01:51:07 +00:00
Joe Groff
c4317411b6 IRGen: Use SILType in functions used for existential container insts.
Swift SVN r5191
2013-05-16 22:47:49 +00:00
Joe Groff
cdf95e6c5a IRGen: Use SILTypes when dispatching archetype/existential methods.
Swift SVN r5153
2013-05-10 22:26:24 +00:00
Joe Groff
667ef5d651 IRGen: Look up metatypes and class methods using SIL types.
Swift SVN r5150
2013-05-10 21:20:11 +00:00
Joe Groff
197c3e6d02 IRGen: Strip unneeded parameters from IRGenFunction constructor.
Swift SVN r5146
2013-05-10 18:18:14 +00:00
Joe Groff
223d0251bd IRGen: Add getFragileTypeInfo and getFunctionType for SIL types.
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
2013-05-10 16:28:25 +00:00
John McCall
757c0ae304 Track whether a type is POD and whether it uses inline or allocated
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
2013-05-10 06:16:33 +00:00
John McCall
462c9603ea Demote emitLoadOfValueWitness from being API.
Swift SVN r5137
2013-05-10 06:16:31 +00:00
John McCall
d8cdb0160f Switch IR-generation to generally traffic in alignment
masks rather than raw alignments.

Swift SVN r5136
2013-05-10 06:16:28 +00:00
Doug Gregor
82ef1ee2d5 Remove an over-eager assertion when setting the value witness table for an archetype.
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
2013-05-06 20:37:11 +00:00
Joe Groff
1706f912a9 IRGen: Consider bound generic archetypes from substitutions rather than params.
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
2013-05-06 17:43:38 +00:00
Joe Groff
ef522f7a9b IRGen: Fix inaccurate assert in PolymorphicConvention.
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
2013-05-03 16:40:17 +00:00
Joe Groff
d91f78556a IRGen: Implement protocol typeof.
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
2013-05-03 01:00:06 +00:00
Joe Groff
08b6f87524 Add 'typeof' to value witness tables.
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
2013-05-01 18:49:25 +00:00
John McCall
1fec73a8d2 Untested support for tuples with generically-sized elements.
Swift SVN r4926
2013-04-26 21:33:24 +00:00
John McCall
c74ad61247 Extract functions to work with value witnesses into their own file.
Swift SVN r4924
2013-04-26 21:33:21 +00:00
John McCall
24c55531ea Promote emitTypeMetadataRef to being "top-level" IGF API.
Swift SVN r4920
2013-04-26 18:48:33 +00:00
Joe Groff
bcb49ce450 SIL: Key functions directly without SILConstant.
Replace 'constant_ref' with 'function_ref', which references a SILFunction directly, and 'global_addr', which references a global variable VarDecl. Get rid of the SILConstant-to-SILFunction mapping in SILModule and replace it with an ilist of SILFunctions. Allow SILFunctions to be 'external' by not having any blocks in their body. 

For now, SILFunctions still carry around their SILConstant "name", because name mangling and IRGen still rely on access to the original decl in order to recover IRGen information, which unfortunately leaves IRGen's CodeRefs in a gross, awkward intermediate state. Lifting mangling, AbstractCC, and other linkage attributes to SIL should clear up this up.

Swift SVN r4865
2013-04-23 23:29:04 +00:00
Chris Lattner
2b6902b232 eliminate the "manage" operation on TypeInfo, which is now a (complicated!) noop.
Swift SVN r4850
2013-04-21 16:27:43 +00:00
Chris Lattner
5664431c9a remove Cleanup.h and references to the Cleanup class, along with
some dead logic in IRGenFunction.



Swift SVN r4847
2013-04-21 06:36:22 +00:00
Chris Lattner
85663f6df2 simplify Explosion by eliminating (now) copies of existing methods.
This removes addUnmanaged, ignoreAndDestroy, ignoreUnmanaged, claimUnmanagedNext,
claimUnmanaged, forwardNext, and forward


Swift SVN r4846
2013-04-21 06:29:50 +00:00
Chris Lattner
9ae0cf3bee inline Initialization::emitLocalAllocation into each of its callers and
eliminate the Initialization class and GenInit.h.  GenInit.cpp will stay
around, as it has some other random stuff in it.


Swift SVN r4845
2013-04-21 06:13:59 +00:00
Chris Lattner
d523932d85 remove InitializedObject.
Swift SVN r4844
2013-04-21 06:05:01 +00:00
Chris Lattner
0be7bbdddf remove ManagedValue.
Swift SVN r4843
2013-04-21 05:56:02 +00:00
Chris Lattner
e8686c9560 remove Cleanups from IGF, simplify Initialization a bit.
Swift SVN r4841
2013-04-21 05:28:04 +00:00
Chris Lattner
e3d6a489af remove the Cleanup subclasses.
Swift SVN r4839
2013-04-21 05:06:52 +00:00
Chris Lattner
abee79b26e remove some Expr stuff.
Swift SVN r4810
2013-04-18 22:32:37 +00:00
John McCall
38b34b7307 Pass #1 at localizing assumptions about fixed layout and
handling non-fixed layouts.

This uncovered a bug where we weren't rounding up the header
size to the element alignment when allocating an array of archetypes.

Writing up a detailed test case for *that* revealed that we were
never initializing the length field of heap arrays.  Fixing that
caused a bunch of tests to crash trying to release stuff.  So...
I've left this in a workaround state right now because I have to
catch a plane.

Swift SVN r4804
2013-04-18 07:58:21 +00:00
Chris Lattner
edee9a5d60 remove some dead protocol logic.
Swift SVN r4801
2013-04-18 05:45:29 +00:00
Chris Lattner
47e508c24d remove LValue, PathComponent, and LValue.h as a whole.
Swift SVN r4792
2013-04-18 04:50:03 +00:00
Chris Lattner
ac6dbfb604 remove some protocol stuff, which is the last user of emitFakeLValue.
Remove emitFakeLValue, the last user of emitAddressLValue.


Swift SVN r4790
2013-04-18 04:42:49 +00:00
John McCall
eb70c35af7 Bitcast before turning the parameter into an Address in order
to placate an assert.

Test suite passes now.

Swift SVN r4781
2013-04-17 22:27:34 +00:00
John McCall
116a2422ab These arguments aren't cast; don't use the asserting routine.
Swift SVN r4780
2013-04-17 22:17:02 +00:00
John McCall
8fe4246833 Hide StorageSize/Alignment behind accessors in preparation for moving
them to a subclass.

Swift SVN r4779
2013-04-17 21:55:41 +00:00
Chris Lattner
ffe3388aa5 remove the dead logic form GenTuple, RValueInitEmitter, and some
erasure/protocol expr logic.


Swift SVN r4775
2013-04-17 06:34:27 +00:00
Chris Lattner
01a36864a3 Remove LogicalPathComponent, emitLoad, emitAssign, emitLValueAsScalar,
and supporting logic.

PathComponent and LValue are (apparently unnecessarily) kept alive by 
projectPhysicalClassMemberAddress (rdar://13671033)



Swift SVN r4773
2013-04-17 06:00:34 +00:00
Chris Lattner
ade66c8b10 Remove the emitIgnored, emitLValue, and tryEmitAsAddress mechanics and
supporting logic.


Swift SVN r4770
2013-04-17 05:33:23 +00:00
Joe Groff
c217d69779 IRGen: Fix ArchetypeMethodInst for static funcs.
The argument to archetype_method can be a metatype, so allow that. While we're here, implement lowering for AssociatedMetatypeInst, and fix initial bringup of SIL-IRGen so that polymorphic arguments get emitted into the entry point BB instead of a random other BB.

Swift SVN r4741
2013-04-15 22:21:45 +00:00
Joe Groff
9ff6e65af0 IRGen: Lower SIL ArchetypeMethodInst.
ArchetypeMethodInst, like ProtocolMethodInst, actually needs to be modeled as returning a thick function type, in order to represent the metadata parameter to the witness table function. With that change to SILGen, implement ArchetypeMethodInst IRGen.

Swift SVN r4688
2013-04-11 22:24:26 +00:00
Chris Lattner
7f13910498 revert r4673: respecializing SILConstant for ValueDecl instead of Decl.
On second thought, having SILConstant be able to point to a TLCD is going 
against the goal of making SILConstant be a "SILGen thing".  I'll find another
approach.


Swift SVN r4680
2013-04-11 17:41:36 +00:00
Chris Lattner
f4dfaed4cf generalize SILConstant to hold a Decl*, not just a ValueDecl*.
This is in preparation to allow SILConstant of TopLevelCodeDecl.



Swift SVN r4675
2013-04-11 00:46:36 +00:00