Commit Graph

9332 Commits

Author SHA1 Message Date
Joe Groff
b53d7a2344 SILGen: Catch up with new Expr nodes.
Add SILGen support for recently-added super.constructor and collection literal expr nodes. Remove the default visitExpr hack and add stubs for the handful of expr nodes remaining to implement.

Swift SVN r4406
2013-03-16 20:28:49 +00:00
Joe Groff
460ba9e61f SILGen: Fix some constructor issues.
Update value type constructor generation to go back to left-to-right uncurried argument emission. Fix the uncurry level of specializations generated during constructor/destructor emission. Update the 'lifetime' test.

Swift SVN r4386
2013-03-15 20:43:58 +00:00
Joe Groff
05dd6b06d6 SIL: Fix uncurry level of local capturing props.
Take into account the context uncurry level when determining the uncurry level of SILConstant for local properties whose getters or setters capture.

Swift SVN r4381
2013-03-15 18:36:19 +00:00
Joe Groff
b07560e43d SILGen: Fix failing test.
Swift SVN r4380
2013-03-15 15:45:47 +00:00
Joe Groff
d1386b0e40 SILGen: Uncurry property accessors.
Swift SVN r4377
2013-03-15 01:06:55 +00:00
Joe Groff
c157420959 SILGen: Admit archetype metatypes.
Oops. This lets test/SIL/expressions.swift be fixed.

Swift SVN r4374
2013-03-14 23:33:39 +00:00
Joe Groff
e1bb6c0ecb SILGen: Implement specialization with uncurrying.
Handle SpecializeExprs in call ASTs by collecting the substitutions and emitting a single SIL SpecializeInst for the original entry point. Update varargs array injection to emit a proper curried call.

Swift SVN r4372
2013-03-14 23:33:35 +00:00
Joe Groff
7c359cc356 SILGen: Uncurry protocol type methods.
Uncurry protocol type methods one level to match how they're represented in the witness table. Update the address_only_types test to reflect function uncurrying.

Swift SVN r4370
2013-03-14 17:43:44 +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
062ad267c4 Value-only switch statements.
Implement switch statements with simple value comparison to get the drudge work of parsing and generating switches in place. Cases are checked using a '=~' operator to compare the subject of the switch to the value in the case. Unlike a C switch, cases each have their own scope and don't fall through. 'break' and 'continue' apply to an outer loop rather to the switch itself. Multiple case values can be specified in a comma-separated list, as in 'case 1, 2, 3, 4:'. Currently no effort is made to check for duplicate cases or to rank cases by match strength; cases are just checked in source order, and the first one wins (aside from 'default', which is branched to if all cases fail).

Swift SVN r4359
2013-03-12 04:43:01 +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
4437c65178 SIL: Add uncurry level to SILType.
We want to port CallEmission to the SIL level to handle uncurrying, but IRGen needs to have the original signature of a function available to it so that it can maintain the correct calling convention for different ABIs independent of SIL. Instead of flattening curried function types in SIL and losing that information, add an uncurryLevel to SILType so it can represent the type of an entry point at a given uncurry level. Unfortunately, this makes SILType outgrow a single word, so the way Value unions SILType and SILTypeList folding sets needs to be tweaked too.

Swift SVN r4345
2013-03-09 00:53:14 +00:00
Joe Groff
56752aeec5 SILGen: Avoid copy if arg is already temporary.
If an address-only argument is already temporary, the callee can consume that temporary without the caller needing to create a new copy.

Swift SVN r4344
2013-03-09 00:53:12 +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
0db00816cd SIL: Replace ZeroAddr/ZeroValue with InitializeVar
Rename 'ZeroAddr' to 'InitializeVar' and remove ZeroValue since only things with memory locations should ever be in a 'default-initialize' state. Add a ModuleInst so we don't need to use ZeroValue as a hack to represent ModuleExpr values.

