Commit Graph

1292 Commits

Author SHA1 Message Date
John McCall
8c0a464f2e Just one implementation of hasKnownSwiftImplementation.
Swift SVN r3742
2013-01-11 08:08:55 +00:00
John McCall
2e0070e229 Emit metaclass stub objects for swift classes.
Swift SVN r3740
2013-01-11 08:08:50 +00:00
Chris Lattner
47dbc4051c update for mainline LLVM header file moves.
Swift SVN r3634
2013-01-02 14:38:42 +00:00
John McCall
f44ff7bc62 Add offsets in class metadata for fields of generic classes.
The exact condition is that the field's offset might be contingent
on a generic parameter.

Swift SVN r3543
2012-12-19 08:45:52 +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
6c2b8a2949 Easy case of superclass references in class metadata.
The somewhat harder one is when the superclass is generic in
some way.

The much harder one (given the current representation) is when
the superclass is generic and *expressed in terms of the current
class's own generic arguments*.

Swift SVN r3477
2012-12-13 10:28:28 +00:00
John McCall
86f4aacdad Basic infrastructure for emitting class_ro_t structures.
Swift SVN r3476
2012-12-13 10:28:24 +00:00
John McCall
ce46c72906 Fix and test metadata-to-class mapping.
Swift SVN r3426
2012-12-10 08:18:07 +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
Doug Gregor
bb26f52585 Initial support for loading Clang modules into Swift.
From a user's perspective, one imports Clang modules using the normal
Swift syntax for module imports, e.g.,

  import Cocoa

However, to enable importing Clang modules, one needs to point Swift
at a particular SDK with the -sdk= argument, e.g.,

  swift -sdk=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9M.sdk

and, of course, that SDK needs to provide support for modules.

There are a number of moving parts here. The major pieces are:

CMake support for linking Clang into Swift: CMake users will now need
to set the SWIFT_PATH_TO_CLANG_SOURCE and SWIFT_PATH_TO_CLANG_BUILD
to the locations of the Clang source tree (which defaults to
tools/clang under your LLVM source tree) and the Clang build tree.

Makefile support for linking Clang into Swift: Makefile users will
need to have Clang located in tools/clang and Swift located in
tools/swift, and builds should just work.

Module loader abstraction: similar to Clang's module loader,
a module loader is responsible for resolving a module name to an
actual module, loading that module in the process. It will also be
responsible for performing name lookup into that module.

Clang importer: the only implementation of the module loader
abstraction, the importer creates a Clang compiler instance capable of
building and loading Clang modules. The approach we take here is to
parse a dummy .m file in Objective-C ARC mode with modules enabled,
but never tear down that compilation unit. Then, when we get a request
to import a Clang module, we turn that into a module-load request to
Clang's module loader, which will build an appropriate module
on-the-fly or used a cached module file.

Note that name lookup into Clang modules is not yet
implemented. That's the next major step.



Swift SVN r3199
2012-11-16 18:17:05 +00:00
John McCall
3c053a7b98 In preparation for shifting the metadata layout, widen
the metadata kind field to a full word.

Swift SVN r3183
2012-11-14 08:45:29 +00:00
John McCall
23651be7ef Don't distinguish between generic and non-generic types in
the metadata kind.

I don't think this is actually a particularly useful thing
to track, especially since a non-generic type can be
generically parented or have a generic superclass or two.

Swift SVN r3182
2012-11-14 08:45:24 +00:00
John McCall
5eb36187d6 Teach IR-gen how to emit metatypes for metatypes.
Swift SVN r3180
2012-11-14 08:45:17 +00:00
John McCall
7d69b0e3c5 Metatypes of (metatypes of)* class types have a
non-trivial representation.

This is because subtyping extends infinitely meta-wards
in the metatype hierarchy:  the one thing you can do
with a metatype of a metatype is pull the instance
metatype out, but that instance type is still a subtype
of the instance type of the metatype of the base metatype,
so... just trust me on this.

