Commit Graph

9293 Commits

Author SHA1 Message Date
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
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
4de1cee47d SILGen: Fix GetMetatypeExpr.
Implicit type-to-metatype conversion is not a no-op but should fetch the appropriate metatype.

Swift SVN r3501
2012-12-14 22:02:26 +00:00
Joe Groff
d2030f95ea SILGen: Fix bug with generic member lvalues.
LValue components can't derive their member types from the type decl because a generic type decl has unbound type vars. Get the type for the MemberRef lvalue component from the expr. Add a RequalifyComponent type because we don't fake the right LValueType qualifiers anymore.

Swift SVN r3500
2012-12-14 21:45:25 +00:00
Joe Groff
cad196c432 SILGen: Fix subscript index type is type variable.
When deriving the specialized subscript accessor type from a generic subscript, we can't get the index type from the decl, because its type variables will be unbound. Get the type from the index expression node instead.

Swift SVN r3499
2012-12-14 20:36:53 +00:00
Joe Groff
b2692db978 SILGen: Implement InterpolatedStringLiteralExpr.
Generate InterpolatedStringLiteralExprs by visiting their semantic exprs.

Swift SVN r3498
2012-12-14 19:01:58 +00:00
Joe Groff
704d0caf68 SILGen: Kludge type variable GenericMemberRefExprs
According to John, the AST representation of type variable values, which currently appear as GenericMemberRefExprs on the generic metatype, might be wrong. For now, I'll handle these by emitting metatype instructions on the type variable type, which should work because the method already has a local type variable representing the same variable.

Swift SVN r3497
2012-12-14 18:44:55 +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
9f7b89b1b2 Add a -dump-sil-verbose option.
Since I can't seem to help myself from committing my local debug dumps.

Swift SVN r3495
2012-12-14 18:44:51 +00:00
Joe Groff
99c31002e9 SILGen: Back out debug dumps again. Sorry.
Swift SVN r3494
2012-12-14 17:49:59 +00:00
Joe Groff
e96dc2df65 SILGen: Implement GenericSubscriptExpr.
Subscript accessors of generics also need to be specialized before being applied, like member properties.

Swift SVN r3493
2012-12-14 17:47:45 +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
62e4e71ce8 SILGen: Implement CoerceExpr and DowncastExpr.
Use the new CoerceInst and DowncastInst instructions to handle Coerce and Downcast expressions.

Swift SVN r3491
2012-12-14 02:42:45 +00:00
Joe Groff
b335710fd2 SIL: Add CoerceInst and DowncastInst insns.
Add instructions to represent type coercion and downcast conversion operations. Factor out a common ConversionInst base class for Convert and these instructions, and rename ConvertInst to ImplicitConvertInst to distinguish it from these new explicit conversion instructions.

Swift SVN r3490
2012-12-14 02:13:21 +00:00
Joe Groff
7142b34161 SIL: Make SpecializeInst own its Substitutions.
Have SpecializeInst own its Substitution array so that a SpecializeInst can be instantiated independently of a backing SpecializeExpr in the AST.

Swift SVN r3483
2012-12-13 22:08:45 +00:00
Joe Groff
0401a248ec SIL: Fix typing of generic property accessors.
Getters and setters of generic types have polymorphic function type '<T...> This<T...> -> A -> R', not a bound function type.

Swift SVN r3482
2012-12-13 22:08:43 +00:00
Joe Groff
0aec96e6cd SILGen: Delete debugging dump deluge.
Swift SVN r3481
2012-12-13 19:30:46 +00:00
Joe Groff
6b64e6ca6d SILGen: Implement generic member access.
Add visitors for GenericMemberRefExpr so that accessors to generic physical members with monomorphic types work. Access to members with generic types still requires proper archetype support. Access to logical properties currently breaks because of a bug in the generation of property method types.

Swift SVN r3480
2012-12-13 18:02:47 +00:00
Joe Groff
8a5cf1579e SILGen: Fix Apply(ScalarToTuple) special case.
If a ScalarToTupleExpr is building a multiple-element tuple with default arguments, it's not valid for an apply expression to peek through it to directly generate its argument. Check that a ScalarToTupleExpr result actually has a single element before applying the special case.

Swift SVN r3470
2012-12-13 01:26:36 +00:00
Joe Groff
4325479fc4 SIL: add print() and dump() methods to SILConstant
Expose the static printSILConstant function in SILPrinter.cpp as a method on SILConstant.

Swift SVN r3469
2012-12-13 01:26:34 +00:00
Joe Groff
f4ef00cefa SILGen: Support qualified module paths.
Add a visitor method for DotSyntaxIgnoredBaseExpr so that things like 'Builtin.Int1' and 'swift.true' work.