Swift SVN r4319
2013-03-07 18:38:25 +00:00
Joe Groff
f489f2a6fd Clean up AST representation of 'super'.
Replace the more specific Super*RefExpr nodes with a single SuperRefExpr that resolves members of 'this' relative to its superclass. Add an OtherConstructorDeclRefExpr for referring to a constructor as called from another constructor, and use it to represent resolved 'super.constructor' expressions. (It should also be able to represent delegating constructors for free, if we decide we want to add syntax for that.)

Swift SVN r4286
2013-03-05 02:13:49 +00:00
Joe Groff
2ccfbdcf1a SIL: Add an UpcastExistentialInst.
Converting from a protocol type to a more general protocol type is different at the implementation level from converting a concrete type to a protocol type, since the witness tables and concrete value can be copied directly from the original existential container to the new without adding another indirection. This instruction represents that operation.

Swift SVN r3887
2013-01-28 20:02:52 +00:00
Dave Zarzycki
ba8abb9e41 Apply r3879 to SIL (fix "continue" in do/while)
Swift SVN r3882
2013-01-26 18:43:37 +00:00
Joe Groff
6cfcb412b3 SILGen: Support super.constructor.
Match SuperConstructorRefCallExpr and emit a ConstantRef to the initializing constructor. Remove some now-redundant code in TypeLowering to fake up the type of the initializing entry point.

Swift SVN r3879
2013-01-26 01:30:33 +00:00
Joe Groff
d994ef2fa2 SILGen: Fix bug in downcast memory mgmt.
The downcast ManagedValue wasn't carrying the cleanup from the original value, so even when the downcast value was consumed, the original value cleanup still fired and redundantly released the value.

Swift SVN r3876
2013-01-26 00:49:54 +00:00
Joe Groff
8b1c38bfbd SIL: Add an 'upcast' instruction.
Upcasting isn't quite a no-op like the other implicit conversions because the underlying pointer type still needs to be bitcast. The additional semantic information will be useful for SIL consumers as well.

Swift SVN r3872
2013-01-26 00:49:47 +00:00
Joe Groff
9e971afadd SILGen: Make initializing ctors return this back.
John recommended this because it has a number of benefits:
- It avoids a retain/release cycle, because 'this' can be passed to the initializer at +1 and just received back at +1.
- The allocating constructor can thus tail call the initializing constructor.
- If we end up needing to support rogue ObjC initializers that change self, we're set up to do so.

Swift SVN r3836
2013-01-22 23:36:32 +00:00
Joe Groff
5852448152 IRGen: Generate SIL ctor and property decls.
Remove the filter that only irgenned SIL functions for FuncDecls so that we emit functions for all SIL decls, and disable the old paths for properties, constructors, and destructors when a SIL module is present. Unfortunately this breaks class constructors because SIL and IRGen don't agree on how initializing constructors should work. I need to sync with John to figure out how to fix that.

Swift SVN r3827
2013-01-22 02:45:27 +00:00
Joe Groff
32889de15d SILGen: Make destructor a "destroying" destructor.
IRGen can handle synthesizing the deallocating destructor in terms of the destroying destructor, and SIL will likely never have to refer to a deallocating destructor directly, so generate the body of the destroying destructor only and consider a SILConstant::Destructor to be a destroying destructor in IRGen terms.

Swift SVN r3825
2013-01-22 02:45:23 +00:00
Dave Zarzycki
2f31759280 Remove SemiStmt class
We have no intention of ever supporting actual semicolon statements
(separators, statements no), nor do we ever want to because that would
mean the behavior of the program would potentially change if semicolons
were naively removed.

This patch tracks the trailing semicolon now in the decl/expr/stmt,
which will enable someone to write a good "swift indent" tool in the
future.

Swift SVN r3824
2013-01-22 00:25:26 +00:00
Joe Groff
b7c03623a8 SIL: Properly type closure constants and insns.
I was being lazy by not mangling the context arguments onto the types of closure SIL constants and then having ClosureInst pass the type of its callee through T -> T. Now closure functions get emitted with the right types, ClosureInst properly partially applies the type, and the SIL Verifier properly checks that the argument types all line up correctly.

