Commit Graph

785 Commits

Author SHA1 Message Date
Jordan Rose
132a29eb67 Remove unnecessary wrapper type GenericParam.
This always wrapped a single GenericTypeParamDecl *, and provided no benefit
over just using the decl directly.

No (intended) functionality change.

Swift SVN r19628
2014-07-07 20:51:50 +00:00
John McCall
ace9e8e406 Allow cleanups to declare that they should not be
completely destroyed when forwarded.

Also, make forwarding a cleanup a first-class operation
on cleanups, rather than setting the cleanup state directly.

Swift SVN r19332
2014-06-30 11:55:24 +00:00
Joe Groff
9a190ea59e AST: Remove unneeded expression nodes for __inout_conversion and __writeback_conversion.
We no longer need this language feature. The Sema support is still skeletally kept in place because removing it seems to totally break pointer conversions; I need to work with Joe and Doug to figure out why that's the case.

Swift SVN r19289
2014-06-27 04:23:35 +00:00
Joe Groff
0db8de1341 SILGen: Implement inout-to-pointer conversion.
For writeback through an AutoreleasingUnsafePointer, create an intrinsic AutoreleasingWritebackComponent we can append to lvalues.

Swift SVN r19134
2014-06-24 15:11:41 +00:00
John McCall
48d6a833a5 SILGen unconditional dynamic casts using the new
unconditional_dynamic_cast_addr instruction.

Also, fix some major semantic problems with the
existing specialization of unconditional dynamic
casts by handling optional types and being much
more conservative about deciding that a cast is
infeasible.

This commit regresses specialization slightly by
failing to turn indirect dynamic casts into scalar
ones when possible; we can fix that easily enough
in a follow-up.

Swift SVN r19044
2014-06-20 07:47:03 +00:00
Joe Groff
ef52068e43 SILGen: Don't +1 'self' references for direct property access in constructors.
The CALayer brittleness in <rdar://problem/17014037> is worse than we thought—we can't r/r *at all* before super.init. Go through some contortions to ensure that, when doing direct stored property access in an initializer, we always base off of a +0 value. I tried fixing this in a more general and principled way using SGFContext::AllowPlusZero, but that introduced miscompiles we don't have the luxury of tracking down right now, so hack a more targeted fix that only affects class initializers.

Swift SVN r18635
2014-05-26 18:09:25 +00:00
Joe Groff
0141da1107 SILGen: Attach an OwnershipComponent to weak/unowned member references.
Partially fixes <rdar://problem/16989616>, but exposes an IRGen crash (which is likely <rdar://problem/16979789>) behind it.

Swift SVN r18585
2014-05-23 04:20:25 +00:00
Chris Lattner
d4280cf27c remove the old functions that SILGen's huge blobs of code to form/decompose
optionals for weak pointers.  This eliminates the need to do rdar://16871379,
and moves rdar://14921511 forward a bit more.



Swift SVN r18315
2014-05-18 05:03:08 +00:00
Chris Lattner
6d84785e52 Substantially rework how weak pointers are represented in the AST and
at the SIL level.  Now, the referent type of a WeakStorageType is always
an optional type, instead of always being the underlying reference.  This
allows us to represent both optional types.  Before, both of these had the
same AST representation of WeakStorageType(T):

  weak var x : T?
  weak var x : T!

which doesn't work.  Now we represent the optional type explicitly in the
AST and at SIL level.  This also significantly simplifies a bunch of code
that was ripping off the optional type and resynthesizing it in other places,
and makes SILGen of weak pointers much more straight-forward by eliminating
the need for emitRefToOptional and emitOptionalToRef entirely (see the diffs
in test/SILGen/weak).

Weak pointers still have problems, but this is a big step forward.


Swift SVN r18312
2014-05-18 04:53:35 +00:00
Chris Lattner
feddbc1844 fix <rdar://problem/16880044> unowned let properties don't work as struct and class members
Swift SVN r17934
2014-05-12 15:42:12 +00:00
Chris Lattner
e2e36f2832 rework OwnershipComponent: instead of being the root of an lvalue, make it be
an interior node that remaps the weak/unowned storage representation to its
strong rvalue representation.  This allows it to chain on top of ValueComponent
and other memory-addressing things.  NFC.