Swift SVN r3466
2012-12-13 00:37:53 +00:00
Joe Groff
27cbe8f65a SIL: suppress warning in release builds.
Swift SVN r3465
2012-12-13 00:37:50 +00:00
Joe Groff
e182e73c42 SILGen: Fix assign for nontrivial-type properties.
Properties don't need to do the load/retain/store/release dance of physical elements; the setter handles all of that. Rename emitStoreToLValue to emitAssignToLValue, and push the physical reassignment logic into emitAssignToLValue. Dump the old emitAssign since emitAssignToLValue now does everything it used to do. Add a FullExpr scope to the left-hand side of AssignStmts so their temporaries have better-fitting lifetimes.

Swift SVN r3461
2012-12-12 23:57:24 +00:00
Joe Groff
6dce1c9b5f SILGen: Let any reftype expression root an lvalue.
In the SILGenLValue visitor, stop when we see a subexpression that has a reference type and use the result of that expression to root the lvalue expression. This allows rvalue reference type expressions like `foo().bar = bas` to work.

Swift SVN r3460
2012-12-12 23:57:22 +00:00
Joe Groff
b3fe45bf5f SILGen: Consume materializes used for writeback.
Split CleanupMaterialize into CleanupMaterializeAlloc and CleanupMaterializeValue. Have emitMaterialize, emitGetProperty, and other methods that create materialize buffers return a new Materialize type, which has a consume() method to disable the CleanupMaterializeValue cleanup, load the value, and return it as a ManagedValue for the caller to consume.

Swift SVN r3458
2012-12-12 22:26:42 +00:00
Joe Groff
220adf7b74 SILGen: Retain reftype property arg in lvalue.
When calling a property accessor as part of a logical lvalue chain, retain the this argument if it is of a reference type.

Swift SVN r3457
2012-12-12 22:26:40 +00:00
Joe Groff
fb99320134 SILGen: Don't load trivial materializes on cleanup
emitReleaseRValue is smart enough to do nothing with trivial types, but a useless load instruction was still being generated for cleaning up materializes. Don't do that.

Swift SVN r3455
2012-12-12 22:26:36 +00:00
Joe Groff
5bc7a0169d SILGen: Implement setting subscripts.
Fix up GetterSetterComponent's logic for applying subscript arguments, and wire up SILGenLValue to handle SubscriptExprs.

Swift SVN r3453
2012-12-12 20:23:59 +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
eeaa120fa7 SILGen: Visit methods in types.
Generate SIL for methods inside NominalTypeDecls.

Swift SVN r3449
2012-12-12 17:42:17 +00:00
Dave Zarzycki
8ade2edcd5 Fix a build warning in release builds
Swift SVN r3447
2012-12-12 16:25:00 +00:00
Joe Groff
ec86ae9d0e SILGen: Implement reftype elements and properties.
Generalize a bunch of code that assumed address-of-value-type for the "this" side of properties to accept reftypes as well. Use RefElementAddrInst to extract physical elements of reference types. Fix an off-by-one in the writeback logic in emitStoreToLValue so that writeback chains properly terminate at the deepest value type component below a reference type component.

Swift SVN r3445
2012-12-12 01:04:31 +00:00
Joe Groff
13bb47d070 SIL: Add RefElementAddrInst instruction.
Like ElementAddrInst for reference type instances. Takes an rvalue reference type and gives the address of an element in the instance.

Swift SVN r3444
2012-12-12 01:04:30 +00:00
Joe Groff
87979299bf SILGen: Small writeback bug.
Any reference type component of a logical lvalue resets the writeback chain, not just a logical reference type component.

Swift SVN r3443
2012-12-12 01:04:27 +00:00
Joe Groff
44497bf9a3 SILGen: Handle byref arguments as logical lvalues.
Visit ApplyExpr arguments with SILGenLValue. If the resulting path is purely physical, pass it through to the function. If the path has logical components, materialize the logical property and write it back after applying the function.

Swift SVN r3441
2012-12-11 19:19:39 +00:00
Joe Groff
0f3414480e SILBuilder: r/r of constant_ref is a no-op.
Retaining or releasing a constant_ref can be trivially elided in SILBuilder.

Swift SVN r3440
2012-12-11 18:23:08 +00:00
Joe Groff
60545db43d SILGen: Fixed leaked retain of lvalue get/set.
SILGenFunction::emitConstantRef was returning a retained reference to local closures, but SILGenLValue saves off the reference and retains it as needed, leading to an extra retain that was never cleaned up. Add a SILGenFunction::emitUnmanagedConstantRef that returns a local or global constant value without retaining a local constant.

Swift SVN r3439
2012-12-11 18:23:06 +00:00
Joe Groff
a99c4551d3 SILGen: Implement logical lvalues.
Steal the 'LValue' type from irgen, which describes a logical lvalue as a path through physical and logical accessor expressions, such as member ref, tuple element, and subscript operations. Implement a SILGenLValue visitor that builds logical lvalues for lvalue contexts. Implement assignment using SILGenLValue to visit the left-hand side of assignment statements. Still to be implemented: subscript expressions and byref function arguments.

Swift SVN r3437
2012-12-11 01:53:46 +00:00