Commit Graph

42 Commits

Author SHA1 Message Date
John McCall
e249fd680e Destructure result types in SIL function types.
Similarly to how we've always handled parameter types, we
now recursively expand tuples in result types and separately
determine a result convention for each result.

The most important code-generation change here is that
indirect results are now returned separately from each
other and from any direct results.  It is generally far
better, when receiving an indirect result, to receive it
as an independent result; the caller is much more likely
to be able to directly receive the result in the address
they want to initialize, rather than having to receive it
in temporary memory and then copy parts of it into the
target.

The most important conceptual change here that clients and
producers of SIL must be aware of is the new distinction
between a SILFunctionType's *parameters* and its *argument
list*.  The former is just the formal parameters, derived
purely from the parameter types of the original function;
indirect results are no longer in this list.  The latter
includes the indirect result arguments; as always, all
the indirect results strictly precede the parameters.
Apply instructions and entry block arguments follow the
argument list, not the parameter list.

A relatively minor change is that there can now be multiple
direct results, each with its own result convention.
This is a minor change because I've chosen to leave
return instructions as taking a single operand and
apply instructions as producing a single result; when
the type describes multiple results, they are implicitly
bound up in a tuple.  It might make sense to split these
up and allow e.g. return instructions to take a list
of operands; however, it's not clear what to do on the
caller side, and this would be a major change that can
be separated out from this already over-large patch.

Unsurprisingly, the most invasive changes here are in
SILGen; this requires substantial reworking of both call
emission and reabstraction.  It also proved important
to switch several SILGen operations over to work with
RValue instead of ManagedValue, since otherwise they
would be forced to spuriously "implode" buffers.
2016-02-18 01:26:28 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
John McCall
73258f2b21 Generate method/property @encodings from the foreign
SILFunctionType of the method instead of its formal type.

Gives more accurate information to the @encoding, makes
foreign error conventions work implicitly, and allows
IRGen's Swift-to-Clang to avoid duplicating arbitrary
amounts of the bridging logic from SILGen.

Some finagling was required in order to avoid calling
getConstantFunctionType from within other kinds of
lowering, which might have re-entered a generic context.

Also required fixing a bug with the type lowering of
optional DynamicSelfTypes where we would end up with
a substituted type in the lowered type.

Also, for some reason, our @encoding for -dealloc
methods was pretending that there was a formal parameter.
There didn't seem to be any justification for this,
and it's not like Clang does that.  Fixed.

This commit reapplies r29266 with a conservative build fix
that disables ObjC property descriptors for @objc properties
that lack a getter.  That should only be possible in SIL
files, because @objc should force accessors to be synthesized.
Arguably, Sema shouldn't be marking things implicitly @objc
in SIL files, but I'll leave that decision open for now.

Swift SVN r29272
2015-06-03 04:59:54 +00:00
Dmitri Hrybenko
8d8a462ee1 Revert "Generate method/property @encodings from the foreign"
This reverts commit r29266.  It broke buildbots.

Swift SVN r29271
2015-06-03 03:49:32 +00:00
John McCall
ed68d261e7 Generate method/property @encodings from the foreign
SILFunctionType of the method instead of its formal type.

Gives more accurate information to the @encoding, makes
foreign error conventions work implicitly, and allows
IRGen's Swift-to-Clang to avoid duplicating arbitrary
amounts of the bridging logic from SILGen.

Some finagling was required in order to avoid calling
getConstantFunctionType from within other kinds of
lowering, which might have re-entered a generic context.

Also required fixing a bug with the type lowering of
optional DynamicSelfTypes where we would end up with
a substituted type in the lowered type.

Also, for some reason, our @encoding for -dealloc
methods was pretending that there was a formal parameter.
There didn't seem to be any justification for this,
and it's not like Clang does that.  Fixed.

Swift SVN r29266
2015-06-03 02:33:38 +00:00
Joe Groff
b5b860ad39 IRGen: Properly create ObjC protocols using the runtime in JIT mode.
Just injecting a new protocol descriptor into an already-running ObjC runtime isn't a good idea, since the runtime might have already canonized the protocol somewhere else, and it won't recognize that classes conform to protocols it doesn't know about.