Swift SVN r17931
2014-05-12 15:07:10 +00:00
Chris Lattner
38a16df992 fix <rdar://problem/16880240> SILGen crash assigning to _
Swift SVN r17913
2014-05-12 01:50:57 +00:00
Chris Lattner
f8ce2a3a87 Fix <rdar://problem/16871284> silgen crashes on weak capture
This reworks handling of weak/unowned values to represent them as logical 
lvalues instead of as physical lvalues.  Representing them as physical
lvalues breaks a lot of assumptions throughout silgen because (while they
have the same in-memory representation) weak pointers and optional have
different dynamic behavior.

This will hopefully make weak pointers generally more reliable than they
have been.  One causualty of this is that the "copy_addr" peephole is defeated
for the case that you copy a weak lvalue to another weak lvalue, but correctness
needs to win, and this can be added back later when it becomes a priority.



Swift SVN r17842
2014-05-10 20:31:01 +00:00
Chris Lattner
8aa65c027e teach the AST walker to walk into the capture list of closure exprs, teach the
type checker to type check them, tweak the ast dumper to dump out something nicer.



Swift SVN r17832
2014-05-10 19:17:13 +00:00
John McCall
b38a63950d Implement @unowned(unsafe).
This was part of the original weak design that
there was never any particular reason to rush the
implementation for.  It's convenient to do this now
so that we can use it to implement Unmanaged<T> for
importing CF types.

Swift SVN r16693
2014-04-23 08:51:23 +00:00
Joe Groff
8adaab0233 Fold ExtInfo::isThin and ::isBlock into a "Representation" enum.
These bits are orthogonal to each other, so combine them into one, and diagnose attempts to produce a type that's both. Spot-fix a bunch of places this revealed by inspection that we would have crashed in SILGen or IRGen if blocks were be handled.

Swift SVN r16088
2014-04-09 00:37:26 +00:00
Joe Groff
ea492e7ca4 SILGen: Only reabstract physical lvalues with real abstraction differences.
Check that a physical lvalue's lowered type is actually different from what we get if we load the lvalue before introducing a reabstraction writeback. Fixes <rdar://problem/16530674>.

Swift SVN r15970
2014-04-05 01:13:59 +00:00
Chris Lattner
f6e87dec54 Rework SILGen's emission of release_value to have it auto-merge into
retain_value instructions, just like we do for strong_retain/release.

This wraps up rdar://15889208, which is admittedly more of a moral 
victory than a practical one.


Swift SVN r15804
2014-04-02 16:39:53 +00:00
Chris Lattner
afea47b621 rename "destroy_value" to "release_value", part of rdar://15889208.
Swift SVN r15777
2014-04-02 05:33:52 +00:00
Joe Groff
ba34976f87 SILGen: Implement lowering for writeback conversion.
Lower LValueConversionExprs to LValueConversionComponents of SILGen's LValues, which add the conversion pair as a logical component of a writeback chain.

Swift SVN r15771
2014-04-02 03:15:12 +00:00
Joe Groff
8f1c2d1e79 Sema: Implement type-checking for inout writeback conversion.
Add a third branch to the constraint system for '&x' expressions that allows conversion from an lvalue to a type via an additional writeback step:

- Add an LValueConversionExpr node that converts from @lvalue T to @lvalue U, given a pair of functions that convert T -> U and U -> T, to represent the writeback temporary.
- Allow conversion in an inout expression from @lvalue T to a type U that has the following members:

  static func __writeback_conversion(Builtin.RawPointer, T.Type) -> U
  static func __writeback_conversion_get(T) -> V
  static func __writeback_conversion_set(V) -> T

which builds a solution that produces an LValueConversion from the get/set pair before passing the pointer to the writeback temporary off to the conversion function.

