Commit Graph

2516 Commits

Author SHA1 Message Date
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
Joe Pamer
dc42cbac74 When attempting to convert an expression type to a built-in protocol, it is incorrect to assume that the expression will always conform to that protocol. (Or if it doesn't that the protocol is "broken".) In these cases, produce an error type.
Swift SVN r14342
2014-02-25 17:34:26 +00:00
Chris Lattner
b2b15d2d88 Fix <rdar://problem/16151899> init method shouldn't directly access superclasses ivars
Swift SVN r14336
2014-02-25 07:08:54 +00:00
Chris Lattner
5eb0a81974 Implement support for <rdar://problem/15912000> Stored property doesn't properly fulfil a protocol property requirement
Swift SVN r14333
2014-02-25 02:08:26 +00:00
Chris Lattner
7f4c0b981c rename the StoredObjC storage class to StoredWithTrivialAccessors since
we'll be using it for more general things soon.  NFC.


Swift SVN r14329
2014-02-25 01:08:27 +00:00
Doug Gregor
61c240c8a8 Allow construction of existential values based on an existential metatype value.
... but obviously not when we've statically derived the existential
metatype. This isn't quite the way I'd like to prohibit these issues,
but more work on existentials and metatypes is coming up shortly.


Swift SVN r14326
2014-02-25 00:32:31 +00:00
Doug Gregor
6a532e05c6 Allow construction of archetype values via archetype metatypes.
Swift SVN r14325
2014-02-25 00:11:24 +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
d69f91d68e switch Sema to produce SubscriptExpr for archetype subscripts, instead of producing
ArchetypeSubscriptExpr.  This implements support for subscripting archetypes.


Swift SVN r14283
2014-02-23 08:04:10 +00:00
Chris Lattner
30f4b1ba4a remove the unused ArchetypeMemberRefExpr and ExistentialMemberRefExpr nodes.
Swift SVN r14274
2014-02-22 22:09:38 +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
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
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
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
0da11a8b0b Implement semantic analysis for abstract initializers.
Swift SVN r14221
2014-02-21 19:41:14 +00:00
Argyrios Kyrtzidis
eeb9589d2c [AST] Introduce "hasName()" convenience methods and replace "getName().empty()" callers.
Swift SVN r14206
2014-02-21 15:00:38 +00:00
Doug Gregor
0b42fcdbea Type-check construction using DynamicSelf metatype values.
Within a DynamicSelf method, we can [*] construct an object of type
DynamicSelf by calling an initializer on the metatype
value. Type-check and build a reasonable AST for this. This is the
rest of <rdar://problem/15862605>, but see the [*] below for it to
actually be useful.

[*] We're still subject to the restriction that one cannot actually
invoke an initializer on a class metatype value that is not statically
derived; that's the intent behind "virtual" initializers
<rdar://problem/15758600>.




Swift SVN r14178
2014-02-20 23:09:28 +00:00
Doug Gregor
8024563678 Don't allow construction of classes based on non-statically-derived metatypes.
An arbitrary value of class metatype cannot be used to construct an
object, because there's no guarantee that a given subclass will
provide that initializer.


Swift SVN r14175
2014-02-20 22:17:23 +00:00
Chris Lattner
46913bae6b Move some code around, this lets us form ExistentialSubscriptExpr when
subscripting on a protocol value.  Too much else is broken to test this
yet.


Swift SVN r14082
2014-02-19 15:57:19 +00:00
Joe Groff
9a3126bbbf Make Char 32 bits again.
Making it an i21 is cute but interferes with bridging wchar_t or char32_t easily from C <rdar://problem/15840077>.

Swift SVN r13945
2014-02-16 06:36:15 +00:00
Dmitri Hrybenko
efe54a1c4a Fix a slightly different type checker crash when DictionaryLiteralConvertible is broken
Swift SVN r13906
2014-02-14 11:14:14 +00:00
Dmitri Hrybenko
90fc4aa2da Fix type checker crash when DictionaryLiteralConvertible is broken
Swift SVN r13905
2014-02-14 10:59:46 +00:00
Doug Gregor
2134072285 Split open_existential[_ref] out as their own instructions.
Riding off of project_existential[_ref] was convenient, but the
resuls are used quite differently. Note that open_existential[_ref]
still don't print/parse reasonably yet.



Swift SVN r13878
2014-02-13 23:42:23 +00:00
Doug Gregor
71f9438dd0 Introduce very basic support for selector-style initializations.
The type checker changes here are a complete hack; I'll be revisiting
this shortly. Addresses the rest of <rdar://problem/16031332>.


Swift SVN r13858
2014-02-13 04:15:55 +00:00
Joe Groff
68db63b45d AST: Have GenericFunctionType use GenericSignature.
Change GenericFunctionType to reference a GenericSignature instead of containing its generic parameters and requirements in-line, and clean up some interface type APIs that awkwardly returned ArrayRef pairs to instead return GenericSignatures instead.

Swift SVN r13807
2014-02-12 03:44:28 +00:00
Chris Lattner
b56d46b8c9 Teach sema that uses of local observing properties are direct when in
the accessors.  This completes:
<rdar://problem/15922884> support non-member observing properties



Swift SVN r13782
2014-02-11 06:57:41 +00:00
Doug Gregor
6d1f80f331 Bubble the covariant conversions to the outermost relevant call.
When applying a function that was produced via a covariant function
conversion, strip off that covariant function conversion and introduce
a covariant (function or return) conversion outside of the
application. This allows us to perform the covariant conversion very
late, eliminating the need to produce reabstraction thunks for any
call to a DynamicSelf method.


Swift SVN r13779
2014-02-11 06:29:33 +00:00
Doug Gregor
474016398f Model references to DynamicSelf methods on existentials by opening the existential.
Introduce a new expression kind, OpenExistentialExpr, that "opens" up
an existential value into a value of a fresh archetype type that
represents the dynamic type of the existential. That value can be
referenced (via an OpaqueValueExpr) within the within the
subexpression of OpenExistentialExpr. For example, a call to a
DynamicSelf method on an existential looks something like this:

        (open_existential_expr implicit type='P'
          (opaque_value_expr implicit type='opened P' @ 0x7fd95207c290
          unique)
          (load_expr implicit type='P'
            (declref_expr type='@lvalue P' decl=t.(file).func
          decl.p@t.swift:5:37 specialized=no))
          (erasure_expr implicit type='P'
            (call_expr type='opened P'
              (archetype_member_ref_expr type='() -> opened P'
          decl=t.(file).P.f@t.swift:2:8 [with Self=opened P]
                (opaque_value_expr implicit type='opened P' @
          0x7fd95207c290 unique))
              (tuple_expr type='()')))))

