Commit Graph

270 Commits

Author SHA1 Message Date
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
Chris Lattner
d2a33362dc Fix getRValueType() to not strip off @inout types, only @lvalue types.
- Introduce a new TypeBase::getInOutObjectType() that strips off @inout types
- Switch stuff that is calling getRValueType() to call getInOutObjectType()
  when they are stripping @inout, not @lvalue (this is primarily around
  stuff working with self)
- Update testcases, some diagnostics improve around & handling.

This fixes rdar://15708430 and rdar://15729093.



Swift SVN r11794
2014-01-01 18:56:44 +00:00
Chris Lattner
9a74e8af78 Add some PrettyStackTrace entries to identify the top level generator of a
silfunction when we get a crash.

Merge AutoClosure and ExplicitClosure generation logic.

NFC.


Swift SVN r11769
2013-12-31 05:35:51 +00:00
Chris Lattner
9ae289de46 Drive the semantic wedge harder into lvalues. Now, instead of having one LValueType
with qualifiers on it, we have two distinct types:
 - LValueType(T) aka @lvalue T, which is used for mutable values on the LHS of an
   assignment in the typechecker.
 - InOutType(T) aka @inout T, which is used for @inout arguments, and the implicit
   @inout self argument of mutable methods on value types.  This type is also used
   at the SIL level for address types.

While I detangled a number of cases that were checking for LValueType (without checking
qualifiers) and only meant @inout or @lvalue, there is more to be done here.  Notably,
getRValueType() still strips @inout, which is totally and unbearably wrong.



Swift SVN r11727
2013-12-29 22:23:11 +00:00
Chris Lattner
d3c91387e9 Substantially simplify the API to LValueType now that nonsettable is gone.
Swift SVN r11703
2013-12-28 22:48:44 +00:00
Joe Groff
3e30cbcfef SILGen/IRGen: Don't emit top_level_code for libraries.
If there's no script-mode file in a module, don't produce a top_level_code SILFunction for it, and don't consider emitting an LLVM global_ctor for it. We should never emit static constructors from user code anymore.

Swift SVN r11644
2013-12-26 00:18:29 +00:00
Chris Lattner
b29748a6be remove the ASTContext argument from Type::transform,
(various) FunctionType::get's, ArrayType::get,
ArraySliceType::get, OptionalType::get, and a few
other places.

There is more to be done here, but this is all I plan to do
for now.


Swift SVN r11497
2013-12-20 02:23:21 +00:00
Chris Lattner
1472e4d914 Remove the ASTContext argument from LValueType::get(). It is already
only two loads away from the type argument passed in.



Swift SVN r11496
2013-12-20 01:28:50 +00:00
Joe Groff
44dcc43fa9 ClangImporter: Make NS_OPTIONS imports conform to RawOptionSet.
This makes the bitwise operations &|^~ work with NS_OPTIONS.

Swift SVN r11349
2013-12-16 19:22:27 +00:00
Adrian Prantl
c610ac94ef Add an IsBare attribute to SILFunction for functions that do not have an
AST.

Swift SVN r11236
2013-12-13 04:48:37 +00:00
Doug Gregor
0c4baac6f6 Make the 'self' declaration of a value type constructor be '@inout'.
This removes an oddity in the AST whereby the 'self' declaration
within a value type constructor was not represented as @inout, despite
having @inout semantics in the language.


Swift SVN r11194
2013-12-12 18:31:54 +00:00
Joe Groff
4a25b56846 SILGen: REPL globals are not lazily initialized.
Check for a REPL SourceFileKind along with Main before going the lazy initialization path. Also put response variables in the REPL SourceFile decl context so they are recognized as REPL variables and not lazily initialized. Handle PatternBindingDecls that appear under a script-mode SourceFile decl context but not a TopLevelCodeDecl context.

Swift SVN r11133
2013-12-11 17:54:17 +00:00
Joe Groff
c5dd36cd99 SILGen: Attach debug scopes and location info to lazy init functions.
Swift SVN r11080
2013-12-10 17:41:15 +00:00
Joe Groff
4d1459a6e4 SILGen: Don't blow up trying to emit lazy global initializers for computed properties or declarations without initializers.
Swift SVN r11079
2013-12-10 17:41:14 +00:00
Joe Groff
02a0e996c4 SIL: Kill initialize_var instruction.
Remove the initialize_var instruction now that DI fully diagnoses initialization problems. Change String-to-NSString bridging to explicitly invoke String's default constructor; it was the last remaining user of initialize_var. Remove dead code to emit an implicit default constructor without a body.

Swift SVN r11066
2013-12-10 03:36:59 +00:00