Commit Graph

9332 Commits

Author SHA1 Message Date
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
Joe Groff
601f1d3c4d SIL: Move SILModule::getConstantType to TypeInfo.
Determining constant types requires help from SILGen because of address-only types, and the type of a constant after SILGen should always be readily available from the ConstantRefInst. Initialize SIL Function objects with their lowered type as well so that it's available to IRGen and SIL passes.

Swift SVN r3526
2012-12-17 20:27:46 +00:00
Dave Zarzycki
113faab6f6 Fix warning during RELEASE builds and fix -Wnewline-eof bugs
We really ought to enable: -Wnewline-eof

Swift SVN r3522
2012-12-17 17:59:52 +00:00
Joe Groff
90b3f319c7 SILGen: implement ArchetypeToSuperExpr.
Add an ArchetypeToSuperInst to represent archetype-to-base-constraint-type conversions. Use it to emit ArchetypeToSuperExprs.

Swift SVN r3521
2012-12-17 17:52:27 +00:00
Joe Groff
edbc00bcc8 SILGen: Implement MetatypeConversionExpr.
Handle MetatypeConversionExpr by emitting a MetatypeInst for the destination metatype.

Swift SVN r3520
2012-12-17 17:24:46 +00:00
Joe Groff
dd715119f6 SILGen: Make DeclRef of metatype emit MetatypeInst
If a DeclRef references a metatype, it should emit a MetatypeInst instead of a ConstantRefInst.

Swift SVN r3519
2012-12-17 17:16:09 +00:00
Joe Groff
1fa8ac05a0 SILGen: Implement DerivedToBaseExpr.
Represent it as an implicit_convert instruction since it has no runtime representation effect. Factor out the common implicit conversion code among the other ImplicitConversionExpr subtypes.

Swift SVN r3510
2012-12-15 02:15:57 +00:00
Joe Groff
45c675da24 SILGen: Half-implement ErasureExprs.
Proper handling of existentials requires address-only types. For now, we can implement proper initialization of an existential in memory then "load" it as a hack so we can move on with other nodes.

Swift SVN r3509
2012-12-15 02:15:56 +00:00
Joe Groff
03dd05ca07 SIL: Add ProjectExistential and AllocExistential.
ProjectExistential derives the value pointer from an existential, and AllocExistential initializes an existential's witness tables and allocates its value. Tweak SILGen's handling of ExistentialMemberRefExprs to emit a project_existential between querying the method and applying it.

Swift SVN r3508
2012-12-15 02:15:54 +00:00
Joe Groff
59fb775cd0 SILGen: Implement existential method references.
Handle ExistentialMemberRef for methods by emitting ExistentialMethodInst, similar to ArchetypeMemberRef. Properties still need to be implemented.

Swift SVN r3507
2012-12-15 02:15:53 +00:00
Joe Groff
6d77ef4041 SIL: Add ExistentialMethodInst.
Like ArchetypeMethodInst for existential types. Factor out a common WitnessTableMethodInst for both insns.

Swift SVN r3506
2012-12-15 02:15:51 +00:00
Joe Groff
112d0e1282 SIL: Clean up extra dumps in verifier.
Swift SVN r3505
2012-12-15 00:11:31 +00:00