Commit Graph

2448 Commits

Author SHA1 Message Date
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
John McCall
0224e93a2b Only look through UncheckedOptional<T> on explicit accesses.
Add .Some and .None members.

Swift SVN r12951
2014-01-25 03:07:30 +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
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
John McCall
5c6b022cbe Track whether a constraint locator is part of a function
conversion, and use the same process to optimize isSimple()
as an afterthought.

Swift SVN r12813
2014-01-22 23:22:55 +00:00
Chris Lattner
8ad44c16a2 fix rdar://15877337 - let properties in structs are always accessed through
rvalue bases.


Swift SVN r12745
2014-01-22 17:31:51 +00:00
Doug Gregor
d52cec4b20 Eliminate a pile of literal identifiers for self, init, destructor, etc.
... because I can't stomach adding another one of these.


Swift SVN r12687
2014-01-22 01:09:49 +00:00
Chris Lattner
f5b85341a1 Expand out the "isComputed" property in AbstractStorageDecl to be an enum
with two kinds, and some more specific predicates that clients can use.

The notion of 'computed or not' isn't specific enough for how properties
are accessed.  We already have problems with ObjC properties that are 
stored but usually accessed through getters and setters, and a bool here
isn't helping matters.

NFC.



Swift SVN r12593
2014-01-20 18:16:30 +00:00
Doug Gregor
9179fa28ed TypeCheckFlags -> TypeResolutionFlags and s/TC_/TR_/g, NFC.
Swift SVN r12584
2014-01-20 16:51:42 +00:00
Chris Lattner
b4735381d0 Plumb the DeclContext of the use site down to the "doesVarDeclMemberProduceLValue"
function.  Pretty soon, whether something is an lvalue or not will depend on who is
asking.


Swift SVN r12507
2014-01-17 22:14:02 +00:00
John McCall
7be7c20a27 Implicitly look through UncheckedOptional<T> when it's the
base of a member access or subscript.

Swift SVN r12345
2014-01-15 21:00:59 +00:00
Doug Gregor
25d705f019 Rename the pattern coerceToType to coercePatternToType, switch to options.
Swift SVN r12342
2014-01-15 20:24:17 +00:00
Doug Gregor
7fdfe68a9d Be defensive when doing a metatype conversion.
Swift SVN r12285
2014-01-14 15:17:39 +00:00
Dave Abrahams
e149bd8e21 Revert "Diagnose metatype conversions we can't handle yet."
This reverts commit r12265, which caused test expr/delayed-ident/static_var.swift to fail.

Swift SVN r12271
2014-01-14 03:00:12 +00:00
Doug Gregor
d0c4ab11d7 Diagnose metatype conversions we can't handle yet.
It's better than crashing <rdar://problem/15777610>.


Swift SVN r12265
2014-01-14 01:14:58 +00:00
John McCall
817e80bde5 Implicit conversions for UncheckedOptional.
rdar://15189000
rdar://15189009

Swift SVN r12260
2014-01-13 23:15:03 +00:00
Chris Lattner
1ca9f79f55 simplify coerceObjectArgumentToType - we now no longer coerce
rvalues to lvalues, so this can be dramatically simplified.


Swift SVN r12124
2014-01-10 17:47:27 +00:00
Chris Lattner
f6a08290bc switch archetype bases over to the new world order where ArchetypeMemberRef
takes the archetype as an rvalue, not an lvalue.  This defines away the need
for MaterializeExpr at sema time, reusing the existing temporary mechanics in
SILGen.  This also opens future optimizations.


Swift SVN r12123
2014-01-10 17:41:38 +00:00