Commit Graph

421 Commits

Author SHA1 Message Date
Joe Groff
dd5dec3dd5 IRGen: Use SILFunctionType interface types in easy places.
ObjC partial_apply thunks are never generic, and neither are cast builtins, so the interface types are always equivalent.

Swift SVN r12625
2014-01-21 00:23:06 +00:00
Joe Groff
0776c4b6b8 SIL: Reorient function type lowering toward interface types.
Lower types for SILDeclRefs from the interface types of their referents, dragging the old type along for the ride so we can still offer the context to clients that haven't been weaned off of it. Make SILFunctionType's interface types and generic signature independent arguments of its  Derive the context types of SILFunctionType from the interface types, instead of the other way around. Do a bunch of annoying inseparable work in the AST and IRGen to accommodate the switchover.

Swift SVN r12536
2014-01-18 19:42:02 +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
Mark Lacey
d9c88e94db Small clean-up in Clang type generation.
Factor our code to get to Clang ASTContext.

Swift SVN r12462
2014-01-17 04:25:10 +00:00
John McCall
32d4ef7001 Remove IR-gen's specialized ASTVisitor.
Swift SVN r12427
2014-01-16 22:32:35 +00:00
John McCall
0692adcbcb More simplifications and dead-code removal.
Swift SVN r12373
2014-01-16 01:12:04 +00:00
John McCall
a1b469ed2f ExplosionKind -> ResilienceExpansion. NFC.
Swift SVN r12364
2014-01-16 00:25:29 +00:00
John McCall
5c4a43d5e4 Good riddance to dead code.
Swift SVN r12360
2014-01-15 23:32:18 +00:00
Fariborz Jahanian
53392e0c62 Fix up the tests which were failing after my patch and
bring back the patch.


Swift SVN r12263
2014-01-14 00:38:42 +00:00
Fariborz Jahanian
6b653dab22 Remove effect of my last patch until I fix the tests
which failed because of it.


Swift SVN r12259
2014-01-13 23:13:03 +00:00
Fariborz Jahanian
8b2ca31095 More initial encoding of ObjectiveC methods;
trying hard to match clang's encoding in this
area.


Swift SVN r12249
2014-01-13 21:34:35 +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
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
Fariborz Jahanian
e395bea737 Start on type encoding of ObjectiveC types into
swift version of ObjectiveC metadata. Currently,
GenClangType is missing all interesting types so,
this patch doesn't do much (and therefor no tests).


Swift SVN r12159
2014-01-10 23:00:17 +00:00
Doug Gregor
183a22b212 Add a deallocating destructor kind to SILDeclRef.
Swift SVN r12141
2014-01-10 22:32:50 +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
Joe Groff
5e5f31d5e3 IRGen: Share TypeInfo among equivalent generic instantiations, take 2.
IRGen type conversion is invariant with respect to archetypes with the same set of constraints, so instead of redundantly generating a TypeInfo object and IR type for Optional<T> for every T everywhere, key TypeInfo objects using an "exemplar type" that we form using a folding set to collapse together archetypes with the same class-ness, superclass constraint, and protocol constraints.

This is a nice memory and IR size optimization, but will be essential for correctness when lowering interface types, because there is no unique context to ground a dependent type, and we need to lower the same generic parameter with the same context requirements to the same type whenever we instantiate it in order for the IR to type-check.

In this revision, we profile the nested archetypes of each recursively, which I neglected to take into account originally in r12112, causing failures when archetypes that differed by associated type constraints were incorrectly collapsed.

Swift SVN r12116
2014-01-10 05:25:45 +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
Joe Groff
97ff9e47a8 Revert "IRGen: Share TypeInfo among equivalent generic instantiations."
This reverts commit r12112. It gives the buildbot indigestion.

Swift SVN r12113
2014-01-10 03:22:53 +00:00
Joe Groff
57cacbfe38 IRGen: Share TypeInfo among equivalent generic instantiations.
IRGen type conversion is invariant with respect to archetypes with the same set of constraints, so instead of redundantly generating a TypeInfo object and IR type for Optional<T> for every T everywhere, key TypeInfo objects using an "exemplar type" that we form using a folding set to collapse together archetypes with the same class-ness, superclass constraint, and protocol constraints.