Swift SVN r15764
2014-04-02 00:17:51 +00:00
Joe Groff
b3e9a17269 SILGen: Implement inout address conversion.
Implement lowering for the LValueToPointer and InOutConversion expressions. For the former, we emit the lvalue, then convert it to a RawPointer; for the latter, we introduce an InOutConversion scope, which suppresses any nested writeback conversion scopes.

This completes the implementation of inout address conversion, except that we don't implement reabstraction of the lvalue prior to taking its address. Simply report them unimplemented for now, since reabstraction should not come up for our immediate use case with C types.

Swift SVN r15595
2014-03-29 02:50:26 +00:00
Joe Groff
45eadd1d9b Rename AddressOfExpr to InOutExpr.
The "address" is an implementation detail; formally, it turns an lvalue into an inout parameter.

Swift SVN r15458
2014-03-25 16:28:28 +00:00
Chris Lattner
13e06548cf Fix <rdar://problem/16411449> ownership qualifiers don't work with non-mutating struct property
Swift SVN r15429
2014-03-25 00:17:47 +00:00
Chris Lattner
3392c4e8ab remove ArchetypeSubscriptExpr, since it is dead now.
Swift SVN r14284
2014-02-23 08:04:51 +00:00
Chris Lattner
a121e9798e implement support for property references on archetypes, implementing rdar://14195801
Swift SVN r14282
2014-02-23 08:02:22 +00:00
Chris Lattner
728a865904 change Sema to form vardecl member references in protocols as MemberRefExpr instead of
ExistentialMemberRefExpr, and enhance silgen to avoid unnecessary copies of protocol
and archetype bases.   With this, uses of properties in protocols start to work.


Swift SVN r14270
2014-02-22 20:52:11 +00:00
Chris Lattner
380e44c615 remove ExistentialSubscriptExpr. We don't need specialized forms of
subscriptexpr for various base types, for the same reason we don't need
multiple different kinds of MemberRefExpr.


Swift SVN r14268
2014-02-22 20:18:02 +00:00
Chris Lattner
936cf62925 implement support for getting and setting subscripts on lvalues.
Swift SVN r14266
2014-02-22 20:00:15 +00:00
Chris Lattner
a61e32008c stub out missing lvalue handling for subscripts on protocols and archetypes
Swift SVN r14083
2014-02-19 15:57:53 +00:00
Chris Lattner
09e49dc2d8 strength reduce SILGen's representation of indexes from being
RValueSource's to RValues.  SILGen doesn't need the generality
of RValueSource.  NFC.


Swift SVN r14015
2014-02-17 23:41:32 +00:00
Chris Lattner
48759e2ae1 strength reduce SILGen's handling of the "value" argument when calling
a setter to use an RValue instead of RValueSource.  NFC.


Swift SVN r14013
2014-02-17 23:35:02 +00:00
Joe Groff
b19cfb27ea Drop the context generic params from SILFunctionType.
SILFunctionType is now 100% context free!

Swift SVN r13775
2014-02-11 04:21:20 +00:00
Joe Groff
481fbb7b91 Drop the non-interface types from SILFunctionType.
There are some straggling references to the context generic param list, but nothing uses the non-interface param or result types anymore!

Swift SVN r13725
2014-02-09 22:39:01 +00:00
Chris Lattner
d690a63a87 progress towards non-member observing properties:
- Add a "isDirectPropertyAccess" bit to DeclRefExpr, serving the 
   same purpose as MemberRefExprs for non-member properties.
 - Teach sema to synthesize correct non-member get/set implementations
   for observing properties.
 - Teach silgen to handle the isDirectPropertyAccess bit.



Swift SVN r13600
2014-02-06 22:34:37 +00:00
Chris Lattner
595817bd89 Rename data structures relating to WillSetDidSet properties to call them "Observing"
properties internally to the compiler.  NFC.


Swift SVN r13587
2014-02-06 17:51:45 +00:00
Doug Gregor
f1be1ed572 Implement super mesage sends for @objc property and subscript getters/setters.
Fixes <rdar://problem/15933008>.


