Commit Graph

405 Commits

Author SHA1 Message Date
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
John McCall
f1180f5e6d in order to work correctly for non-@objc protocols.
Language features like erasing concrete metatype
values are also left for the future.  Still, baby steps.

The singleton ordinary metatype for existential types
is still potentially useful; we allow it to be written
as P.Protocol.

I've been somewhat cavalier in making code accept
AnyMetatypeType instead of a more specific type, and
it's likely that a number of these places can and
should be more restrictive.
When T is an existential type, parse T.Type as an
ExistentialMetatypeType instead of a MetatypeType.

An existential metatype is the formal type
 \exists t:P . (t.Type)
whereas the ordinary metatype is the formal type
 (\exists t:P . t).Type
which is singleton.  Our inability to express that
difference was leading to an ever-increasing cascade
of hacks where information is shadily passed behind
the scenes in order to make various operations with
static members of protocols work correctly.

This patch takes the first step towards fixing that
by splitting out existential metatypes and giving
them a pointer representation.  Eventually, we will
need them to be able to carry protocol witness tables

Swift SVN r15716
2014-04-01 00:38:28 +00:00
John McCall
1923cf510a existential_metatype returns a thick metatype, but
dynamic_method really expects an ObjC metatype.

Swift SVN r15666
2014-03-31 05:49:20 +00:00
John McCall
6e03b1423c Always coerce the operand of an optional force to
Optional type,

The attempt to coerce the operand to UncheckedOptional for
dynamic member accesses leads to an inconsistency when
applying the constraint solution because we haven't figured
out how to convert to UncheckedOptional<T> --- all the
conversion restrictions are to optional type.

The test case will be part of the standard test suite when
applying the UncheckedOptional import patch.

In order to continue to work around weaknesses in SILGen's
function conversion code, peephole optional conversion in
the function application path.

Swift SVN r15651
2014-03-30 19:15:18 +00:00
Joe Groff
584009d27e SIL: Remove copy_value's result.
We won't have any types where copying has an effect on the bit pattern (except for blocks, which need special handling anyway), and copy_value having a result makes optimizations more complex, so remove it.

Swift SVN r15640
2014-03-30 03:40:45 +00:00
Joe Groff
71404091d4 Add Builtin.fixLifetime as a way for library code to fix object lifetimes.
Lowers directly to the SIL fix_lifetime instruction.

Swift SVN r15637
2014-03-29 22:59:24 +00:00
Joe Groff
9f7dab725c Make the ASTContext parameter to MetatypeType::get optional for type-checked types.
We can just get it from the instance type, if the instance type has been fully initialized, which is the case except during parsing of type decls when the decls' own types are being formed.

Swift SVN r15598
2014-03-29 02:50:30 +00:00
Joe Pamer
56e2b28b76 Remove more unnecessary semicolons.
Swift SVN r15489
2014-03-26 06:07:06 +00:00
Joe Groff
f2ed6dd49b Reflection: Add additional dispositions and an 'AttributedString' QuickLookObject case.
<rdar://problem/16412965> and <rdar://problem/16413366>.

Swift SVN r15438
2014-03-25 02:55:20 +00:00
Joe Groff
b8b4f4efbe SILGen: Don't throw away the cleanup on accessor base args.
Getters and setters don't always take self at +1, in particular @objc accessors, so we can't just take the base object as an unmanaged thing. Fixes <rdar://problem/16398756>.

Swift SVN r15372
2014-03-22 22:12:32 +00:00
Chris Lattner
cecfcc38ff Fix rdar://16381392 - Super property references in non-objc classes should be direct,
a blocker for other property work.



Swift SVN r15274
2014-03-20 18:50:20 +00:00
Nadav Rotem
791d8ee6a5 a small cleanup.
Swift SVN r15217
2014-03-19 00:39:22 +00:00
Nadav Rotem
cdb1db8e8a Strip in-out qualifiers when inspecting closure arguments.
Swift SVN r15195
2014-03-18 17:36:40 +00:00
Chris Lattner
ce7bc53f50 implement <rdar://problem/16310561> Property vtables not set up correctly
This switches property/subscript dispatch to use virtual dispatch instead of static
dispatch.  This currently only works for computed properties (and subscripts of 
course), not stored ones yet.

Long story short, this:

class Base {
  subscript() -> Int {
    return 42
  }
}

class Derived : Base {
  @override
  subscript() -> Int {
    return 9
  }
}

var a : Base = Derived()
print(a[])

now prints 9 instead of 42.



Swift SVN r15142
2014-03-17 16:37:37 +00:00
Chris Lattner
4782017753 revert r15135, the missing IRGen piece breaks swiftFoundation, I can't stage it.
Swift SVN r15136
2014-03-17 15:54:31 +00:00
Chris Lattner
e99774329f switch properties and subscripts to be virtually dispatched when on any class,
not just @objc classes.  This is continued progress towards resolving rdar://16310561


Swift SVN r15135
2014-03-17 15:34:45 +00:00
Doug Gregor
3cc834714c SILGen for initialization using an existential metatype value.
Loosen the restrictions on open_existential_ref to also allow it to
refer to an existential metatype. When it does, open_existential_ref
returns the metatype for the opened archetype.



Swift SVN r15113
2014-03-16 20:52:54 +00:00
Doug Gregor
0c02a45745 Implement dispatch to @objc initializers through non-statically-derived metatypes.
Swift SVN r15097
2014-03-15 00:48:09 +00:00
John McCall
8a6dd6e124 Give CanType a getAnyOptionalObjectType accessor.
Swift SVN r15079
2014-03-14 22:00:06 +00:00
Joe Groff
cdd2ec38d2 SILGen: Add missing WitnessMarker to the synthesized generic signature of trait builtins.
Swift SVN r14946
2014-03-12 00:50:44 +00:00
Chris Lattner
d758e0dfe3 Eliminate more "DynamicLookup" in favor of "AnyObject", this is the
bulk of finishing rdar://13327098.


Swift SVN r14653
2014-03-04 22:15:46 +00:00
Doug Gregor
15be2159a2 Rename "abstract initializers" to "required initializers".
It's better than what we have.

Swift SVN r14620
2014-03-03 23:12:40 +00:00
Doug Gregor
82c1ba2e29 Remove peer_method instruction; we're no longer using it.
Swift SVN r14599
2014-03-03 17:13:06 +00:00
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