Swift SVN r23313
2014-11-14 01:01:02 +00:00
Jordan Rose
3fcdfd40e9 Remove the "swift/Basic/Optional.h" header.
llvm::Optional lives in "llvm/ADT/Optional.h". Like Clang, we can get
Optional in the 'swift' namespace by including "swift/Basic/LLVM.h".

We're now fully switched over to llvm::Optional!

Swift SVN r22477
2014-10-02 18:51:45 +00:00
Jordan Rose
9891c7f2f2 Replace swift::Optional with llvm::Optional.
There are some compatibility aliases here that will go away after the switch.

Swift SVN r22474
2014-10-02 18:51:38 +00:00
John McCall
0ddc7ee5b6 Resilience expansion is not an IR-generation concept.
If a type has to be passed or returned resiliently, it
will necessarily be passed indirectly, which is already
represented in SILFunctionType.  There is no need to
represent this as a separate channel of information.

NFC. Also fixes a problem where the signature cache
for ExtraData::Block was writing past the end of an
array (but into the storage for an adjacent array
which was fortunately never used).

ExtraData should also disappear as a concept, but we're
still relying on that for existential protocol witnesses.

Swift SVN r21548
2014-08-28 23:07:50 +00:00
Joe Groff
318aba81ef IRGen: Implement block header generation.
Implement the init_block_storage_header SIL instruction by teaching IRGen how to produce block descriptors, including copy/dispose helpers and block signatures.

Swift SVN r16478
2014-04-17 22:40:23 +00:00
Joe Groff
8adaab0233 Fold ExtInfo::isThin and ::isBlock into a "Representation" enum.
These bits are orthogonal to each other, so combine them into one, and diagnose attempts to produce a type that's both. Spot-fix a bunch of places this revealed by inspection that we would have crashed in SILGen or IRGen if blocks were be handled.

Swift SVN r16088
2014-04-09 00:37:26 +00:00
Fariborz Jahanian
b15d326bd8 Adds support for extended method signature for
methods declared in protocols. // rdar://16308986


Swift SVN r15239
2014-03-19 17:19:12 +00:00
John McCall
a1b469ed2f ExplosionKind -> ResilienceExpansion. NFC.
Swift SVN r12364
2014-01-16 00:25:29 +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
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
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
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
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
56edc42dc8 IRGen for Objective-C subscript thunks.
Swift SVN r8617
2013-09-25 01:14:54 +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
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
Joe Groff
398cbba5be Rename SILConstant to SILDeclRef.
"SILConstant" doesn't really describe its role in SIL anymore, which is to provide a reference to a Swift declaration in a SIL instruction, such as a method or nominal type field.

Swift SVN r6559
2013-07-24 21:21:31 +00:00
Joe Groff
5e2779b51e SIL: Uncurry function types within the Swift type system.
Remove uncurry level as a property of SILType/SILFunctionTypeInfo. During SIL type lowering, map a (Type, UncurryLevel) pair to a Swift CanType with the uncurried arguments as a Swift tuple. For example, T -> (U, V) -> W at uncurry level 1 becomes ((U, V), T) -> W--in reverse order to match the low-level calling convention. Update SILGen and IRGen all over the place for this representation change.

SILFunctionTypeInfo is still used in the SILType representation, but it's no longer load-bearing. Everything remaining in it can be derived from a Swift type.

This is an ABI break. Be sure to rebuild clean!

Swift SVN r5296
2013-05-24 01:51:07 +00:00
Joe Groff
8993ed707e Split 'C' and 'ObjCMethod' calling conventions.
This cleans up some wishy-washy control flow that relied on the uncurryLevel of a type to distinguish ObjC methods from freestanding C functions. While we're here, clean up all the places we use ad-hoc comparison logic on the AbstractCC enum to use switches that properly cover the enum.

Swift SVN r5251
2013-05-21 15:19:37 +00:00
Joe Groff
8303addde0 IRGen: Get ObjC thunks from SIL.
Use the SIL-generated ObjC thunk symbols instead of generating them in IRGen. Kill all the now-dead IRGen OwnershipConventions stuff. Teach IRGenSILFunction how to emit a C-calling-convention function, and getFunctionType how to map a C-calling-convention function type. Fix a bug in SILGen where ObjC thunks for methods and properties from extensions weren't getting emitted.

