Commit Graph

1232 Commits

Author SHA1 Message Date
Doug Gregor
b1dfcd7085 Dynamically dispatch when delegating from a complete object initializer.
Inherited initializers are now functional: one can use an inherited
initializer to construct an object of a subclass type, and we properly
handle delegation to overridden complete object or subobject
initializers as appropriate. See the executable test.

This commit also contains various fixes for the IRGen side of vtable
emission and use. Proper IRGen tests still to come.

For now, we're still performing peer delegation from a subobject
initializer to another subobject initializer, hence the SILGen hack
for identifying when we're in a complete object vs. a subobject
initializer. We'll be banning delegation from subobject initializers,
so this hack---along with the peer_method instruction---will be going
away in the near future.



Swift SVN r14571
2014-03-02 08:19:11 +00:00
Doug Gregor
8f64658fc1 Misc. cleanups related to SuperRefExpr queries.
Swift SVN r14558
2014-03-01 18:54:34 +00:00
Joe Groff
88b6efcc43 Rename ArchetypeMethodInst -> WitnessMethodInst more thoroughly.
Swift SVN r14501
2014-02-28 06:41:18 +00:00
Joe Groff
59d2a169f6 SIL: Rename 'archetype_method' to 'witness_method'.
It has been generalized to get a witness out of an arbitrary protocol conformance, not just for archetypes.

Swift SVN r14497
2014-02-28 05:09:11 +00:00
Jordan Rose
0d4b039e11 Support properties in Objective-C protocols.
There are two parts to this:
- Import protocol properties as properties, instead of as a pair of methods.
- Fix IRGen to handle property accesses in @objc protocols.

<rdar://problem/12993073>

Swift SVN r14438
2014-02-27 01:19:08 +00:00
Chris Lattner
1344319677 Rename the internal compiler lexicon from val -> let.
Swift SVN r14408
2014-02-26 21:21:18 +00:00
Joe Groff
c0d8ae7c13 Parse 'x.self' as an identity expression.
Factor an IdentityExpr base class out of ParenExpr, and migrate most of the logic to see through ParenExprs to see through IdentityExprs instead. Add DotSelfExpr as a new subclass of IdentityExpr, produced by parsing 'x.self'.

Swift SVN r14381
2014-02-26 06:23:55 +00:00
Doug Gregor
ea16062f75 Basic SILGen support for initializer requirements.
Emit witnesses for initializer requirements. Allow the use of
initializer requirements on archetypes; existentials don't work due to
<rdar://problem/16165890>.


Swift SVN r14356
2014-02-25 23:06:33 +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
d3e2870646 remove some dead code.
Swift SVN r14278
2014-02-23 05:32:44 +00:00
Chris Lattner
e6dcae5c4f Change sema to form MemberRefExpr instead of ArchetypeMemberRefExpr. The most
significant impact of this is that it eliminates a bunch of near duplicate logic
in SILGen and makes ArchetypeMemberRefExpr dead.


Swift SVN r14273
2014-02-22 21:59:36 +00:00
Chris Lattner
1bb9d28680 switch all existential member refs to be done with MemberRefExpr, making
ExistentialMemberRefExpr dead.


Swift SVN r14272
2014-02-22 21:24:16 +00:00
Chris Lattner
0134eb2309 rework sema and silgen to build subscripts on protocols as
SubscriptExpr instead of ExistentialSubscriptExpr.  The later
is just a special case of the former.


Swift SVN r14267
2014-02-22 20:09:54 +00:00
Chris Lattner
a16aeccd40 enhance getBaseAccessorFunctionRef to handle accessors in protocols, and
implement RValueEmitter::visitExistentialSubscriptExpr to call it.  This
allows rvalue subscript calls on protocols to work.


Swift SVN r14265
2014-02-22 19:33:58 +00:00
John McCall
3d5d8fdc03 Resilience expansion is really an aspect of a SILDeclRef.
We should also remove it from IRGen's Explosion API; IRGen
should always use maximal explosion, and SILGen will tell us
whether or not we need to put that in memory somewhere.
But that can be a later commit.

