Commit Graph

9293 Commits

Author SHA1 Message Date
Joe Groff
2bed090d26 SILGen: Oops, left some debug dumps in.
Swift SVN r3715
2013-01-09 00:56:28 +00:00
Joe Groff
b406e56738 SILGen: Generate type info for function types.
Record the destructured input types, result type, and indirect-return-ness of function types so that they are available for IRGen.

Swift SVN r3714
2013-01-09 00:54:56 +00:00
Joe Groff
4dffe605f7 SILGen: TypeLoweringInfo.{h,cpp} -> TypeLowering
The module itself performs type lowering, it doesn't just house TypeLoweringInfo.

Swift SVN r3713
2013-01-09 00:54:54 +00:00
Joe Groff
cb03dbd3be SIL: Associate SILTypeInfo with the SILModule.
For some types, there is lowering info that is useful to IRGen, such as the SIL-level calling convention for functions or the element layout of aggregates, that can't fit in a SILType pointer but still should be associated with the module. Add a SILTypeInfo hierarchy, add a mapping of SILTypes to infos to SILModule, and rename the SILGen-specific TypeInfo to TypeLoweringInfo. Move the derived layout information for compound types from TypeLoweringInfo to SILTypeInfo so that IRGen will be able to use it.

Swift SVN r3712
2013-01-09 00:02:38 +00:00
Joe Groff
49521d60e5 SIL: Rename instructions.
ExistentialMethod -> ProtocolMethod for better specificity.
[De]AllocExistential -> [De]InitExistential because it doesn't necessarily allocate anything.

Swift SVN r3710
2013-01-08 17:14:45 +00:00
Joe Groff
0bf47aaf74 SILGen: Count base class fields for field offsets.
Derived class fields were being given offsets from zero even if the base class has fragile fields.

Swift SVN r3708
2013-01-08 02:09:08 +00:00
Joe Groff
2ffe9f848a SILGen: Fix detection of address-only generics.
BoundGenericTypes aren't NominalTypes, so TypeInfo wasn't correctly walking generic StructDecls and propagating address-only-ness for generic struct types.

Swift SVN r3692
2013-01-05 01:02:01 +00:00
Joe Groff
a3b61a60a9 SILGen: Fix dtor of class with generic base.
emitDestructor wasn't properly SpecializeInst-ing the base class destructor constant before calling it.

