Commit Graph

9293 Commits

Author SHA1 Message Date
Joe Groff
15d606b630 IRGen: Lower SIL class_method for native classes.
Turn class_method into a vtable lookup for Swift class and class metatype instances.

Swift SVN r4467
2013-03-21 20:50:37 +00:00
John McCall
3c7df2d9d9 Waste time during SIL-generation keeping a lot of information
that we're not even using.

Oh, and initialize the existential operand of a
DeinitExistentialInst.

Swift SVN r4464
2013-03-21 05:29:19 +00:00
Joe Groff
e07609c3e7 SIL: Add ClassMetatypeInst.
Represents getting the dynamic metatype from a class instance.

Swift SVN r4459
2013-03-20 23:27:18 +00:00
Joe Groff
c090f65a06 IRGen: Update lowering for SIL protocol_method.
Swift SVN r4456
2013-03-20 20:48:16 +00:00
Joe Groff
61077a641d IRGen: Lower SIL function args in right order.
Map the SIL entry point BB's args to LLVM function args in the inner-to-outer-uncurry order used by Swift's ABI.

Swift SVN r4452
2013-03-20 03:23:56 +00:00
Joe Groff
ac73865dd7 IRGen: Update lowering of SIL applications.
We no longer need the PartialCall hackery in IRGen to uncurry calls, because SILGen does it for us.

Swift SVN r4451
2013-03-20 00:02:49 +00:00
Joe Groff
98fd61559a SIL: Keep SIL argument counts for each curry level
Track the argument offset for each curry level of an uncurried function so that IRGen can map SIL arguments to LLVM arguments in the correct order for the underlying calling convention.

Swift SVN r4449
2013-03-19 16:28:43 +00:00
Joe Groff
35fb03afc2 SILGen: Adopt thin function types.
Emit constant_refs as having thin function type and introduce context with closure instructions. Add checks to the verifier that function reference operations act on the right level of thinness.

Swift SVN r4432
2013-03-18 22:20:23 +00:00
Joe Groff
9da0f893e5 SIL: Add address_to_pointer instruction.
Make converting a SIL address to a Builtin.RawPointer its own instruction separate from implicit_convert, which will let me get rid of a goofy edge case in IRGenSIL.

Swift SVN r4412
2013-03-18 03:14:24 +00:00
Joe Groff
f3bf84c12f SILGen: Fix generic method of nongeneric class.
Properly emit a SpecializeInst for an uncurried call to a generic method of a nongeneric class, where there are only generic parameters on the second uncurry level and the outermost function type appears monomorphic.

Swift SVN r4410
2013-03-17 18:39:11 +00:00
Joe Groff
4c09ef61e3 Add conditional expressions.
Implement the syntax 'if x then y else z', which evaluates to 'y' if 'x' is true or 'z' if 'x' is false. 'x' must be a valid logic value, and 'y' and 'z' must be implicitly convertible to a common type.

Swift SVN r4407
2013-03-16 20:28:58 +00:00
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