Build closures for local getter and setter decls, and load the get closure when the property is referenced in a normal expression context.
Swift SVN r3417
- Steal some bits from SILConstant::id to reference getter and setter definitions, and normalize SILConstant references to property FuncDecls to be SILConstant references to the ValueDecl getter/setter instead.
- In normal expression context, handle getting properties by calling the getter and materializing the return value. Setting lvalues is not implemented yet; that will require borrowing the LValue and GenLValue machinery from irgen to construct logical lvalue paths in assignment and byref contexts.
Swift SVN r3414
Have TypeConverter generate a field-to-index mapping for physical fields of loadable structs.
Use the resulting TypeInfo mapping to generate element_addrs for physical MemberRefExprs, borrowing the logic from TupleElementExpr.
Swift SVN r3406
The type of an Extract from the right-hand side is an rvalue type, not the lvalue type of the corresponding tuple assignment destination.
Swift SVN r3394
If the operand of a TupleElementExpr is an lvalue, derive the address of the element from the operand rather than try to extract a value from it as the code was doing before.
Swift SVN r3392
Derives the address of a member from the address of a fragile value type. SIL extract : SIL element_addr :: LLVM extractvalue : LLVM getelementptr. Also add SILVerifier checks for ExtractInst and ElementAddrInst that they deal only in values and addresses, respectively.
Swift SVN r3391
Instead of considering `constant_ref @var` to give the address of `var` directly, consider it to be a `() -> [byref] T` function that returns the address, presumably after running the initializer for the global if necessary. Generate a DeclRef to a global var as a constant_ref to get the function followed by an apply to get the address. Actually generating the global accessor is still to be implemented.
Swift SVN r3389
Change the signature of emitFunction to take just a decl (and leave it up to the implementation to create the SILConstant) because emitFunction may produce functions for multiple SILConstants from a single FuncExpr.
Swift SVN r3388
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