Swift SVN r5180
2013-05-16 19:03:37 +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
Joe Groff
0566088bf2 Move name mangling into SIL.
Sever the last load-bearing link between SILFunction and SILConstant by naming SILFunctions with their mangled symbol names. Move the core of the mangler up to SIL, and teach SILGen how to use it to mangle a SILConstant.

Swift SVN r4964
2013-04-28 03:32:41 +00:00
Joe Groff
e5068920bb SILGen: Handle ObjC ownership conventions of calls
Port IRGen's calculation of consumed arguments and return value semantics to SILGen, and use it to handle the ownership semantics of calls. Refactor the handling of properties and other clients of emitApply so they can properly hand ownership semantics down to it.

This should let all the moribund cleanup management code in IRGen die. Unfortunately Scope appears to be tied into scoped calculated metadata caching so it's not quite ready to die.

Swift SVN r4834
2013-04-20 23:13:42 +00:00
Chris Lattner
abee79b26e remove some Expr stuff.
Swift SVN r4810
2013-04-18 22:32:37 +00:00
Chris Lattner
6a6601ec04 remove the Expr version of prepareObjCMethodCall and the code that is keeps alive.
Swift SVN r4807
2013-04-18 18:05:45 +00:00
Joe Groff
c724d1f6a1 IRGen: Emit SIL class metatypes as Swift or ObjC.
Look at the uses of a SIL MetatypeInst to determine whether it is being used as a Swift metatype and/or ObjC class and emit the needed values. This avoids a costly trip wrapping and unwrapping ObjC Classes in a Swift metatype when they're just used to invoke class methods.

Swift SVN r4562
2013-04-01 22:10:12 +00:00
Joe Groff
0034475514 IRGen: Map SIL metatypes back to ObjC classes.
For ObjC class method calls, map a metatype value back to an objc Class before emitting the ObjC call. This is dumb because we already map the original Class to a Swift metatype when we map the metatype instruction, but it gets ObjC class method calls working. Now that SIL keeps use chains, we could be easily smarter about this.

Swift SVN r4558
2013-03-30 23:40:35 +00:00
Joe Groff
02de4d8007 IRGen: Handle ownership conventions from SIL apply
Introduce cleanups onto arguments to SIL apply instructions, and let CallEmission consume the cleanups corresponding to the values consumed by the called function, so that releases will be emitted as needed to make a foreign call conform to Swift ownership conventions.

Swift SVN r4556
2013-03-30 22:48:16 +00:00
Joe Groff
0e4c0a568d IRGen: Start adding ObjC call support through SIL.
Represent class_method and super_method SIL values using an ObjCMethod variant of LoweredValue that holds the necessary information to emit an objc_msgSend* call when the value is apply-ed. You can't really use ObjC objects from SIL IRGen yet because SILGen doesn't yet visit external definitions from the Clang importer.

Swift SVN r4550
2013-03-30 00:06:41 +00:00
Joe Groff
0132f279a7 IRGen: ObjC super dispatch for super.constructor.
Implement super.constructor for ObjC superclasses by dispatching the superclass init message with objc_msgSendSuper2. Fixes <rdar://problem/13107128>.

Swift SVN r4288
2013-03-05 21:39:42 +00:00
Joe Groff
470ad60d60 IRGen: Emit properties for ivars of ObjC classes.
If a class has ObjC interop, synthesize property accessors for its ivars so that things like IBOutlets and bindings work correctly.

Swift SVN r4240
2013-02-28 20:24:43 +00:00
Joe Groff
827cbfe0b0 IRGen: Dynamic init for repl ObjC extensions.
When running in immediate mode, generate a global initializer when an extension is defined for an ObjC class that uses the class_replaceMethod runtime function to dynamically add the extension methods to the ObjC class.

Swift SVN r4153
2013-02-22 21:08:39 +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
Joe Groff
4792c60d2d IRGen: Implement super method calls.
For Objective-C super calls, build an objc_super struct value containing the receiver and class/metaclass object and pass it to objc_msgSendSuper2. For Swift super calls, emit a direct call to the super implementation.

Swift SVN r4023
2013-02-13 02:41:20 +00:00
John McCall
b15b306314 Emit ObjC metadata and swift-as-ObjC thunks for methods.
Swift SVN r3697
2013-01-05 23:46:24 +00:00
John McCall
7c277001a4 Implement basic objc_msgSend capabilities.
Swift SVN r3104
2012-11-03 00:26:56 +00:00