Commit Graph

9293 Commits

Author SHA1 Message Date
Joe Groff
03610fab6c SILGen: Emit DeclRefExprs using the expr type.
This gets the right type for generic-parameterized DeclRefExprs.

Swift SVN r4693
2013-04-11 23:20:32 +00:00
Joe Groff
6a516363cf SIL: Verify TupleInst elements.
The element types should match the corresponding field types of the result tuple type.

Swift SVN r4692
2013-04-11 23:20:30 +00:00
Joe Groff
9ff6e65af0 IRGen: Lower SIL ArchetypeMethodInst.
ArchetypeMethodInst, like ProtocolMethodInst, actually needs to be modeled as returning a thick function type, in order to represent the metadata parameter to the witness table function. With that change to SILGen, implement ArchetypeMethodInst IRGen.

Swift SVN r4688
2013-04-11 22:24:26 +00:00
Joe Groff
a33ab2ee16 SIL: Verify DowncastInsts harder.
Doug found that the verifier would admit a DowncastInst that took an lvalue as the input, which is bogus. Refine the verifier rules for DowncastInst so it only admits class rvalues and destination types.

Swift SVN r4685
2013-04-11 21:40:11 +00:00
Joe Groff
44eaa29ff9 SILGen: Forward archetypes from alloc to init ctor
During type checking, fake up a "forwarding" substitution set for constructor decls that maps archetypes to themselves. This is goofy, but type-checking is the place that knows how to make ProtocolConformances, and I don't want to reinvent that. Use these forwarding substitutions in SILGen when emitting a generic allocating constructor so we can properly emit a call to the corresponding initializing constructor.

Swift SVN r4684
2013-04-11 21:40:09 +00:00
Chris Lattner
7f13910498 revert r4673: respecializing SILConstant for ValueDecl instead of Decl.
On second thought, having SILConstant be able to point to a TLCD is going 
against the goal of making SILConstant be a "SILGen thing".  I'll find another
approach.


Swift SVN r4680
2013-04-11 17:41:36 +00:00
Chris Lattner
f4dfaed4cf generalize SILConstant to hold a Decl*, not just a ValueDecl*.
This is in preparation to allow SILConstant of TopLevelCodeDecl.



Swift SVN r4675
2013-04-11 00:46:36 +00:00
Joe Groff
fd14aa423a SILGen: Consistently handle stores and assigns.
Factor out the logic for properly storing a loadable or address-only rvalue into ManagedValue::forwardInto and ManagedValue::assignInto, and use those methods everywhere instead of trying to cut corners and directly emit store instructions.

Swift SVN r4670
2013-04-10 23:48:00 +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
bfd2f85b5c Parse 'fallthrough' statements.
Create a new FallthroughStmt, which transfers control from a 'case' or 'default' block to the next 'case' or 'default' block within a switch. Implement parsing and sema for FallthroughStmt, which syntactically consists of a single 'fallthrough' keyword. Sema verifies that 'fallthrough' actually appears inside a switch statement and that there is a following case or default block to pass control to.

SILGen/IRGen support forthcoming.

Swift SVN r4653
2013-04-10 17:30:42 +00:00
Joe Groff
9a98f9353d SILGen: Remove hack to convert toplevel code type.
All SILTypes now reliably convert through the same mechanism, so this hack isn't needed anymore.

Swift SVN r4628
2013-04-07 02:42:54 +00:00
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