Swift SVN r3178
2012-11-14 08:45:06 +00:00
John McCall
310268c4fd Fix several bugs in the emission of metatype references.
In particular, fix a bug where DREs that refer to types were
always given trivial reps because we were trying to emit the
metatype's metatype.  This in turn exposes a number of bugs,
including a typechecker bug (where GetMetatypeExpr bases
weren't converted to r-values) and a bug where MREs that
refer to types were always assumed to produce trivial reps.

Swift SVN r3095
2012-10-31 08:09:28 +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
0548cc7cff Cache local metadata in the scope in which we compute it,
to avoid some obvious redundancies.  This also gives us a
more general framework with which to exploit other ways
in which metadata is known.

Swift SVN r3047
2012-10-23 23:30:23 +00:00
John McCall
e8d5f08e94 Fix/suppress some warnings arising in newer clangs
as reported by Chris.

Swift SVN r3044
2012-10-23 08:12:08 +00:00
John McCall
85490080c2 Make protocol thunks expect a metatype pointer (for This) as
their last argument.  Pass it down correctly.

Swift SVN r3042
2012-10-23 07:59:35 +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
98aa71f424 Move EmptyTypeInfo into GenType.cpp
Swift SVN r2970
2012-10-11 00:36:04 +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
179e260ea3 Add an abstraction to encapsulate a Decl + explosion level +
uncurrying level, which is something I find myself passing around
quite a bit.  Make sure that it can propagate getter/setter
references in the same way.

Swift SVN r2902
2012-09-28 05:21:24 +00:00
John McCall
3467e63516 Emit pointers to final overriders of member functions into
the metadata objects for classes.  This is currently only
done for methods defined in the main class body, and it's
(naturally) totally fragile, and it's screwed up in a
couple known ways w.r.t. generic classes:  there's no
thunking when the overrider differs by abstraction from
the overridden method, and methods on classes currently
expect to get all the type arguments passed directly
and thus will disagree in signature from members of
non-generic classes.  Also, of course, we're not using
any of this in the call infrastructure.  But it's progress.

Swift SVN r2901
2012-09-27 06:17:46 +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
2c21ee7796 Add the compiler infrastructure for emitting references to tuple and
function metadata.

Swift SVN r2864
2012-09-18 07:23:51 +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
6c821ddc1b Support allocating local objects of archetype type, at least in
theory.

Swift SVN r2245
2012-06-25 20:45:04 +00:00
John McCall
770ce0fde7 Refactor to make it easier to keep common information in
the type converter.

Swift SVN r2241
2012-06-25 20:44:59 +00:00
John McCall
e2440ff94c Split TypeInfo into its own header.
Swift SVN r2240
2012-06-25 20:44:51 +00:00
John McCall
72ebeee76f Try to optimize assignment a bit more, and fix assignment
of protocol types to correctly handle self-assignment.
This ends up creating such a large amount of code that it's
worth extracting into its own helper function.  Fortunately,
this can be the same helper function for every protocol type.

Swift SVN r1905
2012-05-19 06:46:05 +00:00
John McCall
b3b71178a5 Fix a pair of bugs with partial updates of logical l-values:
first, we weren't registering the cleanup for the temporary
if it needed materialization, and second, we were potentially
double-consuming cleanups associated with the l-value, e.g.
subscript indices.

Swift SVN r1631
2012-04-25 09:39:22 +00:00
John McCall
bc32a8aedb Fix a bug with returning value that need to be refcounted:
we want to do a take-load out of the return address slot
instead of a normal load, or else we'll end up +1'ing an
already +1 value.

Swift SVN r1564
2012-04-23 17:47:07 +00:00
John McCall
f3e27d90ff Change IR-generation so that it emits metadata objects for the
heap allocations it makes, and switch swift_alloc over to pass
that pointer in as well as the alignment.  Also, compute
whether a type is POD during its generation and cache that in
the object, and introduce a method on TypeInfo to destroy an
object in memory.

Swift SVN r1356
2012-04-10 06:28:22 +00:00
John McCall
ca9f85d694 Add code for associating cleanups with intermediate
evaluation results and then claiming or forwarding the
ownership of such results.

Swift SVN r1337
2012-04-06 07:07:28 +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