Commit Graph

834 Commits

Author SHA1 Message Date
Doug Gregor
a87d65d617 Bridge NSArray <-> AnyObject[].
Allows AnyObject[] to occur in @objc methods/properties/etc., then
bridges between the two in SILGen based on the new array
implementation. <rdar://problem/16535097>.

Note that this commit does not change the Clang module importer to
import NSArray* as AnyObject[] (yet).


Swift SVN r16004
2014-04-07 05:49:48 +00:00
Joe Groff
fea886d048 SILGen: Bridge the C*VoidPointer types to COpaquePointer.
Swift SVN r15868
2014-04-03 15:03:48 +00:00
Joe Groff
8102dee6f0 SILGen: Bridge ObjCMutablePointer.
Make ObjCMutablePointer @objc-able for (potentially optional) class types, and bridge it down to UnsafePointer when calling @objc entry points.

Swift SVN r15838
2014-04-02 22:49:32 +00:00
Jordan Rose
fc6b20369f Only generate derived conformance bodies for decls in the primary source file.
...and for decls imported from Clang, because those don't have home locations.

Fixes <rdar://problem/15936403>

Swift SVN r15831
2014-04-02 21:00:49 +00:00
Joe Groff
86faf30617 SILGen: Emit bridging from C*Pointer to UnsafePointer.
When we see CConstPointer or CMutablePointer in a foreign function signature, transparently bridge it to UnsafePointer at the foreign entry point, lifetime-extending the C*Pointer value during foreign calls so that its owner reference is held for the duration of the call.

Swift SVN r15602
2014-03-29 02:50:35 +00:00
Joe Groff
9e5bc637ae Add __FUNCTION__ as a magic literal identifier.
Add __FUNCTION__ to the repertoire of magic source-location-identifying tokens. Inside a function, it gives the function name; inside a property accessor, it gives the property name; inside special members like 'init', 'subscript', and 'deinit', it gives the keyword name, and at top level, it gives the module name. As a bit of future-proofing, stringify the full DeclName, even though we only ever give declarations simple names currently.

Swift SVN r14710
2014-03-06 01:06:06 +00:00
Doug Gregor
b1dfcd7085 Dynamically dispatch when delegating from a complete object initializer.
Inherited initializers are now functional: one can use an inherited
initializer to construct an object of a subclass type, and we properly
handle delegation to overridden complete object or subobject
initializers as appropriate. See the executable test.

This commit also contains various fixes for the IRGen side of vtable
emission and use. Proper IRGen tests still to come.

For now, we're still performing peer delegation from a subobject
initializer to another subobject initializer, hence the SILGen hack
for identifying when we're in a complete object vs. a subobject
initializer. We'll be banning delegation from subobject initializers,
so this hack---along with the peer_method instruction---will be going
away in the near future.



Swift SVN r14571
2014-03-02 08:19:11 +00:00
Doug Gregor
ea16062f75 Basic SILGen support for initializer requirements.
Emit witnesses for initializer requirements. Allow the use of
initializer requirements on archetypes; existentials don't work due to
<rdar://problem/16165890>.


Swift SVN r14356
2014-02-25 23:06:33 +00:00
John McCall
9f6820fadc SILGenModule::getConstantLinkage -> SILDeclRef::getLinkage
Swift SVN r14247
2014-02-22 01:45:40 +00:00
John McCall
3d5d8fdc03 Resilience expansion is really an aspect of a SILDeclRef.
We should also remove it from IRGen's Explosion API; IRGen
should always use maximal explosion, and SILGen will tell us
whether or not we need to put that in memory somewhere.
But that can be a later commit.

Swift SVN r14242
2014-02-21 23:28:43 +00:00
Chris Lattner
db2309101a fix a couple of simple things off argument patterns.
Swift SVN r13914
2014-02-14 18:18:32 +00:00
Chris Lattner
d88852e457 remove SILDeclRef::Getter/Setter and supporting code. NFC, but I think
the previous patches have defined away a few obscure bugs handling subscript 
accessors (from inspection).


Swift SVN r13885
2014-02-14 01:12:56 +00:00
Chris Lattner
51609c1ac8 unbreak ClangModules/ctypes_ir.swift & ClangModules/macros_ir.swift,
imported accessors from clang modules need to be hacked to have shared
linkage, even in the new form.