This is a nice memory and IR size optimization, but will be essential for correctness when lowering interface types, because there is no unique context to ground a dependent type, and we need to lower the same generic parameter with the same context requirements to the same type whenever we instantiate it in order for the IR to type-check.

Swift SVN r12112
2014-01-10 02:02:58 +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
Doug Gregor
1cf3bdbe8c Use objc_msgSendSuper[Stret] for foreign initializer delegation.
Introduce the SIL instruction peer_method, which references a method
in the given class or one of its superclasses (but not a subclass). It
IRGen's to objc_msgSendSuper[Stret] (vs. super_method IRGen'ing to
objc_msgSendSuper[Stret]2 for superclass lookup).

Use peer_method for initializer delegation to a foreign initializer
(i.e., an init-family method written in Objective-C) to close the
safety loophole introduced by initializer delegation in r11965. The
loophole still exists, but can only be triggered from Objective-C.

Teach definite initialization that peer_method really isn't a use of
self.



Swift SVN r11992
2014-01-07 17:33:41 +00:00
Mark Lacey
9b81800432 Choose correct IR types for @objc return values.
This change updates signature generation as well as IR generation for
calls and returns so that the correct ABI types are generated for the
results of @objc functions.

Swift SVN r11527
2013-12-20 23:31:01 +00:00
Joe Groff
63d08c786d SIL: Handle metatype abstraction differences.
Lower metatype types as @thin or @thick based on whether the type is static and whether the abstraction pattern allows for a thin metatype. Add a '@thick' attribute and require SIL metatypes to always be annotated with either '@thin' or '@thick' to distinguish them from unlowered metatypes.

Swift SVN r11525
2013-12-20 23:06:16 +00:00
Joe Groff
017440165e Fix the weird capitalization of MetaTypeType.
Swift SVN r11475
2013-12-19 18:43:08 +00:00
Connor Wakamo
3e81830385 Move "include/swift/IRGen/Options.h" to "include/swift/AST/IRGenOptions.h".
This commit only moves the header file; updating the class so that it is no longer in the irgen namespace will be handled separately.

Swift SVN r11404
2013-12-18 01:17:09 +00:00
John McCall
4bba9b38f8 Make several new interfaces traffic in AbstractionPatterns.
Swift SVN r10621
2013-11-21 02:19:46 +00:00
Joe Groff
3c897bc0c1 IRGen: Use the parameter convention of 'self' when partial_apply'ing ObjC methods
Now that SIL function values carry their full parameter types around at all times (thanks John!), partial_apply can do the right thing for methods with weird conventions. We should really do this for all partial_apply's, but it matters most for ObjC thunks to fix the leak in <rdar://problem/15120887>.

Swift SVN r10583
2013-11-20 05:52:57 +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
554abf2d7a IRGen/Runtime: Expose extra inhabitants of class types.
Start using null-page values as extra inhabitants when laying out single-payload enums that contain class pointers as their payload type. Don't use inhabitants that set the lowest bit, to avoid trampling potential ObjC tagged pointer representations. This means that 'T?' for class type T now has a null pointer representation. Enums with multiple empty cases, as well as nested enums like 'T??', should now have optimal representations for class type T as well.

Note that we don't yet expose extra inhabitants for aggregates that contain heap object references, such as structs with class fields, Swift function types, or class-bounded existentials (even when the existential has no witness tables).

Swift SVN r10061
2013-11-09 00:43:40 +00:00
Joe Groff
d2de66b18b IRGen: Include formal protocol conformances in ObjC class and protocol data.
So that Swift-defined classes actually do the right thing when -conformsToProtocol:-ed by dynamic protocol casts. Partially addresses <rdar://problem/15247517>, but we still need to dynamically emit runtime calls to register the conformance when compiling extensions in the JIT.

Swift SVN r9471
2013-10-17 22:51:04 +00:00
Joe Groff
f164a88615 IRGen: Emit ObjC protocol records for protocols used in casts.
Greg indicated that objc_getProtocol only works if somebody actually reifies a protocol_t record for the protocol with the runtime, so we need to emit our own protocol_t for every Protocol* value we do a checked cast with. Hijack the ClassDataBuilder to also build protocol_t records.