Note that we're using archetype_member_ref_expr rather than
existential_member_ref_expr, because the call is operating on the
opaque_value_expr of archetype type. The outer erasure turns the
archetype value back into an existential value.

The SILGen side of this is somewhat incomplete; we're using
project_existential[_ref] to open the existential, which is almost
correct: it gives us access to the value as an archetype, but IRGen
doesn't know to treat the archetype type as a fresh archetype whose
conformances come from the existential. Additionally, the output of
the opened type is not properly parsable. I'll fix this in follow-on
commits.

Finally, the type checker very narrowly introduces support for
OpenExistentialExpr as it pertains to DynamicSelf. However, this can
generalize to support all accesses into existentials, eliminating the
need for ExistentialMemberRef and ExistentialSubscript in the AST and
protocol_method in SIL, as well as enabling more advanced existential
features should we want them later.



Swift SVN r13740
2014-02-10 06:44:44 +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
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
Chris Lattner
63dc900f91 Pattern processing cleanups, NFC:
Introduce a new Pattern::forEachVariable that takes a lambda and iterates
over all the variables encompassed by the pattern (the ones found by
collectVariables) and runs the lambda on it.

Use this to implement collectVariables, so we only have one copy of the code.

Convert several places to use this, removing a bunch of duplicated code for
walking the pattern structure and extracting decls.

Convert a few uses of collectVariables to forEachVariable, leading to more
clear code without a temporary smallvector.

Remove simplifyPatternTypes in CSApply.cpp, which is dead.



Swift SVN r13545
2014-02-06 01:52:35 +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
7a3b17a238 Look through @unchecked_option for function application.
Swift SVN r13475
2014-02-05 04:51:38 +00:00
Chris Lattner
8a0512d972 Fix rdar://15962740, lets are sometimes mutable (in init methods) and we need to take
this into consideration when adjusting self.


Swift SVN r13356
2014-02-03 16:38:15 +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
af82df1aec Simplify the AST for expressions referencing DynamicSelf methods.
When referring to a DynamicSelf method, treat DynamicSelf as an alias
for the class type in which the method was declared, then perform a
function conversion to a method with the appropriate subclass as the
result result type. This is always a (trivial) subtype conversion on
the method.

Swift SVN r13268
2014-02-01 01:20:26 +00:00
Doug Gregor
81f74263c8 Clean up the ASTs for DynamicSelf on non-generic methods.
In the interface type for such a method, use the owning nominal type
within the type of the 'self' parameter. Practically speaking, this
means that a call to the method will perform a superclass conversion
when on 'self', which is what already happens for generic methods that
return DynamicSelf.



Swift SVN r13178
2014-01-30 22:44:04 +00:00
Doug Gregor
030770a8c2 Make DynamicSelf into its own special type node.
Making DynamicSelf its own special type node makes it easier to opt-in
to the behavior we want rather than opting out of the behavior we
don't want. Some things already work better with this representation,
such as mangling and overriding; others are more broken, such as the
handling of DynamicSelf within generic classes and the lookup of the
DynamicSelf type.


Swift SVN r13141
2014-01-30 05:36:20 +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
acefe4ff89 remove a special case for SelfApplyExpr that isn't needed anymore.
With that change, all calls to adjustSelfTypeForMember are in the
argument list of coerceObjectArgumentToType. Instead of doing this,
just call adjustSelfTypeForMember from coerceObjectArgumentToType
instead.


Swift SVN r13023
2014-01-28 01:20:42 +00:00
Chris Lattner
5d28be5662 start teaching sema about didset/willset. First up, accesses to the
variable are direct in init/destructor and in the didSet/willSet specifiers
themselves (to avoid infinite loops in reassignments).

Also, teach adjustSelfTypeForMember to handle direct accesses properly,
and move isImplicitDirectMemberReference early enough that it can find out
about inferred directness.


Swift SVN r13022
2014-01-28 01:09:06 +00:00
Chris Lattner
99259580cf another simplification, NFC.
Swift SVN r12977
2014-01-26 23:30:34 +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
Argyrios Kyrtzidis
dc258df962 [IDE] Make sure the constructor reference in a [super/self].init is reported by the SourceEntityWalker.
Swift SVN r12957
2014-01-26 05:13:50 +00:00