Swift SVN r3815
2013-01-20 19:50:04 +00:00
Joe Groff
0422897a47 Expose %swift.opaque as a builtin type.
Archetypes and projected existentials have the type %swift.opaque* and not i8*, so I need a corresponding SIL type to be able to model the ProjectExistential operation. We might also end up needing the builtin type for other low-level things down the line.

Swift SVN r3793
2013-01-18 02:24:23 +00:00
Joe Groff
c2096a4bfe SIL: Include conformances in InitExistentialInst.
IRGen needs the conformances to be able to initialize an existential container.

Swift SVN r3786
2013-01-17 23:20:56 +00:00
Joe Groff
521b9376eb SIL: Make RefElement take VarDecl instead of index
This is inconsistent with ElementAddr and Extract, but allows all the hairy logic of accessing class fields in IRGen to stand without a bunch of pointless refactoring.

Swift SVN r3778
2013-01-16 22:12:17 +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
4239b2edf0 SIL: Make Value::operator bool() explicit.
Implicit conversions to integer are bad news.

Swift SVN r3758
2013-01-14 02:57:08 +00:00
Dave Zarzycki
ed5de91828 Fix build warnings
Swift SVN r3749
2013-01-11 18:58:44 +00:00
Joe Groff
aba47a6b90 Add a '-sil-emit-llvm' option to the driver.
It doesn't do anything but crash yet. Also add an entry point fo SILGen to Subsystems so that it can be invoked without dependency on SIL or SILGen.

Swift SVN r3738
2013-01-11 01:51:54 +00:00
Joe Groff
c320fe1e39 SILGen: Implement variadics in argument tuples.
Bring variadic support back to tuples in argument contexts. Since the variadic part of a tuple is never going to be destructured, we can evaluate it all eagerly and reuse the code in emitTupleShuffle that was already there.

Swift SVN r3734
2013-01-10 21:59:22 +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
d9db6d86e5 SIL: Make (Archetype|Protocol)Method with pre-formed types.
Deriving the instruction type of these nodes needs to go through SILGenModule so that their SILTypes have SILFunctionTypeInfo properly associated with them.

Swift SVN r3729
2013-01-10 03:45:42 +00:00
Joe Groff
2858bc4fde SIL: Replace '-dump-sil-verbose' hack with DEBUG()
Swift SVN r3728
2013-01-10 03:45:40 +00:00
Dave Zarzycki
92d87def4c Build warning fix: missing newline at EOF
Swift SVN r3717
2013-01-09 18:04:23 +00:00
Joe Groff
2bed090d26 SILGen: Oops, left some debug dumps in.
Swift SVN r3715
2013-01-09 00:56:28 +00:00
Joe Groff
b406e56738 SILGen: Generate type info for function types.
Record the destructured input types, result type, and indirect-return-ness of function types so that they are available for IRGen.

Swift SVN r3714
2013-01-09 00:54:56 +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
49521d60e5 SIL: Rename instructions.
ExistentialMethod -> ProtocolMethod for better specificity.
[De]AllocExistential -> [De]InitExistential because it doesn't necessarily allocate anything.

Swift SVN r3710
2013-01-08 17:14:45 +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
2ffe9f848a SILGen: Fix detection of address-only generics.
BoundGenericTypes aren't NominalTypes, so TypeInfo wasn't correctly walking generic StructDecls and propagating address-only-ness for generic struct types.

Swift SVN r3692
2013-01-05 01:02:01 +00:00
Joe Groff
a3b61a60a9 SILGen: Fix dtor of class with generic base.
emitDestructor wasn't properly SpecializeInst-ing the base class destructor constant before calling it.

Swift SVN r3689
2013-01-05 00:19:24 +00:00
Joe Groff
481f0128a6 SILGen: Refactor "epilog" code for ctors and dtors
Constructors and destructors both set up an epilog block so that 'return' within the decl body has a place to branch to without skipping all the implicit behavior. Factor out the common code to branch to and emit the epilog basic branch, and throw in a peephole optimization to fuse the BB when it has no predecessors (as it currently always does because of rdar://problem/12950817/).

Swift SVN r3688
2013-01-04 23:58:42 +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