Swift SVN r9420
2013-10-16 21:50:56 +00:00
John McCall
b880e60100 Remove SILFunctionTypeInfo in favor of SILFunctionType.
We still don't actually use this as a type, however.

Swift SVN r9091
2013-10-09 20:55:55 +00:00
Joe Groff
57ea2025cb Adopt '_TPA.*' as a proper mangling for partial_apply thunks.
Jim wants a less ad-hoc naming convention for these thunks so that LLDB's 'trampoline' logic can recognize and step past these thunks in the process of "stepping into" methods involving closures.

Swift SVN r9086
2013-10-09 20:42:24 +00:00
Greg Parker
be12f30395 Move MaxScalarsForDirectResult to SwiftTargetInfo.
Swift SVN r8935
2013-10-04 22:11:46 +00:00
John McCall
affefbe1e0 Remove the AllocSelfExpr from constructors and teach
alloc_ref how to call +allocWithZone: for classes that might
(i.e. probably do) use ObjC allocation.

Swift SVN r8874
2013-10-03 06:36:34 +00:00
Doug Gregor
3a72c7ff88 Use dynamic dispatch for [objc] properties and methods used in lvalues.
There are two major restrictions on this at the moment:
  1) It only applies to [objc] properties/subscripts (where we go
  through Objective-C dispatch). It still does static dispatch for
  non-[objc] properties/subscripts in classes.
  2) The Clang importer doesn't mark imported Objective-C properties
  and subscript operators as [objc], so this is useless in practice.



Swift SVN r8691
2013-09-26 14:13:19 +00:00
Doug Gregor
56edc42dc8 IRGen for Objective-C subscript thunks.
Swift SVN r8617
2013-09-25 01:14:54 +00:00
Doug Gregor
e6f47a6e2d IRGen for dynamic subscripting operations.
Swift SVN r8612
2013-09-24 22:28:36 +00:00
Doug Gregor
903a4d2ea1 Implement SILGen/IRGen support for dynamic lookup that resolves to properties.
Swift SVN r8521
2013-09-20 22:15:03 +00:00
Doug Gregor
f7a2d5eed0 Emit Objective-C thunks for [objc] initializing constructors.
Now that all [objc] constructors have a suitable "init" selector, emit
an Objective-C thunk for the initializing constructor (not the
allocating constructor!) with that selector, and make sure it shows up
in the Objective-C metadata. 

With this, we can write a Swift constructor "constructor()" to
override "-init"; see the change to ListMaker that exercises this.

Joe or John: I'd love a review of these.



Swift SVN r8373
2013-09-18 00:30:54 +00:00
Greg Parker
616b6371e1 Add SwiftTargetInfo for arm64. Add objc_msgSend variants to SwiftTargetInfo.
Swift SVN r8180
2013-09-13 01:43:37 +00:00
Joe Groff
4a4c70ab36 IRGen: Implement partial_apply lowering for objc dynamic method values.
To do this right, we need to emit the objc_msgSend on the 'self' argument inside the forwarding stub, so handle them in a different code path in IRGenSIL::visitPartialApplyInst.

Swift SVN r8112
2013-09-11 21:07:28 +00:00
Doug Gregor
0e3aa19313 Factor the selector-loading logic into its own routine.
When loading a selector in the JIT, we need to call
sel_registerName(). This was manually coded in two places and missed
in a third, so factor it appropriately.


Swift SVN r8082
2013-09-10 22:42:45 +00:00
Joe Groff
29b866bf9c IRGen: Remove stale FIXME.
Swift SVN r7993
2013-09-06 20:33:23 +00:00
Ted Kremenek
8f5b8ccb02 Rename "This" to "Self" and "this" to "self".
This was not likely an error-free change.  Where you see problems
please correct them.  This went through a fairly tedious audit
before committing, but comments might have been changed incorrectly,
not changed at all, etc.

Swift SVN r7631
2013-08-27 21:58:27 +00:00