Commit Graph

1326 Commits

Author SHA1 Message Date
Jordan Rose
ca498e04ef More -Wdocumentation cleanup.
Swift SVN r5167
2013-05-13 21:41:28 +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
Jordan Rose
77ce3f31cb Add a DeclContextKind for Swift modules.
Swift SVN r5095
2013-05-08 18:33:34 +00:00
Chris Lattner
6c9c6c47a9 revert r5028, re-eliminating Scope since its caching behavior is better handled
by the LLVM IR optimizer.  Tuple metadata refs are now largely
readnone, function metadata refs are already readnone.  There may be some
left that are not, but they can be handled later. 


Swift SVN r5071
2013-05-06 23:27:05 +00:00
Chris Lattner
ca0091a445 add a few "optimized" runtime entrypoints for swift_getTupleTypeMetadata
that handle the 2/3 element cases specially.  These are not actually
optimized at the moment (they just call into swift_getTupleTypeMetadata)
but this could be done at some point.

This is a win for a couple reasons: this reduces the amount of code generated
inline and it allows swift_getTupleTypeMetadata2/3 to be marked readnone,
enabling CSE.  As a driveby, optimize metadata refs of zero element tuples
to directly use _TMdT_, eliminating a branch from swift_getTupleTypeMetadata.



Swift SVN r5070
2013-05-06 23:19:31 +00:00
Joe Groff
d313a4eed1 IRGen: Remove debug dumps.
Swift SVN r5057
2013-05-06 18:31:00 +00:00
Joe Groff
8ac393d0e5 IRGen: Initialize protocol pointer in FindStructWitnessTableIndex.
Fixes structs with constrained generic parameters with associated types.

Swift SVN r5056
2013-05-06 18:28:40 +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
df059d02cc IRGen: Revive scoped metadata caching, at BB level.
John talked me out of this. We still want to cache metadata at the BB level, because even with SIL GVN, there are potentially redundant metadata bits at a level SIL doesn't know about.

Swift SVN r5030
2013-05-02 23:28:31 +00:00
Joe Groff
14cef05844 IRGen: Kill scoped metadata caching.
It doesn't really work with SIL-IRGen, and SIL GVN and LICM will hopefully have the same intended effect eventually.

Swift SVN r5028
2013-05-02 22:17:21 +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
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
0be7bbdddf remove ManagedValue.
Swift SVN r4843
2013-04-21 05:56:02 +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
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
Joe Groff
6af18efae8 IRGen: Use ObjC vwtable for ObjC classes.
Fixes <rdar://problem/13300684>.

Swift SVN r4226
2013-02-27 19:35:00 +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
Jordan Rose
7afd5f0348 Remove the "no Swift bit" hack entirely.
As Doug points out, we won't regress here. All Objective-C runtimes we care
about are correctly ignoring this bit.

<rdar://problem/13065246>

Swift SVN r4052
2013-02-14 23:07:26 +00:00
Joe Groff
9c022d5d65 IRGen: Fudge passing large ObjC structs as byvals.
Push LLVM attribute generation from expandAbstractCC into getFunctionSignature and CallEmission so that they can generate sret and/or byval attributes per-argument according to the calling convention. Copy our bogus rule for emitting sret returns (more than three elements in the explosion) and reuse it to pass large struct values as byvals rather than as explosions. This should be good enough to get both 'NSRect' and
'NSRange', 'NSSize' etc. to pass correctly to ObjC methods. Next step is to set the AbstractCC correctly for imported func decls so that standalone C functions follow the same bogus rule.

Swift SVN r3993
2013-02-08 21:50:08 +00:00
Jordan Rose
14cbc7f39c Allow methods from Objective-C categories to be overridden.
While we don't have a model for overriding methods in Swift extensions yet,
overriding category methods is exactly like overriding any other Objective-C
method, and we shouldn't disallow it.

Swift SVN r3985
2013-02-08 00:19:49 +00:00
Doug Gregor
a9a90fd56a Track the Clang macros that were used to generate Swift constants.
Swift SVN r3960
2013-02-06 00:57:03 +00:00
Joe Groff
18fa3009ea IRGen: Use correct func decl to emit virtual calls
When looking for the least-derived override to index into a vtable, we now have to stop when we see an ObjC decl.

Swift SVN r3890
2013-01-29 01:59:29 +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
Jordan Rose
64719e0be9 [HACK] Fix r3837's test for 10.9 vs. 10.8 systems.
ObviouslUilabilityMacros.h is not the way to go when we're building against
10.9 SDKs on 10.8 systems. Since this is a temporary hack anyway, just make
it based on the  the host syatem ake configuration time, and disable the
failing tests on 10.9.

Swift SVN r3851
2013-01-23 23:23:24 +00:00
Jordan Rose
0d0b4af17e HACK: Don't set the Swift bit in class metadata on 10.9.
The libobjc in current builds can't handle it. <rdar://problem/13046897>
We are going to want this bit set, though, so this hack should be
removed once a new libobjc is available. <rdar://problem/13065246>

Swift SVN r3839
2013-01-23 00:01:08 +00:00
John McCall
3713b6a549 Add a framework for distinguishing between deallocating
and non-deallocating destructors and allocating/non-allocating
constructors.

Non-deallocating destructors might not play well with ObjC
classes;  we might have to limit them to pure-swift hierarchies.

No functionality change except that I decided to not force
destructors to have internal linkage unconditionally.

Swift SVN r3814
2013-01-20 19:40:12 +00:00
John McCall
2d03621435 Fill in _objc_empty_cache and _objc_empty_vtable.
The ObjC ABI requires these class fields to be initialized by
resolving symbols from the runtime.  So this is a historical
requirement.  Note that there is a desire to optimize this
even for ObjC, because in a project with many classes, these
can actually end up representing a significant fraction of
the external non-lazy relocations in the linked image.  But
for now we follow the spec, as we must.
The ObjC ABI requires these to be taken from the runtime,
although there is an effort to make them not require external
relocations like this, since in large projects it can actually
add up to a large percentage of the non-lazy external relocs.
3,6d
2i

Swift SVN r3804
2013-01-19 10:06:47 +00:00
Joe Groff
0422897a47 Expose %swift.opaque as a builtin type.
Archetypes and projected existentials have the type %swift.opaque* and not i8*, so I need a corresponding SIL type to be able to model the ProjectExistential operation. We might also end up needing the builtin type for other low-level things down the line.

Swift SVN r3793
2013-01-18 02:24:23 +00:00
John McCall
02c3c8703d Collect references to non-generic classes in __DATA,__objc_classlist.
Swift SVN r3788
2013-01-17 23:54:09 +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
61dd2646f1 Add a flag (always true) for whether to support ObjC interop.
Swift SVN r3744
2013-01-11 08:09:01 +00:00
John McCall
f6838659ff Use SwiftObject as an implicit super class on swift root classes.
Swift SVN r3743
2013-01-11 08:08:57 +00:00
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