Commit Graph

315 Commits

Author SHA1 Message Date
Joe Groff
7934842505 SILGen: Handle globals in top-level code.
In top-level code, global variables are notionally local variables of the "main" function, but we give them global storage as an implementation detail. Add the ability to represent physical global variables to SILConstant, and emit top-level-code global variable initializers and references in terms of the physical address.

Swift SVN r4479
2013-03-22 21:58:33 +00:00
Joe Groff
557100aefc SILGen: Keep [thin] through FunctionConversionExpr
FunctionConversionExpr was converting the type of SIL values to thick function types without emitting SIL to create the dummy context, which was confusing IRGen.

Swift SVN r4476
2013-03-22 19:09:26 +00:00
Joe Groff
ed6f218836 SIL: "Thicken" function refs when necessary.
Swift doesn't yet type-check function thinness, so variables, arguments, and return values are always thick. When we store, pass as argument, or return a function value that SIL tracks as thin, emit a new 'thin_to_thick_function' instruction to represent converting the type to the thick type and adding a null context pointer.

Swift SVN r4470
2013-03-21 23:44:01 +00:00
John McCall
1a8d624b6c Rename the SIL 'closure' instruction to 'partial_apply'.
Swift SVN r4468
2013-03-21 21:59:28 +00:00
Joe Groff
e07609c3e7 SIL: Add ClassMetatypeInst.
Represents getting the dynamic metatype from a class instance.

Swift SVN r4459
2013-03-20 23:27:18 +00:00
Joe Groff
c090f65a06 IRGen: Update lowering for SIL protocol_method.
Swift SVN r4456
2013-03-20 20:48:16 +00:00
Joe Groff
35fb03afc2 SILGen: Adopt thin function types.
Emit constant_refs as having thin function type and introduce context with closure instructions. Add checks to the verifier that function reference operations act on the right level of thinness.

Swift SVN r4432
2013-03-18 22:20:23 +00:00
Joe Groff
9da0f893e5 SIL: Add address_to_pointer instruction.
Make converting a SIL address to a Builtin.RawPointer its own instruction separate from implicit_convert, which will let me get rid of a goofy edge case in IRGenSIL.

Swift SVN r4412
2013-03-18 03:14:24 +00:00
Joe Groff
f3bf84c12f SILGen: Fix generic method of nongeneric class.
Properly emit a SpecializeInst for an uncurried call to a generic method of a nongeneric class, where there are only generic parameters on the second uncurry level and the outermost function type appears monomorphic.

Swift SVN r4410
2013-03-17 18:39:11 +00:00
Joe Groff
b53d7a2344 SILGen: Catch up with new Expr nodes.
Add SILGen support for recently-added super.constructor and collection literal expr nodes. Remove the default visitExpr hack and add stubs for the handful of expr nodes remaining to implement.

Swift SVN r4406
2013-03-16 20:28:49 +00:00
Joe Groff
460ba9e61f SILGen: Fix some constructor issues.
Update value type constructor generation to go back to left-to-right uncurried argument emission. Fix the uncurry level of specializations generated during constructor/destructor emission. Update the 'lifetime' test.

Swift SVN r4386
2013-03-15 20:43:58 +00:00
Joe Groff
b2c1a83433 SILGen: Uncurry function applications.
Reference and call uncurried function applications when appropriate to the call site, following the same logic implemented in CallEmission/CalleeSource in IRGen. Add ClassMethodInst and SuperMethodInst instructions to represent method and super dispatch. Change how closures and ClosureInst are represented in SIL so that closures are functions with an extra implicit uncurry level and so that ClosureInst applies the outer uncurries of an uncurried function type to give a curried type as a result. This breaks...pretty much everything else SIL-dependent; I'll clean it up next.

Swift SVN r4368
2013-03-14 01:27:54 +00:00
Joe Groff
0db00816cd SIL: Replace ZeroAddr/ZeroValue with InitializeVar
Rename 'ZeroAddr' to 'InitializeVar' and remove ZeroValue since only things with memory locations should ever be in a 'default-initialize' state. Add a ModuleInst so we don't need to use ZeroValue as a hack to represent ModuleExpr values.

Swift SVN r4319
2013-03-07 18:38:25 +00:00
Joe Groff
2ccfbdcf1a SIL: Add an UpcastExistentialInst.
Converting from a protocol type to a more general protocol type is different at the implementation level from converting a concrete type to a protocol type, since the witness tables and concrete value can be copied directly from the original existential container to the new without adding another indirection. This instruction represents that operation.

Swift SVN r3887
2013-01-28 20:02:52 +00:00
Joe Groff
8b1c38bfbd SIL: Add an 'upcast' instruction.
Upcasting isn't quite a no-op like the other implicit conversions because the underlying pointer type still needs to be bitcast. The additional semantic information will be useful for SIL consumers as well.

