ClosureExprs mostly share the same logic as FuncExprs, but need a bit extra help to handle the implicit return from the body expression. Genericize some FuncExpr code to work with an arbitrary CapturingExpr or to accept body and param patterns separately so they can be passed the components of FuncExprs or ClosureExprs.
Swift SVN r3376
We need something more general than ValueDecl to be able to talk about anonymous functions, curried entry points, etc. as SIL constants. SILConstant is a (ValueDecl | CapturingExpr) union with an additional index for discriminating multiple instances or entry points derived from the same AST entity. Update ConstantInst and SILModule's function table to be keyed by SILConstant rather than ValueDecl.
Swift SVN r3372
Local constants (such as local FuncDecls) are never modifiable so can be captured by value. Give the local constant value to the closure when visiting a local FuncDecl, and in the function body, register the corresponding closure context argument as a local constant for that context.
Swift SVN r3369
Associate the closure object for a local FuncDecl with the FuncDecl rather than with the DeclRefExpr. Move the closure creation code into SILGenFunction::visitFuncDecl, and add a LocalConstants map to SILGenFunction to store closures generated from local decls. Add a constructor to ConstantRefInst to allow it to be associated directly with ValueDecls in addition to DeclRefExprs.
Swift SVN r3368
Generate local functions with captured variables as arguments to the entry block. Still need to implement the closure construction sequence when local functions are referenced.
Swift SVN r3357
SIL needs a way to generate and reference getters and setters, which share a decl. Change SILModule to key its component Functions on a (ValueDecl, flags) pair rather than just on ValueDecl.
Swift SVN r3354
If the TranslationUnit being silgenned is a Main or Repl unit, generate globals like locals. Generating toplevel functions as closures still needs to be done.
Swift SVN r3340
Add a toplevel Function object to SILModule. When SILGenModule encounters TopLevelCodeDecls, pass their bodies on to SILGenFunction to emit SIL into the toplevel function
Swift SVN r3336
Create a SILModule type, and lift ownership of TU-global things like the bump allocator and type list uniquing from Function to SILModule. Move the ad-hoc SIL dumping logic out of main() into SILModule and into a new SILGenModule class.
Swift SVN r3324
If an lvalue DeclRefExpr doesn't have a local VarLocs entry in the current SILGen function, assume it's a global variable and generate a constant_ref to get at its address. Eventually there should be a SILGenModule with which we can check that the global access is valid. Either ConstantRef should be renamed or a new GlobalVarRef instruction should be added as well.
Swift SVN r3319
Remove the AllocTmp instruction and represent MaterializeExpr allocations using 'alloc_var stack'/'dealloc_var stack' instructions. Rename Dealloc to DeallocVar, and add an AllocKind attribute to AllocVar and DeallocVar. Update MaterializeExpr SILGen to generate an AllocVar with a DeallocVar cleanup instead of AllocTmp. Tweak SILPrinter's presentation of AllocVar and DeallocVar to be in line with what SIL.rst claims.
Swift SVN r3311
Now that it's being used on both tuples and structs, the current name doesn't make much sense. SIL.rst specifies a unified set of extract/insert/gep instructions that operate on either tuples or nominal fragile structs.
Swift SVN r3303
Stick a ReferenceTypeElements array in the SIL TypeInfo that gives a path to every reference type within a fragile aggregate. Since this now makes TypeInfo nontrivial to compute, steal some of the TypeConverter infrastructure from IRGen to manage TypeInfos for the current SILGen context. Use the reference type elements to determine triviality and to generate retain/release sequences for nontrivial loadable types.
Swift SVN r3301
Argument lifetime is now handled adequately by ManagedValue, so the special-case emitRetainArgument/DestroyArgument helpers aren't needed.
Swift SVN r3297
Steal IRGen's ManagedValue abstraction to handle the generation and consumption of rvalues. ManagedValue is a (Value, Cleanup?) pair that supports "forward"-ing ownership of a value and disabling its cleanup, which allows temporary values to be generated, retained, and either consumed by an ownership-taking operation such as a function call or aggregate initialization or released if unused.
Swift SVN r3293
Add an `emitApply` method to SILGen that retains arguments and then applies a function. Change B.createApply calls to use emitApply instead.
Swift SVN r3282
SILGenExpr has special case logic to avoid constructing a SIL tuple for function arguments, but this logic failed to cover single-argument functions, in which the argument AST goes through a ScalarToTupleExpr node rather than a TupleExpr node. This patch adds similar logic to the ScalarToTupleExpr case so that single function arguments don't go through a SIL tuple instruction.
Swift SVN r3281
Build some infrastructure for handling retain/release/copy/destroy of values. Use this to retain values when storing them into boxes and to clean up reference type arguments on function exit. Right now this just stupidly assumes "value type is trivial, reference type is retained/released", but it eventually needs to handle address-only types using the indirect copy_addr/destroy_addr instructions and to handle loadable value types with reference members by retaining the proper members. Passing arguments to function calls, reassignment, and cleanup of full expression temporaries all still need implementation.
Swift SVN r3267
Update codegen for local variables and arguments to use the new alloc_box instruction to allocate retainable storage for the variables and to release the boxes when the variables go out of scope. Update tests to check for alloc_box and release sequences instead of alloc_var.
Swift SVN r3242
It would be better in the long term to copy the getText() from the AST into the instructions so they can stand independent of any AST node, but this is convenient for now.
Swift SVN r3233