Swift SVN r13100
2014-01-29 07:45:53 +00:00
Chris Lattner
eb66701757 simplify code now that AbstractStorageDecl unifies VarDecl and SubscriptDecl.
Swift SVN r13020
2014-01-28 00:39:20 +00:00
Chris Lattner
e668e86cc3 With many prerequisites out of the way, lets start actually working on didset/willset
properties.  This step provides AST support to model them.


Swift SVN r13011
2014-01-27 22:11:16 +00:00
Chris Lattner
2792e55be4 remove the -enable-new-objc-properties staging option, and
simplify some code.


Swift SVN r12976
2014-01-26 23:24:35 +00:00
Chris Lattner
ddc5ca81d6 Fix <rdar://problem/15858869> *all* objc accessors disabled in init methods, not just for self
This patch: 
 - Changes sema to set the "IsDirectPropertyAccess" on MemberRefExprs
   in inits/destructors that should be done directly because they are
   on the local object.
 - Removes the "SGF.AlwaysDirectStoredPropertyAccess" bool in SILGen,
   which was the source of the problem above and was otherwise problematic.

This will get a bit simpler when -enable-new-objc-properties rolls out. 


Swift SVN r12967
2014-01-26 07:23:42 +00:00
Chris Lattner
0dfb1ec790 introduce a new "IsDirectIVarAccess" bit to MemberRefExpr. Properties
that have both storage AND accessors are accessed by-default through
their accessors.  This bit indicates that a specific MRE should access
the storage instead.

Use this new bit in the synthesized getter/setter for "StorageObjC"
properties (it will also be used for other things in the future).
This also teaches SILGen about it.

One interesting aspect of this representation is that it makes it trivial
to add some expression syntax for directly accessing a store+computed 
property (e.g. ObjC properties, also someday didSet/willSet properties) 
someday if we care.  This would be analogous to the "self->ivar" syntax
in objc (vs self.ivar).  No, we will not use "->" for this. :-)

NFC since this is the use is still hidden under the -enable-new-objc-properties
staging option.



Swift SVN r12965
2014-01-26 06:08:53 +00:00
Chris Lattner
91fb51100d Introduce a new kind of StorageDecl called StoredObjC. These are
properties that are (usually) accessed through getters and setters, but
which have storage.  Nothing generates these yet.


Swift SVN r12902
2014-01-24 05:15:11 +00:00
Chris Lattner
690e8a38af switch places the ignore the result of an rvalue to allow it to be +0. No
impact on stdlib or testsuite.


Swift SVN r12879
2014-01-23 22:06:21 +00:00
Chris Lattner
c6a334ab6e teach SILGenFunction::emitLoad that clients allowing +0 results don't
need the load (and temporary, and cleanup) to actually be emitted for
address-only operands.  They can just use the physical lvalue as the +0 base.

In this example:
struct GenericStruct<T> {
  var a : T
  var b : Int

  func getA() -> T {
    return a
  }

  func getB() -> Int {
    return b
  }
}

we used to produce:

sil @_TFV2t213GenericStruct4getAU__fGS0_Q__FT_Q_ : $@cc(method) @thin <$T_0_0> (@out $T_0_0, @in GenericStruct<$T_0_0>) -> () {
bb0(%0 : $*T, %1 : $*GenericStruct<T>):
  debug_value_addr %1 : $*GenericStruct<T>  // let self // id: %2
  %3 = alloc_stack $GenericStruct<T>              // users: %8, %7, %5, %4
  copy_addr %1 to [initialization] %3#1 : $*GenericStruct<T> // id: %4
  %5 = struct_element_addr %3#1 : $*GenericStruct<T>, #a // user: %6
  copy_addr %5 to [initialization] %0 : $*T       // id: %6
  destroy_addr %3#1 : $*GenericStruct<T>          // id: %7
  dealloc_stack %3#0 : $*@local_storage GenericStruct<T> // id: %8
  destroy_addr %1 : $*GenericStruct<T>            // id: %9
  %10 = tuple ()                                  // user: %11
  return %10 : $()                                // id: %11
}