Swift SVN r14242
2014-02-21 23:28:43 +00:00
Doug Gregor
b5af687b6d Emit and use vtable entries for abstract initializers.
Emit vtable entries for abstract initializers. When we're constructing
an object using an abstract initializer based on a metatype value that
is not statically derivable, use the vtable entry to call the
subclass's allocating constructor.

Most of the IRGen work here is hacking around the lossy SILDeclRef ->
(Code|Function)Ref -> SILDeclRef conversion. I'd feel bad about this
if John hadn't already agreed to clean this up at some point.



Swift SVN r14238
2014-02-21 23:15:46 +00:00
Doug Gregor
c54f98fbc9 Convert thick/thin metatype bool to an enumeration. NFC
Swift SVN r14075
2014-02-19 06:05:48 +00:00
Chris Lattner
ecbbb4a42c rework our representations of subscripts to not curry the indexes
separately from the get/set value.  There is no exposed way in the
source language to use this, and this causes shorter term annoyance.

I chose to flatten the value and indices so the value comes first.
In principle, this allows us to completely eliminate our ObjC importer
thunks.  I haven't removed them though, because they might be useful
for something else.


Swift SVN r14049
2014-02-18 21:34:33 +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
Chris Lattner
28903887e7 Rename the internal compiler lexicon from let -> val.
Swift SVN r13992
2014-02-17 16:48:21 +00:00
Joe Groff
a0874ad8d0 Add a Builtin.canBeObjCClass "type trait" builtin.
This builtin returns true for types that might be ObjC class types. We want to use this builtin to optimize away NSArray handling for non-object Array types, so it needs to persist in SIL long enough for specialization to do its thing, but we never actually want to pay a runtime cost for this check, so always lower it to a constant value at IRGen time. Handle this by having canBeObjCClass return a tri-state "yes/maybe/no" result. In SILGen, we only fold away obviously "yes" or "no" cases, and in IRGen, we fold away "maybe" cases as "yes".

The optimizer will need to learn about this builtin too, but that part isn't done yet.

Swift SVN r13980
2014-02-17 07:25:52 +00:00
Chris Lattner
0388d07cb1 fix <rdar://problem/16006333> observing properties don't work in @objc classes
willSet and didSet accessors need to be dispatched directly, even in the 
@objc case, and should never be added to vtables.



Swift SVN r13918
2014-02-14 19:29:20 +00:00
Chris Lattner
d88852e457 remove SILDeclRef::Getter/Setter and supporting code. NFC, but I think
the previous patches have defined away a few obscure bugs handling subscript 
accessors (from inspection).


Swift SVN r13885
2014-02-14 01:12:56 +00:00
Chris Lattner
12196c17ba Now that we always have funcdecls for getters and setters, we don't need
SILDeclRef::Getter/Setter and the complexity therein.  Switch the world
to make SILDeclRef::Func's instead of them.  NFC.


Swift SVN r13875
2014-02-13 23:11:29 +00:00
Joe Groff
06b7ca2855 AST: Include "Self" and associated archetypes in AllArchetypes of a GenericParamList.
The need to hide Self from AllArchetypes of a GenericParamList is (almost) defined away by @cc(witness_method); IRGen now knows how to do the right thing for witnesses regardless of their generic signature. Eliminating this special case from the AST allows us to clear up a bunch of ugly hacks that piled up elsewhere to try to accommodate that special case, and makes the prospect of moving IRGen's PolymorphicConvention to interface types more manageable.

We do need an unfortunate hack to suppress emitting associated archetypes of Self when considering an archetype as the polymorphic source for a witness, since we can't actually pass those through the witness CC without breaking ABI compatibility between generic signatures.

Swift SVN r13663
2014-02-07 23:24:51 +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
Chris Lattner
827acad533 Various inout improvements:
- purge @inout from comments in the compiler except for places talking about
   the SIL argument convention.
 - change diagnostics to not refer to @inout
 - Change the astprinter to print InoutType without the @, so it doesn't show
   up in diagnostics or in closure argument types in code completion.
 - Implement type parsing support for the new inout syntax (before we just 
   handled patterns).
 - Switch the last couple of uses in the stdlib (in types) to inout.
 - Various testcase updates (more to come).