Swift SVN r3689
2013-01-05 00:19:24 +00:00
Joe Groff
481f0128a6 SILGen: Refactor "epilog" code for ctors and dtors
Constructors and destructors both set up an epilog block so that 'return' within the decl body has a place to branch to without skipping all the implicit behavior. Factor out the common code to branch to and emit the epilog basic branch, and throw in a peephole optimization to fuse the BB when it has no predecessors (as it currently always does because of rdar://problem/12950817/).

Swift SVN r3688
2013-01-04 23:58:42 +00:00
Joe Groff
08399cf882 SILGen: Emit allocating/initializing class ctors.
Add a new SILConstant kind to refer to the initializer of a ConstructorDecl. Emit class constructors as separate allocating and initializing functions named SILConstant(CD) and SILConstant(CD, Initializer) so that derived classes will be able to invoke their superclass constructor.

Swift SVN r3686
2013-01-04 23:13:38 +00:00
Joe Groff
718126bd2e SILGen: Emit implicit destructors.
Add a new "kind" to SILConstant so that SIL can reference destructors without decls. Generate a destructor for classes even if they don't have an explicit destructor. If a class has a base class, call the base class destructor instead of dealloc_ref-ing the current instance.

Swift SVN r3665
2013-01-03 23:57:48 +00:00
Joe Groff
984f1dad91 SILGen: Generate explicit constructors.
Generate ConstructorDecl bodies, sandwiched between code to allocate an instance before running the body and code to return the initialized value afterward. Still need to:
- handle the implicit constructor for structs
- divide the class constructor into allocating and initializing entry points
- chain a call to the base class initializer entry point from the derived class initializer

Swift SVN r3662
2013-01-03 20:12:35 +00:00
Joe Groff
05adc65d14 SIL: Add AllocRefInst.
Represents a raw allocation of a reference type instance. This lets us implement constructors for reference types.

Swift SVN r3661
2013-01-03 20:12:32 +00:00
Joe Groff
7b2c1a31e5 SILGen: A first pass at generating destructors.
Generate explicit destructors by emitting their bodies then emitting release sequences for the class's members. Eventually we'll need to also emit implicit destructors for classes without explicit destructors and to chain a call to the base class destructor, which will require adding a new linkable entity flag onto SILConstant for destructors, similar to getter/setters.

Swift SVN r3655
2013-01-03 04:24:43 +00:00
Dave Zarzycki
4f311202a6 Fix a build warning in Release builds
Swift SVN r3646
2013-01-02 21:52:38 +00:00
Joe Groff
a6f634cb37 SILGen: Generate SuperToArchetypeExprs.
Use SuperToArchetypeInst to handle super-to-archetype downcasts.

Swift SVN r3644
2013-01-02 21:00:39 +00:00
Joe Groff
e7fc1d0bba SIL: Add SuperToArchetypeInst.
Add an instruction to represent super-to-archetype downcasts. Since archetypes are address-only, it needs to take a reference to the destination archetype as a parameter.

Swift SVN r3643
2013-01-02 21:00:37 +00:00
Joe Groff
661f6d8537 SIL: Destruct Instructions when they're erased.
Invoke the leaf destructor for the Instruction when it's eraseFromParent-ed, so that the SILSuccessors of BranchInsts get updated when branches are removed. This un-breaks the peepholing of breaks out of else blocks.

Swift SVN r3641
2013-01-02 18:53:40 +00:00
Chris Lattner
3487cde0c6 fix a pedantic warning.
Swift SVN r3609
2012-12-30 06:42:25 +00:00
Joe Groff
93ca0d39de SILGen: Remove broken Condition::exitFalse merging
We never actually invoke destructors on SIL Instructors, so the nice SILSuccessor RAII thingy in BranchInsts never kicks in to fix up predecessor lists when we erase BranchInsts. Disable the code in Condition::exitFalse that tries to merge terminated else blocks and triggers an assert because of stale predecessor info. After the break I'll look into making Instruction::eraseFromParent actually perform some sort of instruction-specific cleanup.

Swift SVN r3592
2012-12-22 01:10:52 +00:00
Joe Groff
c8d7cd1bcc SIL: Clean up some stray dumps.
Swift SVN r3591
2012-12-22 01:10:50 +00:00
Joe Groff
725bcd9994 SILGen: Fix DenseMap abuse in TypeConverter.
Passing around internal references to a hashed container--not the best idea. Allocate TypeInfos from a bump allocator so they have fixed addresses and stash the pointers in the type map. While we're here, simplify the FragileElement interface a bit by making it take ValueDecls directly as keys instead of identifiers.

Swift SVN r3590
2012-12-22 01:10:49 +00:00
Joe Groff
619cfdee0f SILGen: Handle GenericMemberRef of associated type
Associated types still (correctly) manifest as GenericMemberRefs of the metatype. Use the new AssociatedMetatypeInst to represent getting an associated metatype from a generic.

Swift SVN r3589
2012-12-22 01:10:48 +00:00
Joe Groff
1892f51a05 SIL: Add AssociatedMetatypeInst.
Represents getting an associated type metatype from a generic metatype.

Swift SVN r3588
2012-12-22 01:10:46 +00:00
Joe Groff
4eeb8eadb9 SIL: Fix ApplyInst verifier bug.
If a function has an address-only return and a single non-tuple argument, then it's valid to have a two-argument call where the first argument matches the function input type and the second matches the result type. This occurs for instance if you try to call Builtin.load, with type Builtin.RawPointer -> T, for an address-only T.

Swift SVN r3587
2012-12-22 01:10:45 +00:00
Joe Groff
b75c948f1b SILGen: Fix address-only return in curried decl.
Checking the result type of the FunctionType for address-only-ness doesn't work for a curried func decl, whose result type is a function type. Pass down the result type from the func decl to emitProlog instead of letting emitProlog derive it from the expr type.

Swift SVN r3586
2012-12-22 01:10:43 +00:00
Joe Groff
0c1514801b SILGen: Reimplement var tuple initialization.
Provide a temporary lame implementation of tuple initialization in emitExprInto so we can reenable the decls tests and fix up some other things before fully implementing in-place initialization.

Swift SVN r3585
2012-12-22 01:10:39 +00:00
Joe Groff
d98083184c SILGen: Add a context argument to SILGenFunction.
Add some private per-recursion-level info that will let SILGen track emit-into initializations, materializing into a load, and other peephole optimizations. We'll also need context to be able to distinguish argument tuples from tuple values, which need to lower differently when they contain address-only elements.

Swift SVN r3579
2012-12-21 21:16:35 +00:00
Joe Groff
fd87d78cda SIL: Fix some verifier bugs.
ArchetypeMethodInst was still trying to cast to LValueType rather than checking the address-ness of the SIL type, and ApplyInst was failing for an address-only byref argument. This makes the last disabled expressions test pass again.

Swift SVN r3577
2012-12-21 18:23:43 +00:00
Joe Groff
b7b8c4a5fd SILGen: Use Initialization for indirect returns.
Indirect return values can be initialized in-place using emitExprInto, like vars and arguments.

Swift SVN r3575
2012-12-21 17:18:18 +00:00
Joe Groff
975e8dd55b SILGen: Improve initialization implementation.
Prepare to do variable and return value initialization the smart way, by allocating the buffer first and then emitting the expression result directly into the buffer rather than by evaluating the expression then allocating and initializing the buffer. Create an Initialization class hierarchy that represents an uninitialized buffer or tuple of uninitialized buffers, and rewrite the argument and pattern binding logic to allocate and build up an Initialization first then emit the expression into it. The "emit into" part still needs to be implemented, as does tuple pattern binding ('var (a,b,c) = ...'). Disable some decls test that do tuple binding for now.

Swift SVN r3574
2012-12-21 02:37:18 +00:00
Joe Groff
21dcefd4f1 SIL: Add DeallocRefInst.
Needed to represent deallocating an uninitialized box.

Swift SVN r3573
2012-12-21 02:37:17 +00:00
Joe Groff
621ab377ca SILGen: Let addr-only vals into lvalue MemberRefs.
Address-only values are supported well enough now as assignment and function arguments that SILGenLValue::visit*MemberRefExpr doesn't need to weed them out anymore. This lets us re-enable some more checks in the expressions and properties tests.

Swift SVN r3572
2012-12-21 02:37:15 +00:00
Joe Groff
f8cd9131b1 SIL: typo in comment
Swift SVN r3571
2012-12-21 02:37:13 +00:00
Joe Groff
860f02b700 SILGen: Remove GenericMemberRef to metatype hack.
Doug fixed the AST representation of type variable metatypes in r3532, so we don't need to check for bugged-out GenericMemberRef-to-metatype nodes anymore.

Swift SVN r3570
2012-12-21 02:37:12 +00:00
Joe Groff
0c0ac932ca SILGen: Update Erasure- and ArchetypeToSuperExpr.
Now that we can represent address-only values, SILGen can correctly generate these operations in terms of archetype/existential addresses instead of impossible values. archetype_to_super is slightly tricky since we can forward ownership from the address-only derived value to the loadable base value, which is normally prevented by the ManagedValue interface, so I wrote some special-case logic directly into visitArchetypeToSuperExpr to handle forwarding the cleanup. Reenable some disabled checks in the expressions test for things that work again.

Swift SVN r3566
2012-12-20 20:18:56 +00:00
Joe Groff
c2f9b197ad SIL: Add DeallocExistentialInst.
Needed to represent deinitializing a partially-initialized existential in which the value witness table has been populated by alloc_existential but the value has not been initialized yet.

Swift SVN r3565
2012-12-20 20:18:54 +00:00
Joe Groff
c8c86010a0 SIL: Update ApplyInst verifier harder.
The result of an address-only returning ApplyInst is going to be empty tuple, not the address-only type. Oops. Rearrange the logic so that it checks that an empty-returning ApplyInst for a non-empty-returning function actually has an address-only indirect return argument.

Swift SVN r3563
2012-12-20 18:31:30 +00:00
Joe Groff
0821ad9104 SILGen: Fix type of global variable accessors.
Emit global accessors as type '() -> [byref] T' instead of '() -> [byref(heap)] T' so that the SIL verifier doesn't stumble on unequal LValueTypes.

Swift SVN r3561
2012-12-20 17:47:31 +00:00
Joe Groff
6d8216b0df SIL: Update Verifier's visitApplyInst.
Update the Verifier for ApplyInsts to take into account indirect arguments and returns.

Swift SVN r3560
2012-12-20 17:47:29 +00:00
Joe Groff
dc5d615a22 SILGen: Implement address-only assignment.
Refactor the assignment implementation a bit so that the FullExpr scope for the assignment lasts long enough that we can pass the ManagedValue from the right-hand side down into the visitor for the left-hand side. A physical assignment of an address-only temporary can take the temporary, but a logical assignment involving a setter call does not, so hand the ManagedValue down through emitAssignToLValue and LValue LogicalComponent::storeRValue so forward-ing can do its thing where appropriate.

Swift SVN r3557
2012-12-20 01:58:19 +00:00
Joe Groff
587537bce1 SILGen: Fix lowering of address-only LValueTypes.
The "loadable" flag was getting set on SILTypes derived from LValueTypes of address-only types. Fix that.

Swift SVN r3556
2012-12-20 01:58:17 +00:00
Joe Groff
2a28e77814 SILGen: Implement calls with address-only arg/ret.
Handle address-only arguments and return values from the caller's end. The callee does not assume ownership of address-only arguments, so don't forward their ManagedValues to the apply. If the return type is address-only, allocate a local temporary, pass the address to the function, then give ownership of the cleanup to a ManagedValue referencing the address.

Swift SVN r3552
2012-12-19 22:35:35 +00:00
Joe Groff
7d8f04ac45 SIL: Make SILType independent of Type.
Move SILType to its own header, and make it its own container type consisting of a Type with an "isAddress" bit for representing address types. Move the "isAddressOnly" information from SILGen's TypeInfo onto SILType as a second bit, because address-only-ness is extremely useful for verification outside of SILGen. Instead of mangling function types during type lowering, rely on the fact that SILType is no longer a Type to force us to mangle argument and return types when we see them. (We may eventually need SILFunctionType and SILTupleType things to represent lowered SIL function and tuple types containing addresses, but for now we can lower function and tuple components as needed.)

Swift SVN r3551
2012-12-19 21:51:39 +00:00
Joe Groff
8d6506f4f0 SILGen: Temporary hack for address-only tuples.
Tuple values are currently abused by SILGen for handling function arguments, and dealing with indirect tuples will complicate that logic. Punt on classifying tuples as address-only till we can fix up function handling logic.

Swift SVN r3549
2012-12-19 21:51:35 +00:00
Joe Groff
dd6977607a SILGen: "Materialize" address-only values.
Address-only values are already in memory, so when we materialize one, just transfer ownership of the value in the buffer from the ManagedValue rvalue to the Materialize temporary lvalue.

Swift SVN r3548
2012-12-19 21:51:32 +00:00
Joe Groff
aab2997273 SIL: Print SIL type when dumping Functions.
Swift SVN r3541
2012-12-19 01:30:25 +00:00
Joe Groff
0d34838a79 SILGen: Handle address-only arguments and returns.
Use copy_addr to copy argument addresses into local boxes and to store to the return value address when working with address-only types. Add a bit to ManagedValue so that it knows when it's referencing an address-only value (as opposed to just an address) so it can require that forwarded address-only values be forwardInto-ed a memory location.

Swift SVN r3540
2012-12-19 01:30:23 +00:00
Joe Groff
6ad32a20c4 SIL: Use SILType and lower types where needed.
Change over SIL Values and Instructions to work in terms of SILTypes, and update SILGen to lower types where needed. Add LValueType logic to SILType lowering to get rid of those annoying lvalue qualifiers so we can ignore RequalifyExprs. Tighten up the XFAILs in the SIL tests and disable the checks that currently crash.

Swift SVN r3538
2012-12-18 23:53:39 +00:00
Joe Groff
dc1af6ae11 SILGen: Implement address-only type lowering.
Add a getLoweredType() method to SILGen's TypeInfo and logic to convert function signatures and address-only types to their SIL-level representations. Drive a (currently weak) type wedge between lowered and unlowered types by making a SILType subclass of CanType. Make SILConstants take on their lowered function types. This breaks a bunch of SIL test cases, which I've temporarily XFAILed until proper address-only type support can propagate through the rest of SILGen.

Swift SVN r3528
2012-12-18 02:29:27 +00:00