sil @_TFV2t213GenericStruct4getBU__fGS0_Q__FT_Si : $@cc(method) @thin <$T_0_0> (@in GenericStruct<$T_0_0>) -> Int64 {
bb0(%0 : $*GenericStruct<T>):
  debug_value_addr %0 : $*GenericStruct<T>  // let self // id: %1
  %2 = alloc_stack $GenericStruct<T>              // users: %7, %6, %4, %3
  copy_addr %0 to [initialization] %2#1 : $*GenericStruct<T> // id: %3
  %4 = struct_element_addr %2#1 : $*GenericStruct<T>, #b // user: %5
  %5 = load %4 : $*Int64                          // user: %9
  destroy_addr %2#1 : $*GenericStruct<T>          // id: %6
  dealloc_stack %2#0 : $*@local_storage GenericStruct<T> // id: %7
  destroy_addr %0 : $*GenericStruct<T>            // id: %8
  return %5 : $Int64                              // id: %9
}

now we produce:

sil @_TFV2t213GenericStruct4getAU__fGS0_Q__FT_Q_ : $@cc(method) @thin <$T_0_0> (@out $T_0_0, @in GenericStruct<$T_0_0>) -> () {
bb0(%0 : $*T, %1 : $*GenericStruct<T>):
  debug_value_addr %1 : $*GenericStruct<T>  // let self // id: %2
  %3 = struct_element_addr %1 : $*GenericStruct<T>, #a // user: %4
  copy_addr %3 to [initialization] %0 : $*T       // id: %4
  destroy_addr %1 : $*GenericStruct<T>            // id: %5
  %6 = tuple ()                                   // user: %7
  return %6 : $()                                 // id: %7
}

sil @_TFV2t213GenericStruct4getBU__fGS0_Q__FT_Si : $@cc(method) @thin <$T_0_0> (@in GenericStruct<$T_0_0>) -> Int64 {
bb0(%0 : $*GenericStruct<T>):
  debug_value_addr %0 : $*GenericStruct<T>  // let self // id: %1
  %2 = struct_element_addr %0 : $*GenericStruct<T>, #b // user: %3
  %3 = load %2 : $*Int64                          // user: %5
  destroy_addr %0 : $*GenericStruct<T>            // id: %4
  return %3 : $Int64                              // id: %5
}

This cuts about 120 lines out of the stdlib (so, about 40 temporaries).


Swift SVN r12871
2014-01-23 19:44:43 +00:00
Chris Lattner
2cf6d814c7 more tidying:
- Strength reduce the interface to LogicalPathComponent::getMaterialized
   to now just return a SILValue for the address.  The full "Materialize"
   structure hasn't been needed since MaterializeExpr got removed.
 - Move 'struct Materialize' out of SILGen.h into SILGenLValues.cpp now
   that it is only used for logical property materialization.
 - Drop the dead 'loc' argument on DeallocStackCleanup.  The location is
   already specified when the cleanup is emitted.


Swift SVN r12827
2014-01-23 00:43:20 +00:00
Chris Lattner
84f9919016 introduce a SGF::emitRValueAsSingleValue helper function to wrap a common
and repetitive pattern.


Swift SVN r12808
2014-01-22 22:51:55 +00:00
Chris Lattner
c755b13aa0 update comments for the [attributes] -> @attributes syntax change.
Swift SVN r12795
2014-01-22 22:09:57 +00:00
Chris Lattner
7cd0f1739a A big part of handling address-only types is making sure that various
emission routines use the SGFContext passed in.  To help with this and
to help the handshake, add a new "isInContext()" representation to 
ManagedValue.  This makes the code producing and consuming these more
explicit.  NFC.


Swift SVN r12783
2014-01-22 21:31:44 +00:00
Chris Lattner
b457be6a9f SGF::emitLValueForDecl only works on VarDecls, make its prototype more specific
to reflect that.


Swift SVN r12753
2014-01-22 18:20:06 +00:00