Commit Graph

134 Commits

Author SHA1 Message Date
Doug Gregor
b5af687b6d Emit and use vtable entries for abstract initializers.
Emit vtable entries for abstract initializers. When we're constructing
an object using an abstract initializer based on a metatype value that
is not statically derivable, use the vtable entry to call the
subclass's allocating constructor.

Most of the IRGen work here is hacking around the lossy SILDeclRef ->
(Code|Function)Ref -> SILDeclRef conversion. I'd feel bad about this
if John hadn't already agreed to clean this up at some point.



Swift SVN r14238
2014-02-21 23:15:46 +00:00
John McCall
a1b469ed2f ExplosionKind -> ResilienceExpansion. NFC.
Swift SVN r12364
2014-01-16 00:25:29 +00:00
Joe Groff
14362cd8e2 IRGen: Lower metatypes respecting SIL's 'thin' bit.
Use the 'thin' bit set by SIL to decide whether a metatype lowers to an empty type or not. In GenPoly we still need to accommodate unlowered metatypes to keep protocol witnesses limping along; hopefully that code can be killed soon. With this change we now lower @cc(witness_method) consistently for static methods.

Swift SVN r11535
2013-12-21 02:05:37 +00:00
Joe Groff
017440165e Fix the weird capitalization of MetaTypeType.
Swift SVN r11475
2013-12-19 18:43:08 +00:00
John McCall
20e58dcf93 Change the type of function values in SIL to SILFunctionType.
Perform major abstraction remappings in SILGen.  Introduce
thunking functions as necessary to map between abstraction
patterns.

Swift SVN r10562
2013-11-19 22:55:09 +00:00
Joe Groff
bbddf41693 IRGen: Instantiate existential metadata through the runtime.
When we need a reference to protocol or protocol composition type metadata, ask for it through the runtime, instead of referencing statically-emitted protocol metadata.

Swift SVN r9871
2013-11-01 17:13:49 +00:00
Joe Groff
9ab5414609 IRGen: Load dependent class instance size and alignment from metadata.
When allocating and deallocating dependent generic class instances, load the instance size and alignment from the metadata instead of trying to use a static size from the compile-time class layout.

Swift SVN r9250
2013-10-12 02:57:41 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Joe Groff
46fd1c91b3 IRGen: Emit metadata and value witness tables for nongeneric unions.
And remove the hokey hardcoded metadata for Bool from the runtime.

Swift SVN r7541
2013-08-23 23:09:26 +00:00
Joe Groff
398cbba5be Rename SILConstant to SILDeclRef.
"SILConstant" doesn't really describe its role in SIL anymore, which is to provide a reference to a Swift declaration in a SIL instruction, such as a method or nominal type field.

Swift SVN r6559
2013-07-24 21:21:31 +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
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
0566088bf2 Move name mangling into SIL.
Sever the last load-bearing link between SILFunction and SILConstant by naming SILFunctions with their mangled symbol names. Move the core of the mangler up to SIL, and teach SILGen how to use it to mangle a SILConstant.

Swift SVN r4964
2013-04-28 03:32:41 +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
a9f747ec1f IRGen: Emit categories for ObjC class extensions.
Emit ObjC stubs and categories for methods defined in extensions of ObjC-compatible classes. This makes extensions of ObjC classes available to ObjC in statically compiled code. For immediate-mode code we'll still need to dynamically register extension methods using the ObjC runtime.

Swift SVN r4149
2013-02-22 05:40:09 +00:00
Joe Groff
95a6e4db87 IRGen: Don't emit ObjC methods into vtables.
ObjC methods always need to be invoked through objc_msgSend, so they shouldn't have vtable slots, and Swift subclasses that override ObjC methods should always insert override slots into their vtables.

Swift SVN r3889
2013-01-29 01:18:47 +00:00
John McCall
d4f80a3993 Introduce a ClassLayoutBuilder and use it to build layouts.
The test changes are that we're setting a class body on
some types that we weren't before.  For some of these,
this is okay;  for others, it's more questionable, but
ultimately not *harmful*.

