Commit Graph

99 Commits

Author SHA1 Message Date
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
409655e037 SIL: Split tuple/struct field accessor insns.
Split ExtractInst and ElementAddrInst into separate Tuple and Struct versions, and have the Struct versions reference struct member VarDecls directly instead of integer indices.

Swift SVN r5215
2013-05-17 23:34:11 +00:00
Chris Lattner
9a9acb11ba SILType::isLoadable is going to soon require a SILModule argument.
Add it, and propagate this through other APIs that call it (like
isAddressOnly and isTrivial).  No functionality change.



Swift SVN r5213
2013-05-17 23:13:38 +00:00
Doug Gregor
10ecccceea Make Type's bool conversion explicit.
I just tripped over this.


Swift SVN r5209
2013-05-17 19:12:59 +00:00
Joe Groff
19b9ad913e SILGen: Use 'isObjC' bit on SILConstant.
When we intend an ObjC dispatch, indicate so in the SILConstant. This lets us distinguish Swift from ObjC dispatch for Swift classes with ObjC superclasses.

Swift SVN r5207
2013-05-17 18:12:29 +00:00
Chris Lattner
e40f09aa25 remove a dead method, and move const to the "right" place per prevalent coding standard.
Swift SVN r5199
2013-05-17 05:08:56 +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
d5eb080ca5 Revert r5035 force_inline implementation.
We're going to do this in the SIL optimizer instead.

Swift SVN r5171
2013-05-15 18:36:10 +00:00
Joe Groff
d5784307d2 SILGen: Emit objc_msgSend-able thunks in SIL.
Emit thunks for [objc] class methods and properties as SILFunctions, using SILGen's OwnershipConventions. This will help kill some redundant ownership code in IRGen, and will allow msgSend thunks to handle string and block bridging. IRGen doesn't actually codegen the thunks yet; that will require teaching IRGenSILFunction how to be AbstractCC-aware, so for now, we just reemit the thunks using the old IRGen code.

Swift SVN r5168
2013-05-14 01:22:12 +00:00
Joe Groff
b818405034 Replace direct use of [[clang::fallthrough]] with a macro.
Add a SWIFT_FALLTHROUGH macro that expands to [[clang::fallthrough]] for Clang and nothing for other compilers. No functionality change.

Swift SVN r5043
2013-05-05 18:54:03 +00:00
Joe Groff
e40d2f6769 SILGen: Implement basic force-inlining.
Set things up in SILGenFunction so that there can be nested return scopes, and emit force_inline functions inline in SILGenApply.

Swift SVN r5037
2013-05-04 00:46:51 +00:00
Joe Groff
16a640e939 runtime: Guard against recursive destruction in swift_release.
Retain heap objects before invoking their destructor so that retains and releases of the object during its destructor don't trigger recursive destruction. In destructor SILGen, eliminate the goofy double-retain guard that was getting emitted into every destroying destructor. If we count on release fixing the retain count and enforce fixed-lifetime capture of 'this' within a destructor body, we don't need to mess with 'this' at all in a destructor prolog or epilog—it's just a +0 argument.

Swift SVN r5022
2013-05-02 00:52:54 +00:00
Joe Groff
7b305c785f SILGen: Fix crash when taking an address-only tuple argument.
Fix the argument visitor to use RValue's tuple restructuring logic instead of naively trying to cast a TupleInst over destructured arguments, which doesn't work for address-only tuples.

Swift SVN r4967
2013-04-28 16:37:18 +00:00
Joe Groff
b5c42d9876 SILGen: Consume address-only arguments in-place.
If an address-only argument doesn't need a box, we can just bind the address we were passed to the argument variable directly. We only need to destroy_addr the value when it goes out of scope.

Swift SVN r4929
2013-04-27 03:45:26 +00:00
Joe Groff
bcb49ce450 SIL: Key functions directly without SILConstant.
Replace 'constant_ref' with 'function_ref', which references a SILFunction directly, and 'global_addr', which references a global variable VarDecl. Get rid of the SILConstant-to-SILFunction mapping in SILModule and replace it with an ilist of SILFunctions. Allow SILFunctions to be 'external' by not having any blocks in their body. 