Swift SVN r3872
2013-01-26 00:49:47 +00:00
Joe Groff
9e971afadd SILGen: Make initializing ctors return this back.
John recommended this because it has a number of benefits:
- It avoids a retain/release cycle, because 'this' can be passed to the initializer at +1 and just received back at +1.
- The allocating constructor can thus tail call the initializing constructor.
- If we end up needing to support rogue ObjC initializers that change self, we're set up to do so.

Swift SVN r3836
2013-01-22 23:36:32 +00:00
Joe Groff
b7c03623a8 SIL: Properly type closure constants and insns.
I was being lazy by not mangling the context arguments onto the types of closure SIL constants and then having ClosureInst pass the type of its callee through T -> T. Now closure functions get emitted with the right types, ClosureInst properly partially applies the type, and the SIL Verifier properly checks that the argument types all line up correctly.

Swift SVN r3815
2013-01-20 19:50:04 +00:00
Joe Groff
0422897a47 Expose %swift.opaque as a builtin type.
Archetypes and projected existentials have the type %swift.opaque* and not i8*, so I need a corresponding SIL type to be able to model the ProjectExistential operation. We might also end up needing the builtin type for other low-level things down the line.

Swift SVN r3793
2013-01-18 02:24:23 +00:00
Joe Groff
521b9376eb SIL: Make RefElement take VarDecl instead of index
This is inconsistent with ElementAddr and Extract, but allows all the hairy logic of accessing class fields in IRGen to stand without a bunch of pointless refactoring.

Swift SVN r3778
2013-01-16 22:12:17 +00:00
Dave Zarzycki
ed5de91828 Fix build warnings
Swift SVN r3749
2013-01-11 18:58:44 +00:00
Joe Groff
b4c1ea890b SILGen: Recursively destructure tuple arguments.
Fully and consistently destructure tuples when in a function argument context, and require that ApplyInst always take destructured arguments corresponding to the lowered argument types as its inputs. This eliminates a ton of finicky special-case code all over the place and also has the nice fringe benefit of avoiding a bunch of useless TupleInsts that were being emitted before. Currently this breaks variadic tuple fields and argument writeback. I'll fix variadic tuple fields soon. The argument writeback sucked anyway and I'll do it right later.

Swift SVN r3730
2013-01-10 03:45:45 +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
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
Dave Zarzycki
4f311202a6 Fix a build warning in Release builds
Swift SVN r3646
2013-01-02 21:52:38 +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
c8d7cd1bcc SIL: Clean up some stray dumps.
Swift SVN r3591
2012-12-22 01:10:50 +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
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
21dcefd4f1 SIL: Add DeallocRefInst.
Needed to represent deallocating an uninitialized box.

Swift SVN r3573
2012-12-21 02:37:17 +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
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
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
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
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
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
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
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
Joe Groff
6b7405e602 SILGen: Fix associated types in archetype methods.
Pass down the AST type from the ArchetypeMemberRefExpr, which has the right locally-bound archetypes, rather than derive the method type from the decl.

Swift SVN r3504
2012-12-15 00:11:29 +00:00
Joe Groff
92a5e69293 SILGen: Implement archetype method references.
Use ArchetypeMethodInst to implement ArchetypeMemberRefExprs that reference methods. Properties are not yet handled. Fix up ArchetypeInst implementation a bit to substitute the "This" type in the method type and to accept archetype-metatypes in addition to archetype addresses.

Swift SVN r3503
2012-12-14 23:56:34 +00:00
Joe Groff
5d405e5ecd SIL: Add ArchetypeMethodInst.
Add an instruction to get a method implementation from an archetype's protocol witness table.

Swift SVN r3502
2012-12-14 23:56:32 +00:00
Joe Groff
9474a81f0b SIL: Generalize MetatypeInst.
Allow MetatypeInst to be constructed with any expr of metatype type, not just MetatypeExpr nodes.

Swift SVN r3496
2012-12-14 18:44:53 +00:00
Joe Groff
3e14d9782a SILGen: Specialize generic property accessors.
Generic accessors need to have a specialize instruction applied to them to get the concrete accessor before applying them.

Swift SVN r3492
2012-12-14 16:51:59 +00:00
Joe Groff
27cbe8f65a SIL: suppress warning in release builds.
Swift SVN r3465
2012-12-13 00:37:50 +00:00
Joe Groff
d3d617ca70 SILGen: Implement getting subscripts.
Subscripts are just another kind of property. Refactor some logic from ApplyExpr codegen to visit index arguments consistently with apply arguments. Also move the logic for determining SIL constant types onto SILModule because it's too hairy to calculate on the fly.

Swift SVN r3452
2012-12-12 20:23:56 +00:00
Joe Groff
6a67ad7e12 SIL: Add ElementAddrInst.
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
2012-12-07 00:37:29 +00:00
Joe Groff
a593076d09 SIL: Introduce a SILConstant type.
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
2012-12-05 22:40:38 +00:00