Swift SVN r3746
2013-01-11 08:09:06 +00:00
John McCall
8c0a464f2e Just one implementation of hasKnownSwiftImplementation.
Swift SVN r3742
2013-01-11 08:08:55 +00:00
John McCall
d01b272531 Untested infrastructure for emitting non-constant field accesses.
Swift SVN r3542
2012-12-19 08:45:47 +00:00
John McCall
c6374093f6 Add support for messaging Objective-C classes.
Notably, there is still no support for +1 return values,
so we'll leak when doing alloc/init and so on;  but this gets
the fundamentals in place.  A lot of the extra stuff in here
is dealing with mapping between metatypes and class objects.

Swift SVN r3425
2012-12-10 08:18:03 +00:00
John McCall
59d4677b35 Implement metatype references to ObjC classes.
The interesting thing here is that we need runtime support in
order to generate references to metatypes for classes, mostly
because normal ObjC classes don't have all the information we want
in a metatype (which for now just means the VWT pointer).
We'll need to be able to reverse this mapping when finding a
class pointer to hand off to, say, an Objective-C class method,
of course.

Swift SVN r3424
2012-12-10 08:17:57 +00:00
John McCall
65db19395d Make metatype layout compatible with struct objc_class.
The principal difficulty here is that we need accessing the
value witness table for a type to be an efficient operation,
but there (obviously) isn't a VWT field for ObjC classes.
Placing this field after the metatype would tend to bloat
metatypes by quite a bit.  Placing it before is best, but
it introduces an unfortunate difference between the address
point of a metatype and the address of the global symbol.
That, however, can be fixed with appropriate linker support.
Still, for now this is rather unfortunately over-subtle.

Swift SVN r3307
2012-11-30 02:47:01 +00:00
John McCall
2f8f05615e Rename TypeOfExpr / TypeOfInst to MetatypeExpr / MetatypeInst.
Introduce a '.metatype' form in the syntax and do some basic
type-checking that I probably haven't done right.  Change
IR-generation for that and GetMetatypeExpr to use code that
actually honors the dynamic type of an expression.

Swift SVN r3053
2012-10-24 07:54:23 +00:00
John McCall
f4dd62dee7 Metatypes for class types have non-trivial representation.
Swift SVN r2971
2012-10-11 00:36:05 +00:00
John McCall
ae978371ac Make calls to non-static methods on classes use virtual
dispatch.  Currently there is no possibility of override.

This was really not as difficult as I managed to make it
the first time through.

Swift SVN r2960
2012-10-10 01:31:47 +00:00
John McCall
37d024bd38 bindGenericArchetypes is now just how we emit polymorphic
functions on class types, so we can kill all that special code.

Swift SVN r2943
2012-10-05 01:54:52 +00:00
John McCall
6e9a2aab8b Fix a conceptual bug in class metadata: the parent pointer
of a class is part of the class members section and is not
global to the entire class metadata.  This is crucial for
correct operation of functions expecting a base-class
metadata object.

That gives us the correct foundation to implement an
optimization under which generic arguments that can be
inferred from the 'this' pointer need not actually be
separately passed.  This has the important result of
making all class member functions with the same signature
up to abstraction actually have the same physical
signature.

Swift SVN r2936
2012-10-04 23:44:31 +00:00
John McCall
1f5b775bc7 Use metatype pointers as generic type arguments. Movements
towards optimizing generic calls to derive things from the
'this' pointer, which is actually crucial for virtual
dispatch (to get all methods to agree about how the
implicit arguments are passed).  Fix a number of assorted
bugs in metadata emission.  Lots of assorted enhancements.

This was proving surprisingly difficult to actually tease
apart into smaller patches.

Swift SVN r2927
2012-10-03 08:57:40 +00:00
John McCall
32cc48dc84 More restructuring and start emitting struct metadata.
Swift SVN r2892
2012-09-21 07:53:02 +00:00
John McCall
2d03d842f5 Move class metadata emission into GenMeta.cpp. The main
motivation for this is to re-use code involving generic nominal
types.

Swift SVN r2891
2012-09-21 07:52:58 +00:00
John McCall
5b10c5df32 Move emitClassMetadataRef to GenMeta.cpp and make it work for
an arbitrary metadata type.

Swift SVN r2862
2012-09-18 07:23:44 +00:00
John McCall
d789a32827 Module and metatype types are first-class right now, so don't
fail to handle them.

Swift SVN r1271
2012-03-27 22:13:34 +00:00