Commit Graph

9332 Commits

Author SHA1 Message Date
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
Joe Groff
46c4bd45e9 SILGen: Handle capture of local properties.
Add GetterSetter and Getter capture modes that capture the getter and/or setter closures when a local property is closed over.

Swift SVN r3418
2012-12-08 00:47:45 +00:00
Joe Groff
c16fa57e69 SILGen: Handle getting local properties.
Build closures for local getter and setter decls, and load the get closure when the property is referenced in a normal expression context.

Swift SVN r3417
2012-12-08 00:47:43 +00:00
Joe Groff
e0b9794941 Fix some comments.
Swift SVN r3415
2012-12-07 23:24:19 +00:00
Joe Groff
26344c7728 SILGen: Implement getting properties.
- Steal some bits from SILConstant::id to reference getter and setter definitions, and normalize SILConstant references to property FuncDecls to be SILConstant references to the ValueDecl getter/setter instead.
- In normal expression context, handle getting properties by calling the getter and materializing the return value. Setting lvalues is not implemented yet; that will require borrowing the LValue and GenLValue machinery from irgen to construct logical lvalue paths in assignment and byref contexts.

Swift SVN r3414
2012-12-07 23:24:15 +00:00
Joe Groff
dc43d34e39 SILGen: Support MemberRefExpr on loadable structs.
Have TypeConverter generate a field-to-index mapping for physical fields of loadable structs.
Use the resulting TypeInfo mapping to generate element_addrs for physical MemberRefExprs, borrowing the logic from TupleElementExpr.

Swift SVN r3406
2012-12-07 18:28:24 +00:00
Joe Groff
9ea984ca02 SILGen: Fix a bug in destructuring assignment.
The type of an Extract from the right-hand side is an rvalue type, not the lvalue type of the corresponding tuple assignment destination.

Swift SVN r3394
2012-12-07 01:29:43 +00:00
Joe Groff
374aff6632 SILGen: Use ElementAddr for lvalue TupleElements.
If the operand of a TupleElementExpr is an lvalue, derive the address of the element from the operand rather than try to extract a value from it as the code was doing before.

Swift SVN r3392
2012-12-07 00:37:31 +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
752da923e0 SILGen: Move Explosion.h to ManagedValue.h
Rename the header and remove the "Explosion" class from it since we didn't end up using it.

Swift SVN r3390
2012-12-07 00:37:28 +00:00
Joe Groff
0b825c421b SILGen: Treat global vars as accessor functions.
Instead of considering `constant_ref @var` to give the address of `var` directly, consider it to be a `() -> [byref] T` function that returns the address, presumably after running the initializer for the global if necessary. Generate a DeclRef to a global var as a constant_ref to get the function followed by an apply to get the address. Actually generating the global accessor is still to be implemented.

Swift SVN r3389
2012-12-07 00:37:26 +00:00
Joe Groff
370f3b1b94 SILGen: Prepare emitFunction to handle curries.
Change the signature of emitFunction to take just a decl (and leave it up to the implementation to create the SILConstant) because emitFunction may produce functions for multiple SILConstants from a single FuncExpr.

Swift SVN r3388
2012-12-07 00:37:25 +00:00