Swift SVN r13883
2014-02-14 00:48:20 +00:00
Chris Lattner
12196c17ba Now that we always have funcdecls for getters and setters, we don't need
SILDeclRef::Getter/Setter and the complexity therein.  Switch the world
to make SILDeclRef::Func's instead of them.  NFC.


Swift SVN r13875
2014-02-13 23:11:29 +00:00
Jordan Rose
0de8d19514 Define globals for the names of the stdlib, ObjectiveC, and Foundation modules.
This is mostly useful for the standard library, whose name is going to
change to "Swift" soon. (See <rdar://problem/15972383>.) But it's good DRY.

Swift SVN r13758
2014-02-10 22:40:42 +00:00
Chris Lattner
d690a63a87 progress towards non-member observing properties:
- Add a "isDirectPropertyAccess" bit to DeclRefExpr, serving the 
   same purpose as MemberRefExprs for non-member properties.
 - Teach sema to synthesize correct non-member get/set implementations
   for observing properties.
 - Teach silgen to handle the isDirectPropertyAccess bit.



Swift SVN r13600
2014-02-06 22:34:37 +00:00
Joe Groff
0c0d30d5eb SIL: Make ContextGenericParams a constructor parameter of SILFunction.
Edge SILFunction one step closer to independence from SILFunctionType context by taking the generic param list as a separate constructor parameter, and serializing those params alongside the function record. For now we still pass in the context params from the SILFunctionType in most cases, because the logic for finding the generic params tends to be entangled in type lowering, but this pushes the problem up a step.

Thanks Jordan for helping work out the serialization changes needed.

Compared to r13036, this version of the patch includes the decls_block RecordKind enumerators for the GENERIC_PARAM_LIST layouts in the sil_block RecordKind enumerator, as Jordan had suggested before. r13036 caused buildbot failures when building for iOS, but I am unable to reproduce those failures locally now.

Swift SVN r13485
2014-02-05 16:52:02 +00:00
Joe Groff
51001a5910 SILGen: Local definitions in @transparent contexts can't be private.
Importing a transparent definition pulls in references to its local functions and types, so they can't be module-private. Arguably, they should be recursively transparent too, but this is the minimal fix to clear up those annoying 'isExternallyAvailable()' crashes.

Swift SVN r13252
2014-02-01 00:20:02 +00:00
Chris Lattner
3e08673772 Introduce patterns for self arguments to ctors and dtors, making them uniform
with FuncDecls.  This allows us to eliminate special case code for handling
self in various parts of the compiler.

This also improves loc info (debug info and AST info) because 'self' now
has a location instead of being invalid.

I also took the opportunity to factor a bunch of places creating self decls
to use similar patterns and less copy and paste code.



Swift SVN r13196
2014-01-31 02:17:22 +00:00
Michael Gottesman
800ea37c34 Revert r13036 as per Joe's request.
Swift SVN r13063
2014-01-28 21:36:06 +00:00
Joe Groff
5d58f10e48 SIL: Make ContextGenericParams a constructor parameter of SILFunction.
Edge SILFunction one step closer to independence from SILFunctionType context by taking the generic param list as a separate constructor parameter, and serializing those params alongside the function record. For now we still pass in the context params from the SILFunctionType in most cases, because the logic for finding the generic params tends to be entangled in type lowering, but this pushes the problem up a step.

Thanks Jordan for helping work out the serialization changes needed.

Swift SVN r13036
2014-01-28 02:17:46 +00:00
Chris Lattner
ddc5ca81d6 Fix <rdar://problem/15858869> *all* objc accessors disabled in init methods, not just for self
This patch: 
 - Changes sema to set the "IsDirectPropertyAccess" on MemberRefExprs
   in inits/destructors that should be done directly because they are
   on the local object.
 - Removes the "SGF.AlwaysDirectStoredPropertyAccess" bool in SILGen,
   which was the source of the problem above and was otherwise problematic.

This will get a bit simpler when -enable-new-objc-properties rolls out. 


Swift SVN r12967
2014-01-26 07:23:42 +00:00
Doug Gregor
d52cec4b20 Eliminate a pile of literal identifiers for self, init, destructor, etc.
... because I can't stomach adding another one of these.


Swift SVN r12687
2014-01-22 01:09:49 +00:00
Chris Lattner
f5b85341a1 Expand out the "isComputed" property in AbstractStorageDecl to be an enum
with two kinds, and some more specific predicates that clients can use.

The notion of 'computed or not' isn't specific enough for how properties
are accessed.  We already have problems with ObjC properties that are 
stored but usually accessed through getters and setters, and a bool here
isn't helping matters.

NFC.



Swift SVN r12593
2014-01-20 18:16:30 +00:00
Chris Lattner
a0f0c28868 Two related but (theoretically at least) seperable changes:
1. Implement parser and sema support for our subscript syntax proposal in
   protocols.  Now you have to use subscript(..) { get } or  {get set} to 
   indicate what you want.  I suspect that the syntax will evolve, but at
   least we can express what we need now.
2. Change the representation of SubscriptDecls in protocols to make 
   (empty) funcdecls for the getter and setter.  This guarantees that 
   every subscript has at least a getter.



Swift SVN r12555
2014-01-19 01:35:13 +00:00
Chris Lattner
0292a5f34e merge objc thunk generation for subscripts into the thunk
generation logic for vardecls.  They are the same, subscripts
are always just computed.


Swift SVN r12542
2014-01-18 20:28:49 +00:00
Chris Lattner
b4735381d0 Plumb the DeclContext of the use site down to the "doesVarDeclMemberProduceLValue"
function.  Pretty soon, whether something is an lvalue or not will depend on who is
asking.


Swift SVN r12507
2014-01-17 22:14:02 +00:00
Jordan Rose
11008f0ed1 Split diagnostics out into separate files.
Thanks to the way we've set up our diagnostics engine, there's not actually
a reason for /everything/ to get rebuilt when /one/ diagnostic changes.
I've split them up into five categories for now: Parse, Sema, SIL, IRGen,
and Frontend, plus a set of "Common" diagnostics that are used in multiple
areas of the compiler. We can massage this later.

No functionality change, but should speed up compile times!

Swift SVN r12438
2014-01-17 00:15:12 +00:00
John McCall
3c0d18dc1f Pass a ResilienceExpansion when mangling a SILDeclRef.
Swift SVN r12366
2014-01-16 00:36:39 +00:00
John McCall
a1b469ed2f ExplosionKind -> ResilienceExpansion. NFC.
Swift SVN r12364
2014-01-16 00:25:29 +00:00
Doug Gregor
ea209da4be When needed, emit a Objective-C .cxx_construct method to initialize stored properties.
When a class that will be allocated by the Objective-C runtime also
requires all of its stored properties have initial values, move that
complete initialization of the object into -.cxx_construct, which is
invoked by the runtime after +alloc.

Definite initialization doesn't like the resulting initializers (which
don't initialize any of their ivars) at all, so no end-to-end testing yet.

Swift SVN r12229
2014-01-13 16:31:23 +00:00
Doug Gregor
fc7dfb2fae Start emitting .cxx_construct methods for Objective-C-derived classes.
When we're using Objective-C's memory allocation, emit .cxx_construct
methods whenever we have instance variables with in-class
initializers. Presently, these methods are just empty stubs.

Swift SVN r12211
2014-01-12 04:31:52 +00:00
Doug Gregor
804a23e32f Only emit the Objective-C -dealloc method if it does something.
Instance variable destruction is handled separately by -.cxx_destruct,
and the message send to the superclass's -dealloc is handled by the
Objective-C runtime, so we only need to emit a -dealloc if there is
any user code in it.

Swift SVN r12210
2014-01-12 02:07:01 +00:00
Doug Gregor
19f0aaf44c Only emit the Objective-C -.cxx_destruct when it has something to do.
This saves some deallocation time in the Objective-C runtime for
simple Swift classes that inherit from Objective-C classes.

Swift SVN r12208
2014-01-12 01:32:09 +00:00
Doug Gregor
7950fc2df6 Only emit the Objective-C entry point for the ivar destroyer (-.cxx_destruct).
The Swift entry point will never be referenced by anything, so don't
bother generating it.

Swift SVN r12207
2014-01-12 00:50:12 +00:00
Doug Gregor
3524a79fa0 Emit .cxx_destruct for destruction of ivars in Objective-C-derived classes.
The Objective-C runtime executes the .cxx_destruct method after the
last -dealloc has executed when destroying an object, allowing the
instance variables to remain live even after the subclass's
destructor/-dealloc has executed, which is important for memory
safety. This fixes the majority of <rdar://problem/15136592>.

Note that IRGenModule::getAddrOfIVarDestroyer() contains  an egregious
hack to find the ivar destructor SIL function via a linear
search. We need a better way to find SIL functions that we know exist,
because LinkEntity does not suffice.

Swift SVN r12206
2014-01-12 00:17:42 +00:00
Doug Gregor
34113ffee4 Emit both Swift and Objective-C entry points for -dealloc.
The Swift entry point is required for the Swift metadata, while the
Objective-C entry point goes into the Objective-C metadata. As part of
this, stop emitting the destroying destructor for classes that use
Objective-C allocation: it won't work anyway.

Swift SVN r12199
2014-01-11 04:37:39 +00:00
Doug Gregor
f05263d4fe Objective-C's -dealloc is a deallocating destructor, not a destroying destructor.
Because Objective-C doesn't have the notion of a destroying
destructor, this is a matter of cleanliness rather than
correctness. Still, it's better not to lie.


Swift SVN r12160
2014-01-10 23:08:42 +00:00
Doug Gregor
1b746bc3b5 Move the creation of deallocating destructors from IRGen to SILGen.
This is the first (and only) use of the dealloc_ref instruction.

Swift SVN r12145
2014-01-10 22:32:55 +00:00
Doug Gregor
5f1b8618f4 Make the SILDeclRef for a destroying destructor store a DestructorDecl.
SILDeclRef was previously storing the ClassDecl for this case, because
semantic analysis didn't guarantee that a DestructorDecl was always
present. It is now, and this representation makes more sense.

Swift SVN r12122
2014-01-10 17:33:57 +00:00
Doug Gregor
03edef185a Emit a -dealloc method for Swift classes whose root class is defined in Objective-C.
Teach SILGen to emit a -dealloc method that runs user code, destroys
instance variables, and then calls up to the superclass dealloc. Teach
IRGen to deal with Objective-C destructor methods and add -dealloc to
the instance method table.

There are a few things still wrong here: we're emitting both a Swift
destructor and -dealloc, even though only one of them should ever
actually be used. Additionally, instance variables shouldn't be
destroyed in -dealloc, but in .cxx_destruct, so they persist until the
last of the -dealloc methods is invoked.

Swift SVN r12115
2014-01-10 05:07:33 +00:00
Doug Gregor
8d2142dcd0 Tweak the "uses Objective-C allocation" predicate.
We use Objective-C allocation for classes whose root was defined in
Objective-C. Any Swift class whose root is defined in Swift will use
Swift's allocation routines instead.

Plus some minor cleanup in advance of implementing -dealloc.


Swift SVN r12104
2014-01-09 23:09:59 +00:00
Doug Gregor
fbb5681110 SILGen doesn't need to cope with missing DestructorDecls.
Swift SVN r12095
2014-01-09 18:15:12 +00:00
John McCall
5da6defa1f Clean up the linkage model and the computation of linkage.
In general, this forces SILGen and IRGen code that's grabbing
a declaration to state whether it's doing so to define it.

Change SIL serialization to serialize the linkage of functions
and global variables, which means also serializing declarations.

Change the deserializer to use this stored linkage, even when
only deserializing a declaration, and to call a callback to
inform the client that it has deserialized a new entity.

Take advantage of that callback in the linking pass to alter
the deserialized linkage as appropriate for the fact that we
imported the declaration.  This computation should really take
advantage of the relationship between modules, but currently
it does not.

Swift SVN r12090
2014-01-09 08:58:07 +00:00
Joe Groff
b2f0b90ba2 SIL: Switch to SILFunctionType interface types in easy-to-reach places.
In nongeneric contexts, or contexts where we only care about the indirectness of parameters or have already substituted the generic parameters for a function, the interface types are interchangeable, so just switch over.

Swift SVN r12044
2014-01-08 04:48:29 +00:00
John McCall
e507341c1b SILModule lookup: now with that magic O(1) flavor.
Swift SVN r11978
2014-01-07 01:21:10 +00:00
John McCall
bb63d2312b Hide the constructors of SILFunction/SILGlobalVariable
behind factory methods.

Swift SVN r11967
2014-01-07 00:22:15 +00:00
John McCall
cca5fb3bc0 Remove name mutators for SILFunction and SILGlobalVariable.
Swift SVN r11963
2014-01-06 23:32:52 +00:00
John McCall
17a8acfe43 Remove the vestiges of the SILGen mangler.
Swift SVN r11895
2014-01-04 09:11:15 +00:00
Chris Lattner
fdc3e70d6d move SILGenFunction::Writeback out of line and rename it to LValueWriteback
in preparation for more work on it.  NFC.


Swift SVN r11876
2014-01-04 00:17:09 +00:00