Swift SVN r13564
2014-02-06 06:22:27 +00:00
Joe Groff
484468fd96 Push deprecations of SILConstantInfo non-interface types out a bit. NFC.
Swift SVN r13502
2014-02-05 20:23:35 +00:00
Doug Gregor
430fa4d937 Rename SILGenApply method that unfortunately contained "DynamicSelf". NFC
Swift SVN r13487
2014-02-05 17:04:17 +00:00
Doug Gregor
04475c6a85 Use @unchecked optionals for member references into AnyObject/AnyClass.
This eliminates the need for a number of !'s when dealing with
Objective-C APIs. Now with actual executable behavior!


Swift SVN r13483
2014-02-05 07:58:18 +00:00
Doug Gregor
b959059fa9 Sink the DynamicSelf -> owning type replacement lower in SIL type mapping.
SILGenApply is just one such place where this needs to happen;
instead, make it happen when computing the type of a SIL constant,
which applies far more generally.


Swift SVN r13305
2014-02-01 21:08:14 +00:00
Doug Gregor
9f72215bba Basic SIL- and IR-generation support for trivial uses of DynamicSelf.
Introduce a new AST node to capture the covariant function type
conversion for DynamicSelf. This conversion differs from the normal
function-conversion expressions because it isn't inherently type-safe;
type safety is assured through DynamicSelf.  

On the SIL side, map DynamicSelf down to the type of the declaring
class to keep the SIL type system consistent. Map the new
CovariantFunctionConversionExpr down to a convert_function
instruction, slightly loosening the constraints on convert_function to
allow for this (it's always been ABI-compatible-only conversions
anyway).

We currently generate awful SIL when calling a DynamicSelf method,
because SILGenApply doesn't know how to deal with the implicit return
type adjustment associated with the covariant function
conversion. That optimization will follow; at least what we have here
is (barely) functional.


Swift SVN r13286
2014-02-01 04:09:00 +00:00
Michael Gottesman
74165eef2b Revert "Basic SIL- and IR-generation support for trivial uses of DynamicSelf."
This reverts commit r13269. It broke the build.

Swift SVN r13281
2014-02-01 02:31:39 +00:00
Doug Gregor
c25b14b1bd Basic SIL- and IR-generation support for trivial uses of DynamicSelf.
Introduce a new AST node to capture the covariant function type
conversion for DynamicSelf. This conversion differs from the normal
function-conversion expressions because it isn't inherently type-safe;
type safety is assured through DynamicSelf.

On the SIL side, map DynamicSelf down to the type of the declaring
class to keep the SIL type system consistent. Map the new
CovariantFunctionConversionExpr down to a convert_function
instruction, slightly loosening the constraints on convert_function to
allow for this (it's always been ABI-compatible-only conversions
anyway).

We currently generate awful SIL when calling a DynamicSelf method,
because SILGenApply doesn't know how to deal with the implicit return
type adjustment associated with the covariant function
conversion. That optimization will follow; at least what we have here
is (barely) functional.

Swift SVN r13269
2014-02-01 01:20:26 +00:00
Doug Gregor
f3f7cbeb45 Zap the upcast before forming a super_method for a property/subscript getter/setter.
Swift SVN r13105
2014-01-29 08:32:12 +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
290a58494e Implement debug info for willset/didset, and teach dispatch to be non-virtual
to didset/will set since we don't drop these in the class vtable.


Swift SVN r13056
2014-01-28 06:33:31 +00:00
Joe Groff
b6108c0bc2 SILGen: Consume CallEmission parameters based on the interface type.
NFC, the logic here does not depend on generic context.

Swift SVN r13039
2014-01-28 02:46:33 +00:00
Chris Lattner
a945271aa8 Now that properties in protocols are always computed, and that StoredObjC
properties have accessors, we have an amazing property: everything that we
want to form a getter or setter for ... really has one! I suspect many things
can be simplified now, but the first on the chopping block is 
StorageDecl::getGetterType (and its three friends) which is now always exactly
just getGetter()->getType().



