Commit Graph

1476 Commits

Author SHA1 Message Date
Doug Gregor
36cbcccbe9 Generalize constraint application under -strict-keyword-arguments.
Introduce a new locator kind for argument/parameter comparisons that
tracks both the argument and the parameter, which we will eventually
use in diagnostics more regularly. For now, this helps us smooth over
scalar-to-tuple/tuple-to-tuple/tuple-to-scalar nonsense when dealing
with calls.

Fix a pile of fallout from this change.

Swift SVN r17648
2014-05-07 22:36:49 +00:00
Joe Pamer
d22ffa8cb8 Re-lazify the addition of equatable conformances to imported enum types. (rdar://problem/16808612)
Rather than force conformances to Equatable to be added to all imported enumeration types outright, change them back to being lazily added. We can then handle situations where new overloads of '==' are introduced during constraint generation by re-writing the relevant overload disjunction constraint to include the newly forced declarations as bind options.

Swift SVN r17557
2014-05-06 19:56:29 +00:00
Jordan Rose
3e917be738 Use full DeclNames for dynamic lookup of calls.
Previously, we were just using the base name, which resulted in massive
inefficiency when dealing with Clang (we basically had to check every
selector in the system to see if it had the same first selector piece).
I've hacked ConstraintSystem a bit to carry a map from UnresolvedDotExpr
to the ApplyExpr that consumes it, so that we can use the full DeclName
and look up methods by full selector.

Now that dynamic lookup is fast, re-enable it for the
Foundation_bridge.swift test. (r17520 actually provided most of the benefit.)

This does break selector lookup on AnyObject when doing selector splitting,
and slightly regresses diagnostics when you try to call a method on AnyObject
and forget a parameter name.

<rdar://problem/16808651>. Part of the Playground performance efforts.

Swift SVN r17524
2014-05-06 02:35:08 +00:00
Joe Groff
8a5667487c Remove unused function.
Swift SVN r17514
2014-05-06 01:08:10 +00:00
Doug Gregor
baea80e28b Closures don't have keyword arguments.
Swift SVN r17483
2014-05-05 19:43:10 +00:00
Ted Kremenek
050fd53af7 Rename UncheckedOptional to ImplicitlyUnwrappedOptional.
Swift SVN r17232
2014-05-02 06:13:57 +00:00
Doug Gregor
97a2df25c5 Add a new conversion and type-matching kind for argument tuples.
We're going to give argument-tuple handling special behavior; separate
it out first.

Swift SVN r17095
2014-04-30 15:32:50 +00:00
Chris Lattner
30915de98f Form TypeExprs for non-specialized unqualified declrefs that refer to types... like "Int".
Building on previous work, this allows us to properly handle things like Int?() and Int[]().

Of course doing this exposed that TypeExpr was not correct in lots of ways, so this also:
 - Revamps TypeExpr processing to carry a decl in the TypeLoc instead of 
   carrying a Type.  This allows us to correctly handle more complex generics case.  
 - Enhances CSGen to properly open generic types so we can infer generic type parameters from
   context.


Swift SVN r17019
2014-04-29 05:25:21 +00:00
Chris Lattner
29aca1c851 Various minor TypeExpr improvements:
- Change astdumper to print the typerepr in the more canonical syntax.
 - Remove bogus logic from CSApply that was preventing us from rewriting
   TypeExprs properly
 - Teach CSGen to handle unbound generics correctly (thanks to Doug for the help on this)



Swift SVN r17007
2014-04-29 02:58:43 +00:00
Doug Gregor
e84ec00864 Default initialization for @weak <rdar://problem/16662262>.
Swift SVN r16962
2014-04-28 06:39:12 +00:00
Chris Lattner
c45e6b75fd Rip out logic added to me misunderstanding ExistentialMetatypeType,
and teach type checking to resolve TypeExprs that lack TypeReprs.

This gets us debugged enough to start shoving all local type references
down the TypeExpr path, which is significant progress.


Swift SVN r16958
2014-04-28 04:42:44 +00:00
Chris Lattner
53a8a06b9d ongoing progress on TypeExpr rollout, this makes it handle existential metatypes
better and cleans up some interfaces.  They aren't used enough to make much of a
difference yet.



Swift SVN r16957
2014-04-28 02:22:25 +00:00
Ted Kremenek
6caf910d32 Implement new syntactic sugar for UncheckedOptional<T>.
This leaves in the existing syntax for @unchecked T?.  That will
be addressed in later patches.

There's still a mysterious case where some of the SIL output
includes UncheckedOptional<T> and some places T!.

Moreover, this doesn't handle SourceKit's behavior for printing
for overrides.  This just handles parsing the 'T!' syntax.

Swift SVN r16945
2014-04-27 21:59:29 +00:00
Doug Gregor
887fada26f Make the locator associated with an assignment source based on the assignment.
For an assignment "x = y", the locator for the conversion constraint
is an "assign source" locator anchored on the AssignExpr (not the
source expression), so we can properly relate source to destination.

Swift SVN r16931
2014-04-27 16:40:42 +00:00
Chris Lattner
78e8d3f0a9 rename the MetatypeExpr AST node to DynamicTypeExpr now that it is only
used by the "foo.dynamicType" syntax.


Swift SVN r16658
2014-04-22 20:10:11 +00:00
Chris Lattner
7de9c0802a Peel off almost all of the uses of MetaTypeExpr, replacing
them with uses of TypeExpr instead.  The remaining uses of 
MetaTypeExpr (which will be renamed soon) are places where we
are applying the ".dynamicType" virtual property to an expression.

Unadorned uses of types in code, e.g. the Int in "Int.self" are
now represented with TypeExpr.

One unfortunate travesty that doing this work revealed is that we
are extremely sloppy and terrible about maintaining location information
in implicitly generated decls, and our invariants vary quite a bit.  This
is really horrible, but I'm not sure whether I'll go fix the hacks or not.

This patch perpetuates the existing crimes, but makes them more visible.

NFC!




Swift SVN r16646
2014-04-22 05:15:44 +00:00
Chris Lattner
7f3d88632d Introduce a new AST node, named TypeExpr, which will be formed by sema
when resolving identifiers into types.  This will eventually allow us to
solve annoying issues like rdar://15295763&15588967 by better modeling
what we already have.


Swift SVN r16620
2014-04-21 16:10:11 +00:00
Dmitri Hrybenko
e2e8db5f38 Migrate IB attributes to new decl attribute representation and fix a few bugs
along the way


Swift SVN r16542
2014-04-18 20:00:09 +00:00
John McCall
f70879c4d9 Fix a weirdly complicated issue with the order of
type-checking and applying attributes.

We should really move to a model where variables are
type-checked in a single pass, including their attributes.
However, given that we don't, attributes which affect the
type must be applied in multiple places and hence multiple
times to the same declaration.

Swift SVN r16339
2014-04-14 22:54:30 +00:00
John McCall
8a85750c4c Plumb a lot of querying for different kinds of existential
type.

Swift SVN r16232
2014-04-11 22:30:14 +00:00
Joe Groff
7f47ea97fa Sema: Rework __inout_conversion to pass inouts instead of pre-converted RawPointers.
Make it the conversion function's responsibility to addressof the inout if it wants that pointer. For things like mutable array conversion, we actually want the original inout as a parameter, particularly so we can call _makeUnique on it without disturbing its reference count.

Swift SVN r16090
2014-04-09 00:51:40 +00:00
Chris Lattner
b60cb398fc fix <rdar://problem/16554876> property accessor synthesization of @weak variables doesn't work
Swift SVN r16066
2014-04-08 18:50:19 +00:00
Doug Gregor
c5163307c1 Type checker: tighten up the conditions under which we add a "function conversion" score.
Swift SVN r15891
2014-04-03 20:31:32 +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
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
c4d8f238d4 When performing contextual lookup for .memberAccesses,
permit the result to be *convertible* to the contextual
type and not merely *exactly equal*.

I don't have a use case for factory methods that return
subtypes, but factory methods that return @unchecked T?
are going to be pervasive, and it's not like the subtype
thing is unreasonable.

Swift SVN r15664
2014-03-31 05:00:57 +00:00
Joe Groff
7165553b7d Sema: Use JoeP's "discard failures" feature to keep inout type failures from sucking.
Swift SVN r15604
2014-03-29 02:50:37 +00:00
Joe Groff
953c93d936 Sema: Rework inout conversion to do simple member lookup instead of using a protocol.
We'll need types to be convertible from multiple kinds of inouts, which currently can't be represented with protocol conformance since we only allow one protocol conformance per type per protocol. Instead just look for a magic "__inout_conversion" static method in the type; this is lame but easy, and inout conversions shouldn't be available outside of the stdlib anyway.

Swift SVN r15599
2014-03-29 02:50:32 +00:00
Joe Groff
46f77c6181 Sema: Build the AST for inout address conversions.
Add two new AST node types:

- InOutConversionExpr, which represents an '&x' expression that involves inout conversion. This will be a signal to SILGen not to introduce a writeback scope for the nested conversion call.

- LValueToPointerExpr, which represents the primitive '@lvalue T' to 'RawPointer' conversion that produces the argument to the inout conversion.

Build an InOutConversionExpr AST when an inout expression is resolved by a conversion to an BuiltinInOutAddressConvertible type.

Swift SVN r15594
2014-03-29 02:50:25 +00:00
Joe Groff
93f319c706 Sema: Set up constraints for inout conversions.
Set up the disjunction system for '&x' expressions that allows them to type-check either as simple lvalue-to-inout conversions, as before, or as address conversions that go through one of the BuiltinInOut*Convertible protocols. The solution side is not yet implemented.

Swift SVN r15593
2014-03-29 02:50:24 +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
John McCall
1ed9c46fda Permit ! to do the AnyObject downcast magic through one level of
optional type.

Swift SVN r15306
2014-03-20 23:58:14 +00:00
Joe Groff
1585b625f9 Sema: Wire up compound name lookup to UnresolvedSelectorExpr.
Resolve selector references using compound name lookup, pushing DeclNames a bit deeper through the type-checker and diagnostics as necessary.

Swift SVN r14791
2014-03-07 20:52:30 +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
Dmitri Hrybenko
e4dad5cbe4 Type checker: don't create constraints with null types
Fix an issue in the type checker where it could create a constraint with a null
SecondType, and then fail elsewhere later.


Swift SVN r14638
2014-03-04 09:39:58 +00:00
Joe Groff
363a324984 Parse: Start parsing selector member references.
Parse 'x.y:z:' for at least two selector pieces as an UnresolvedSelectorExpr, and declare it unimplemented in Sema.

Swift SVN r14492
2014-02-28 01:47:32 +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
Joe Groff
98d6fecc99 '.metatype' -> '.Type'
Also, reserve 'type' as a keyword for ensuing syntax changes.

Swift SVN r14375
2014-02-26 04:23:21 +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
3392c4e8ab remove ArchetypeSubscriptExpr, since it is dead now.
Swift SVN r14284
2014-02-23 08:04:51 +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
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
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
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
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
be9c6f2d26 Track the member types of type variables explicitly within the constraint graph.
This eliminates the duplication of type variables that represent the member types of existing type variables. I'm unable to trigger this with a test case at the moment, but it becomes important when we begin to substitute type variables through protocol conformances.

Swift SVN r12971
2014-01-26 22:38:33 +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
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
Doug Gregor
9179fa28ed TypeCheckFlags -> TypeResolutionFlags and s/TC_/TR_/g, NFC.
Swift SVN r12584
2014-01-20 16:51:42 +00:00