Replace 'constant_ref' with 'function_ref', which references a SILFunction directly, and 'global_addr', which references a global variable VarDecl. Get rid of the SILConstant-to-SILFunction mapping in SILModule and replace it with an ilist of SILFunctions. Allow SILFunctions to be 'external' by not having any blocks in their body.
For now, SILFunctions still carry around their SILConstant "name", because name mangling and IRGen still rely on access to the original decl in order to recover IRGen information, which unfortunately leaves IRGen's CodeRefs in a gross, awkward intermediate state. Lifting mangling, AbstractCC, and other linkage attributes to SIL should clear up this up.
Swift SVN r4865
Hand the SGFContext, with the current 'emit into' Initialization, down into the CallEmission machinery so that it can be used to emit indirect returns directly into their uninitialized destination buffers without an intermediate copy.
Swift SVN r4863
The value semantics primitives load/move/assign/init/destroy lower trivially to SIL value semantics operators, and the bridge casting operations introduce r/r semantics that should be visible to the ARC optimizer, so move the lowering for these builtins up to SILGen. Add a BUILTIN_SIL_OPERATION metaprogramming macro to Builtins.def, and add a facility similar to IRGen's former SpecializedCallEmission so we can handle builtin call emissions as special cases.
This also sets up the framework for eventually reintroducing special-case handling of known functions like &&, ||, Bool.getLogicValue, Int.convertFromIntegerLiteral, etc. in SILGen.
Swift SVN r4862
Add an IsaInst to represent type tests, and implement SILGen for IsSubtypeExpr AST nodes. Get rid of SuperIsArchetypeExpr because it's not really necessary to have it different from IsaSubtype--the SIL and IR behavior is identical.
Swift SVN r4855
Create a UnaryInstructionBase that factors all the boilerplate out of all the unary instructions. It'll be easy to generalize to all fixed-arity instructions, but let's start simple. No functionality change.
Swift SVN r4854
Port IRGen's calculation of consumed arguments and return value semantics to SILGen, and use it to handle the ownership semantics of calls. Refactor the handling of properties and other clients of emitApply so they can properly hand ownership semantics down to it.
This should let all the moribund cleanup management code in IRGen die. Unfortunately Scope appears to be tied into scoped calculated metadata caching so it's not quite ready to die.
Swift SVN r4834
Don't take for granted that function applications consume their arguments when emitting the object pointer argument of array injections or the function argument of applications. That's not going to be the case for ObjC methods.
Swift SVN r4812
Evaluating all the arguments before uncurrying the function is wrong if the function can't be completely uncurried. Tweak CallEmission so it can work in Exprs instead of already-evaluated RValues and evaluate them in the right order relative to the function applications it emits. This also makes it easier to emit more accurate location info for each of the apply instructions.
Swift SVN r4811
ObjC classes don't have a deallocating destructor, so we can't call up to it in a class derived from an ObjC class. Hack SILGen not to emit a call to the superclass destructor of a class inherited from an ObjC class. This is the wrong thing, but it looks like destructors don't get hooked up to ObjC dealloc methods anyway yet, so what the Swift destructor of an ObjC-derived class does is moot right now. This lets us remove the guards from IRGen that prevented ObjC destructors from being emitted.
Swift SVN r4784
Teach SILGen how to emit the implicit elementwise constructor for structs and the implicit default constructor for classes, and eliminate the now dead IRGen code for them. Add a StructInst SIL instruction to represent constructing a loadable struct value from elements, analogous to TupleInst for tuples.
Swift SVN r4778
If capture analysis deems a local variable fixed-lifetime, we don't need to put it in a box and can instead locally stack-allocate and destroy it.
Swift SVN r4756
Putting 'this' in a box causes 'this' to be released with the box at the end of the destructor and infinite-loop. Double-retain it to work around this. Gross.
Swift SVN r4752
This is unfortunate (and wrong--this really shouldn't be capturable out of a ctor or dtor), but is needed for now in order for auto_closures over 'this' to work with SILGen's current naive handling of local variables and captures.
Swift SVN r4735
Otherwise we try to release junk pointers when we reassign class fields in the struct. Add an attribute to InitializeVarInst so that when dataflow analysis comes online, it knows that these InitializeVars need to be eliminated and can't be lowered to default constructor calls (since we're already in a constructor).
Swift SVN r4730
Teach SILGen's CallEmission how to emit calls to an uncurry level above the natural uncurry level of the callee. Factor out a Callee object (like in IRGen) that encapsulates how to emit an abstract callee at any uncurry level. Currently only currying standalone non-generic functions works.
Swift SVN r4720
type, though; I had to define a WriteAsOperand function and
add a front() method to SILFunction to get this to work.
Rip out my dominators implementation and replace it with
LLVM's. I'd forgotten that LLVM's was actually generic.
Swift SVN r4717
For non-generic, non-property, non-instance-method curried functions, emit SIL thunks for all of the intermediate curry levels. The generic, property, and instance method cases need some additional SIL and irgen work to support, but aren't well supported by the current backend, so I'll leave them to be dealt with later. This causes the SliceUInt8 test to break down in IRGen; I'll fix that next.
Swift SVN r4715
different routine which tries to print some extra context
before triggering an assert.
For now, this is just the instruction and its basic block,
but I think a nicer output would be something like
%0 = ...
%1 = ...
-> %2 = ...
%3 = ...
br ...
Swift SVN r4711
take a const ValueBase* instead of a SILValue, implement SILArgument
cases for a few visitors and opt others out explicitly, and assert
that classes in the SIL value hierarchy override their superclass's
classof.
Swift SVN r4705
For now, lazy-initializing global accessor functions aren't really a thing, so just emit all global variable references as global addresses.
Swift SVN r4701
string_literal can have a two-element tuple type (with any labels) or a Builtin.RawPointer type, so print the type of the string_literal when emitting SIL.
Swift SVN r4699
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
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
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
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
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
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
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