Swift SVN r12983
2014-01-27 06:17:28 +00:00
Chris Lattner
17d784a164 simplify code further. This avoids retain/releasing the base of a classbound protocol/existential.
No change in the stdlib.


Swift SVN r12878
2014-01-23 21:50:03 +00:00
Chris Lattner
c866b721d2 Remove the old "getExistentialOrArchetypeRValueAddress" hack for producing some
bases at +0, and use the new SGFContext::AllowPlusZero mechanism instead.  It
is more rigorous and general.  This cuts 34 lines out of the stdlib, deleting
temporary materializations from: Zip2.generate, and several methods from
Reverse and ReverseIndex.

Also:
 SILGenApply.cpp |   41 ++++-------------------------------------
 1 file changed, 4 insertions(+), 37 deletions(-)



Swift SVN r12875
2014-01-23 21:25:06 +00:00
Dave Zarzycki
6eba6ceeeb Zap accumlated unused variable warnings in non-assert builds
Swift SVN r12861
2014-01-23 08:11:37 +00:00
Chris Lattner
87fbce6a1a Progress on <rdar://problem/15867140> [string perf] member_ref_expr on an rvalue producing unnecessary retains/releases
- Remove my previous local hack.
- Add a new flag to SGFContext indicating that clients are ok with +0 rvalues.
- Teach emitRValueForPropertyLoad and emitRValueForDecl how to work with +0 rvalues.

This allows us to avoid retaining bases in arbitrarily nested struct rvalue
member_ref_expr's.  For example, this:

class SomeClass {}

struct AnotherStruct {
  var x : Int
  var c : SomeClass
}

struct StructMemberTest {
  var c1 : SomeClass, c2 : SomeClass
  var s : AnotherStruct

  func testRecursiveStruct() -> Int {
    return s.x
  }
}

used to compile to:

sil @_TFV1t16StructMemberTest19testRecursiveStructfS0_FT_Si : $@cc(method) @thin (@owned StructMemberTest) -> Int64 {
bb0(%0 : $StructMemberTest):
  debug_value %0 : $StructMemberTest  // let self // id: %1
  %2 = struct_extract %0 : $StructMemberTest, #s  // user: %3
  %3 = copy_value %2 : $AnotherStruct             // users: %5, %4
  %4 = struct_extract %3 : $AnotherStruct, #x     // user: %7
  destroy_value %3 : $AnotherStruct               // id: %5
  destroy_value %0 : $StructMemberTest            // id: %6
  return %4 : $Int64                              // id: %7
}

and now it compiles to:

sil @_TFV1t16StructMemberTest19testRecursiveStructfS0_FT_Si : $@cc(method) @thin (@owned StructMemberTest) -> Int64 {
bb0(%0 : $StructMemberTest):
  debug_value %0 : $StructMemberTest  // let self // id: %1
  %2 = struct_extract %0 : $StructMemberTest, #s  // user: %3
  %3 = struct_extract %2 : $AnotherStruct, #x     // user: %5
  destroy_value %0 : $StructMemberTest            // id: %4
  return %3 : $Int64                              // id: %5
}

There is more that can come from this, but it is a start.  This cuts out 50 retain/release pairs from the stdlib.



Swift SVN r12857
2014-01-23 06:54:02 +00:00
Dave Abrahams
d58caea0cd Revert "Zap accumlated warnings in non-assert builds"
This reverts r12850, which broke the build for me.

Swift SVN r12856
2014-01-23 06:47:29 +00:00
Dave Zarzycki
17eb84d9c6 Zap accumlated warnings in non-assert builds
Swift SVN r12850
2014-01-23 05:45:24 +00:00
Chris Lattner
3c60715902 fix two cases where SGFContext's were incorrectly passed down when of
the wrong type.  this was noticed by inspection, I don't have a testcase.


Swift SVN r12817
2014-01-22 23:48:05 +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
7ee9d7070e The 'ChildOfLoad' and 'Ungeneralized' forms of SGFContext are not used,
remove them.


Swift SVN r12797
2014-01-22 22:21:23 +00:00
Chris Lattner
c755b13aa0 update comments for the [attributes] -> @attributes syntax change.
Swift SVN r12795
2014-01-22 22:09:57 +00:00