Commit Graph

9332 Commits

Author SHA1 Message Date
Chris Lattner
b4fd6dd04a Change TopLevelCodeDecl to allow it to hold a sequence of different exprs and statements in one unit, wrapping them into a BraceStmt. This makes it more similar to other decls (e.g. funcdecl, ctor decls, etc) and will be useful for future sil work.
Unfortunately, this regresses the repl when expressions like (1,2) are entered. This is because the repl is violating some invariants (forming dags out of ASTs, making ASDAG's which upset the type checker).  I'm going to fix this next, but can't bring myself to do it in the same commit.



Swift SVN r4617
2013-04-05 22:33:14 +00:00
Joe Groff
442a51ef36 SIL: Fix Verifier.
The Verifier wasn't actually verifying function bodies, because I neglected to visit the actual basic blocks after checking the entry point arguments in verifySILFunction. This revealed a SILType identity issue where TypeConverter::getLoweredType and SILType::getEmptyTupleType returned non-identical SILTypes for the empty tuple type; fix that by removing SILType::getEmptyTupleType, moving TypeConverter into SILModule, and forcing all SILType creation through TypeConverter.

Swift SVN r4616
2013-04-05 22:19:14 +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
fe23727891 rename Value.h -> SILValue.h, missed it in the last pass.
Swift SVN r4592
2013-04-03 18:47:32 +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
Chris Lattner
05dcf38c1c move SIL/Function.h to SILFunction.h in preparation to renaming the class.
Swift SVN r4589
2013-04-03 18:27:54 +00:00
Chris Lattner
85c7c494ae Wire up the most trivial support for sil parsing, which allows us to write
a (trivial, empty) sil parser testcase.  The parser is still not SIL aware
though.


Swift SVN r4585
2013-04-03 05:57:42 +00:00
Joe Groff
4923acce2b Use C++11 alignof(T) instead of llvm::AlignOf<T>.
Swift SVN r4583
2013-04-03 02:41:29 +00:00
Joe Groff
3a9100f559 SIL: Clean up SILType interface for functions.
Function and compound types have a bunch of extra calling convention and uncurrying info stuffed into a "SILTypeInfo" object that until now had to be fetched through the SILModule. Change the representation of SILType to be a PointerUnion of CanType and SILTypeInfo*, and move the uncurry level onto the SILTypeInfo for functions, so that SILTypeInfo is available directly through the SILType and SILType can go back to being pointer-sized.

Swift SVN r4582
2013-04-03 02:33:29 +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
Chris Lattner
b96818f7d7 Line up all comments (predecessors, users) in column 50 instead of being so tab ragged.
Print sil function bodies as "sil" declarations, not func_decl.
Print an @ before the sil declaration name for consistency with uses.



Swift SVN r4568
2013-04-01 23:10:18 +00:00
Chris Lattner
09d1eb8cb1 some minor stylistic changes to sil printing - add braces around function bodies.
Swift SVN r4567
2013-04-01 22:48:01 +00:00
Joe Groff
88cae3e8f3 SILGen: Fix conditions that jump in both branches.
Fixes <rdar://problem/13549626>.

Swift SVN r4563
2013-04-01 22:38:35 +00:00
Joe Groff
e0aa78f286 SIL: Print uses when printing instructions.
Swift SVN r4560
2013-04-01 22:10:08 +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
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
1f5bdda08f SIL: Add insns for archetype/protocol metatypes.
Archetype and protocol 'x.metatype' expressions eventually need to do a dynamic lookup, like 'x.metatype' for classes. These instructions represent that lookup.

Swift SVN r4534
2013-03-29 03:57:22 +00:00
Joe Groff
1a8b35d383 REPL: Support -sil-irgen.
Add a 'startElem' option to SILModule::constructSIL so that it can be used with REPL input.

Swift SVN r4519
2013-03-28 18:38:29 +00:00
Joe Groff
9667bda089 Implement 'as' syntax for coercions and casts.
Provide distinct syntax 'a as T' for coercions and 'a as! T' for unchecked downcasts, and add type-checker logic specialized to coercions and downcasts for these expressions. Change the AST representation of ExplicitCastExpr to keep the destination type as a TypeLoc rather than a subexpression, and change the names of the nodes to UncheckedDowncast and UncheckedSuperToArchetype to make their unchecked-ness explicit and disambiguate them from future checked casts.

In order to keep the changes staged, this doesn't yet affect the T(x) constructor syntax, which will for the time being still perform any construction, coercion, or cast.

Swift SVN r4498
2013-03-27 22:27:11 +00:00
Joe Groff
43fe40bfd7 SILGen: Start implementing 'emit into' behavior.
If the result of an expression is address-only, we can store the result in-place if we have an uninitialized destination buffer for it, such as in a variable initialization or return. Modify SILGenFunction::visitExpr to write to the buffer of an Initialization if one is available instead of allocating a temporary.

A couple cases that still need to be implemented are destructuring tuple initializations (e.g. 'var (a, b) = (foo(), bar())') and apply expression results.

Swift SVN r4492
2013-03-27 02:58:57 +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
90edf84520 SIL: Verify func args, branch args, and returns.
Add code to the verifier to verify that the entry point BB for a function has the right argument types for its function type, return instructions match the function type, and branch instruction arguments match the branched-to BB.

Swift SVN r4487
2013-03-25 23:49:54 +00:00
Joe Groff
d156b625df SILGen: Lower conditional expressions.
Swift SVN r4486
2013-03-25 23:49:52 +00:00
Joe Groff
59d418de81 SIL: Add arguments to branch instructions.
BranchInst and CondBranchInst need to be able to pass arguments into the target BB. Add argument lists to the instructions.

Swift SVN r4485
2013-03-25 19:28:13 +00:00
Joe Groff
e8b66bce1d SIL: Rename implicit_convert to convert_function.
All the other implicit conversions have been given their own instructions, so specialize this ill-specified instruction to its one remaining use, for converting compatible function types.

Swift SVN r4482
2013-03-25 16:51:03 +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
557100aefc SILGen: Keep [thin] through FunctionConversionExpr
FunctionConversionExpr was converting the type of SIL values to thick function types without emitting SIL to create the dummy context, which was confusing IRGen.

Swift SVN r4476
2013-03-22 19:09:26 +00:00
Joe Groff
cda12bcdf0 SILGen: Fix lowering of ClosureExprs w/o captures.
Another bogus assert.

Swift SVN r4475
2013-03-22 16:51:58 +00:00
Joe Groff
73de77cc34 SILGen: Remove bad assert from Condition.
It's valid to fold away the continuation BB if it's not reachable, such as in a loop that breaks or continues in every execution path.

Swift SVN r4474
2013-03-22 16:30:46 +00:00
Joe Groff
10438902dd Remove GetMetatypeExpr.
Now that we don't allow static methods to be invoked from instances we no longer need an AST node to represent an implicit instance-to-metatype conversion. MetatypeExpr encodes the explicit '.metatype' operation.

Swift SVN r4472
2013-03-22 00:28:21 +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
John McCall
1a8d624b6c Rename the SIL 'closure' instruction to 'partial_apply'.
Swift SVN r4468
2013-03-21 21:59:28 +00:00
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