For now, SILFunctions still carry around their SILConstant "name", because name mangling and IRGen still rely on access to the original decl in order to recover IRGen information, which unfortunately leaves IRGen's CodeRefs in a gross, awkward intermediate state. Lifting mangling, AbstractCC, and other linkage attributes to SIL should clear up this up.

Swift SVN r4865
2013-04-23 23:29:04 +00:00
Joe Groff
11109a9376 SILGen: Implement switch statements.
This should bring SILGen up to feature parity with the old backend. This implementation also now supports fallthrough.

Swift SVN r4858
2013-04-22 01:10:06 +00:00
Joe Groff
2aa41b72ed SILGen: Emit fixed-lifetime local vars to stack.
If capture analysis deems a local variable fixed-lifetime, we don't need to put it in a box and can instead locally stack-allocate and destroy it.

Swift SVN r4756
2013-04-16 22:06:43 +00:00
Joe Groff
ded5883eb4 SILGen: Fix infinite destructor loop.
Putting 'this' in a box causes 'this' to be released with the box at the end of the destructor and infinite-loop. Double-retain it to work around this. Gross.

Swift SVN r4752
2013-04-16 02:45:45 +00:00
Joe Groff
2dea0de6f0 SILGen: Box 'this' in constructors and destructors
This is unfortunate (and wrong--this really shouldn't be capturable out of a ctor or dtor), but is needed for now in order for auto_closures over 'this' to work with SILGen's current naive handling of local variables and captures.

Swift SVN r4735
2013-04-14 21:41:04 +00:00
Joe Groff
88d5192a69 SILGen: Don't crash if FuncDecls lack bodies.
FuncDecls for builtins don't have bodies. Deal with this when determining function natural uncurry levels and captures for SILGen.

Swift SVN r4734
2013-04-14 19:45:02 +00:00
Joe Groff
6e8ec92b4a SILGen: Emit curry thunks for standalone functions
For non-generic, non-property, non-instance-method curried functions, emit SIL thunks for all of the intermediate curry levels. The generic, property, and instance method cases need some additional SIL and irgen work to support, but aren't well supported by the current backend, so I'll leave them to be dealt with later. This causes the SliceUInt8 test to break down in IRGen; I'll fix that next.

Swift SVN r4715
2013-04-12 20:47:14 +00:00
Joe Groff
65933e7eac SILGen: Add globals to module when we see VarDecls
Rather than when we initialize them while visiting the PatternBindingDecl. That's dumb.

Swift SVN r4706
2013-04-12 03:12:47 +00:00
Joe Groff
7a0d879307 SILGen: Handle tuple explosions systematically.
Introduce an 'RValue' object in SILGen that behaves like a simplified version of IRGen's 'Explosion' object, holding a destructured tuple in a naturally destructured state. This cleans up a bunch of ad-hoc scattered code that destructured tuples in various places. Update SILGenFunction so that the expression visitors all pass around RValues, and update CallEmission to handle argument clauses as RValues instead of a pre-destructured string of arguments. Implement "emit into" optimization of TupleExpr and ScalarToTupleExpr, now that that's easy to do.

Swift SVN r4667
2013-04-10 23:00:18 +00:00
Joe Groff
217eb22756 SILGen: Visit extension decls.
Swift SVN r4611
2013-04-05 18:03:43 +00:00
Joe Groff
aeeda4ee12 Parser: Parse operator decls.
At the top level, if 'operator' is followed by 'infix', 'prefix', or 'postfix', consider it a contextual keyword, and parse an operator decl following it that looks like:

  operator {infix|postfix|prefix} <+> {
    attributes…
  }

Prefix and postfix operator decls currently admit no attributes. Infix operators have 'associativity {left|right|none}' and 'precedence <int>' attributes.

This patch implements parsing for operator declarations but does not yet attach the declared attributes to func decls for the operators.

Swift SVN r4596
2013-04-03 23:30:50 +00:00
Chris Lattner
965242a833 rename SILBBArgument.h -> SILArgument.h to match the class name.
I'm done with renaming for now, boy do my fingers hurt.


Swift SVN r4595
2013-04-03 21:08:38 +00:00
Chris Lattner
a71bc3a78e rename Value -> SILValue, BasicBlock -> SILBasicBlock, BBArgument -> SILArgument.
Swift SVN r4594
2013-04-03 21:05:42 +00:00
Chris Lattner
1beebda868 move Instruction/BasicBlock/BBArgument files to have SIL prefixes.
Swift SVN r4591
2013-04-03 18:43:54 +00:00
Chris Lattner
65cd2b2d25 rename swift::Function to swift::SILFunction to be more explicit.
Swift SVN r4590
2013-04-03 18:36:15 +00:00
Joe Groff
83d4b6dda4 SIL: Separate TypeLowering from SILGen.
Other SIL producers (like the parser) will probably need to be able to lower Swift Types to SILTypes, so make TypeLowering.h a public SIL header instead of an implementation detail of SILGen.

Swift SVN r4577
2013-04-02 21:50:28 +00:00
Joe Groff
ef6d33039e Mark fallthroughs with [[clang::fallthrough]].
Use [[clang::fallthrough]] instead of informal /*fallthrough*/ comments.

Swift SVN r4574
2013-04-02 20:51:38 +00:00
Joe Groff
bc7afbae3a SILGen: Visit ClangImporter external definitions.
Emit SIL for definitions synthesized by the Clang importer.

Swift SVN r4552
2013-03-30 17:41:33 +00:00
Joe Groff
9a1899c6e0 SILGen: Clean up 'Initialization' implementation.
Use unique_ptr to manage the ownership of sub-initializations, add the ability for contiguous tuple initializations to break up into non-contiguous tuple initializations so that tuple expressions can be uniformly "emit-into"-ed, and formalize the different broad categories of initialization kind.

Swift SVN r4491
2013-03-27 02:58:54 +00:00
Joe Groff
ca673945b1 SILGen: Tidy up ManagedValue.
Instead of trying to be cute and lazily copy address-only values, always pass around ManagedValues at +1 (unless they represent lvalues). This cleans up some special-case clutter for address-only values.

Swift SVN r4488
2013-03-25 23:49:55 +00:00
Joe Groff
08d06e850d IRGen: Emit top-level globals from SIL.
Set up IRGen to emit SIL code that uses top-level-code global variables. Add -sil-i to a bunch of Interpreter tests that use global variables.

Swift SVN r4480
2013-03-22 23:34:38 +00:00
Joe Groff
7934842505 SILGen: Handle globals in top-level code.
In top-level code, global variables are notionally local variables of the "main" function, but we give them global storage as an implementation detail. Add the ability to represent physical global variables to SILConstant, and emit top-level-code global variable initializers and references in terms of the physical address.

Swift SVN r4479
2013-03-22 21:58:33 +00:00
Joe Groff
ed6f218836 SIL: "Thicken" function refs when necessary.
Swift doesn't yet type-check function thinness, so variables, arguments, and return values are always thick. When we store, pass as argument, or return a function value that SIL tracks as thin, emit a new 'thin_to_thick_function' instruction to represent converting the type to the thick type and adding a null context pointer.

Swift SVN r4470
2013-03-21 23:44:01 +00:00
Joe Groff
b2c1a83433 SILGen: Uncurry function applications.
Reference and call uncurried function applications when appropriate to the call site, following the same logic implemented in CallEmission/CalleeSource in IRGen. Add ClassMethodInst and SuperMethodInst instructions to represent method and super dispatch. Change how closures and ClosureInst are represented in SIL so that closures are functions with an extra implicit uncurry level and so that ClosureInst applies the outer uncurries of an uncurried function type to give a curried type as a result. This breaks...pretty much everything else SIL-dependent; I'll clean it up next.

Swift SVN r4368
2013-03-14 01:27:54 +00:00
Joe Groff
340cc73e1e SIL: Track uncurry levels of SILConstants.
Pack the uncurry level onto SILConstant, and modify SILConstant constructors to determine the natural uncurry level of their referenced entity by default. While we're here, improve how SILConstant represents different kinds of constants by using a real enum for the kind. Type closure entry points by giving them an extra curry level for their context. The implementation of ApplyInst and ClosureInst hasn't been updated yet, so tests that lower closures to SIL are temporarily broken.

Swift SVN r4354
2013-03-11 23:17:35 +00:00
Joe Groff
292f44af20 SILGen: Make address-only calling conv caller-copy
This is more in line with how IRGen currently behaves and with how loadable values are passed, and will make optimization of address-only functions easier.

Swift SVN r4343
2013-03-08 19:32:58 +00:00
Joe Groff
8966bd22b4 SILGen: Initialization::zeroInitialize -> defaultInitialize
To match the renaming of 'zero_addr'.

Swift SVN r4342
2013-03-08 19:32:55 +00:00
Joe Groff
197b9e90e9 SILGen: Emit param patterns in reverse order.
Conform to IRGen's curried calling convention by emitting param patterns in reverse order, with the indirect return argument (if any) coming first.

Swift SVN r3777
2013-01-16 20:03:25 +00:00
Joe Groff
b4c1ea890b SILGen: Recursively destructure tuple arguments.
Fully and consistently destructure tuples when in a function argument context, and require that ApplyInst always take destructured arguments corresponding to the lowered argument types as its inputs. This eliminates a ton of finicky special-case code all over the place and also has the nice fringe benefit of avoiding a bunch of useless TupleInsts that were being emitted before. Currently this breaks variadic tuple fields and argument writeback. I'll fix variadic tuple fields soon. The argument writeback sucked anyway and I'll do it right later.

Swift SVN r3730
2013-01-10 03:45:45 +00:00
Joe Groff
4dffe605f7 SILGen: TypeLoweringInfo.{h,cpp} -> TypeLowering
The module itself performs type lowering, it doesn't just house TypeLoweringInfo.

Swift SVN r3713
2013-01-09 00:54:54 +00:00
Joe Groff
cb03dbd3be SIL: Associate SILTypeInfo with the SILModule.
For some types, there is lowering info that is useful to IRGen, such as the SIL-level calling convention for functions or the element layout of aggregates, that can't fit in a SILType pointer but still should be associated with the module. Add a SILTypeInfo hierarchy, add a mapping of SILTypes to infos to SILModule, and rename the SILGen-specific TypeInfo to TypeLoweringInfo. Move the derived layout information for compound types from TypeLoweringInfo to SILTypeInfo so that IRGen will be able to use it.

Swift SVN r3712
2013-01-09 00:02:38 +00:00
Joe Groff
0bf47aaf74 SILGen: Count base class fields for field offsets.
Derived class fields were being given offsets from zero even if the base class has fragile fields.

Swift SVN r3708
2013-01-08 02:09:08 +00:00
Joe Groff
08399cf882 SILGen: Emit allocating/initializing class ctors.
Add a new SILConstant kind to refer to the initializer of a ConstructorDecl. Emit class constructors as separate allocating and initializing functions named SILConstant(CD) and SILConstant(CD, Initializer) so that derived classes will be able to invoke their superclass constructor.

Swift SVN r3686
2013-01-04 23:13:38 +00:00
Joe Groff
718126bd2e SILGen: Emit implicit destructors.
Add a new "kind" to SILConstant so that SIL can reference destructors without decls. Generate a destructor for classes even if they don't have an explicit destructor. If a class has a base class, call the base class destructor instead of dealloc_ref-ing the current instance.

Swift SVN r3665
2013-01-03 23:57:48 +00:00
Joe Groff
984f1dad91 SILGen: Generate explicit constructors.
Generate ConstructorDecl bodies, sandwiched between code to allocate an instance before running the body and code to return the initialized value afterward. Still need to:
- handle the implicit constructor for structs
- divide the class constructor into allocating and initializing entry points
- chain a call to the base class initializer entry point from the derived class initializer

Swift SVN r3662
2013-01-03 20:12:35 +00:00
Joe Groff
7b2c1a31e5 SILGen: A first pass at generating destructors.
Generate explicit destructors by emitting their bodies then emitting release sequences for the class's members. Eventually we'll need to also emit implicit destructors for classes without explicit destructors and to chain a call to the base class destructor, which will require adding a new linkable entity flag onto SILConstant for destructors, similar to getter/setters.

Swift SVN r3655
2013-01-03 04:24:43 +00:00