Commit Graph

844 Commits

Author SHA1 Message Date
Doug Gregor
1789c4ccbc Collapse CollectionBridgedConversionExpr into CollectionUpcastConversionExpr.
Semantically, these expressions handle the same thing: an upcast of a
collection when the underlying element types of the source are
subtypes of or can be bridged to subtypes of the destination. This
reduces some branching in the type checker and eliminates duplication
in SILGen.

Swift SVN r18865
2014-06-13 16:32:47 +00:00
Joe Pamer
1914df72f3 Begin making locators non-optional for constraints.
One difficulty in generating reasonable diagnostic data for type check failures has been the fact that many constraints had been synthesized without regard for where they were rooted in the program source. The result of this was that even though we would store failure information for specific constraints, we wouldn't emit it for lack of a source location. By making location data a non-optional component of constraints, we can begin diagnosing type check errors closer to their point of failure.

Swift SVN r18751
2014-06-09 17:49:46 +00:00
Doug Gregor
fb2f72ab48 Eliminate type checker support for forced contextual downcasting via "expr!".
We removed this feature when we changed casting syntax, but left it in
the type checker to help migrate code via a Fix-It. We no longer need
it.



Swift SVN r18729
2014-06-06 05:10:15 +00:00
Joe Pamer
a74c44a6e4 Fix two crashing bugs related to checked downcasts - rdar://problem/16093456 and rdar://problem/16892211.
Swift SVN r18118
2014-05-15 18:36:44 +00:00
Joe Pamer
1e5b9116d4 More array casting work:
- Continue adding support for checked downcasts of array types (rdar://problem/16535104)
- Fix non-bridged array conversions post-r17868
- Fix rdar://problem/16773693
- Add tests for NSArray coercions to and from Array<T>

Swift SVN r17957
2014-05-12 20:49:42 +00:00
Doug Gregor
6deba37f0a Enable strict keyword argument checking by default <rdar://problem/14462349>.
Swift SVN r17743
2014-05-09 00:20:47 +00:00
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
66391bd9e9 More improvements to constraint solver diagnostics.
Swift SVN r17256
2014-05-02 17:32:19 +00:00
Ted Kremenek
050fd53af7 Rename UncheckedOptional to ImplicitlyUnwrappedOptional.
Swift SVN r17232
2014-05-02 06:13:57 +00:00
Doug Gregor
667d90c1f4 Start diagnosing scalar-to-tuple conversions that are missing a keyword argument.
Another baby step toward <rdar://problem/14462349>, made even more
tepid by the fact that I've quarantined this behind a new flag,
-strict-keyword-arguments. Enforcing this breaks a lot of code, so I'd
like to bring up the new model on the side (with good diagnostics that
include Fix-Its) before trolling through the entire standard library
and testsuite to fix violations of these new rules.


Swift SVN r17143
2014-05-01 06:15:30 +00:00
Joe Pamer
47628dbfb6 A couple more simple tweaks to improve type-check error reporting.
Swift SVN r17099
2014-04-30 17:54:56 +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
Doug Gregor
321911a059 Add infrastructure for applying fixes during constraint solving.
Introduce some infrastructure that allows us to speculatively apply
localized fixes to expressions during constraint solving to fix minor
typos and omissions. At present, we're able to introduce the fixes
during constraint simplification, prefer systems with fewer fixes when
there are multiple fixes, and diagnose the fixes with Fix-Its.

Actually rewriting the AST to reflect what the Fix-Its are doing is
still not handled.

As a start, introduce a fix that adds '()' if it appears to have been
forgotton, producing a diagnostic like this if it works out:

t.swift:8:3: error: function produces expected type 'B'; did you mean
to call it with '()'?
f(g)
  ^
   ()

Note that we did regress in one test case
(test/NameBinding/multi-file.swift), because that diagnostic was
getting lucky with the previous formulation.

Swift SVN r16937
2014-04-27 19:04:04 +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
Doug Gregor
752828465f Type checker performance hack
This saves ~25% parsing time on the standard library and takes the
test case from <rdar://problem/16362184> from 5m32s down to
0.28s. There's a regression here when the generic form of an operator
is actually the best match, filed as <rdar://problem/16424438>.

Swift SVN r15468
2014-03-25 21:56:00 +00:00
John McCall
fe9793da94 Allow disjunction constraints to request that their
chosen alternative be recorded in the solution.  NFC.

Swift SVN r15253
2014-03-20 00:24:58 +00:00
John McCall
5531ffde25 Add a conversion from T? to @unchecked T?. This is not
a subtype conversion.

Swift SVN r15026
2014-03-14 04:43:46 +00:00
John McCall
d6335efd3f Make nil convert to both T? and @unchecked T?.
This was blocked by some type-checker issues:

First, we weren't registering a constraint restriction when
tail-recursing in matchTypes (as opposed to when creating
a disjunction because multiple conversions applied).  Do so,
and move the set of constraint restrictions to the constraint
system in order to make this simpler.  A large amount of similar
solver state is already there, and of course solving the system
already prospectively modifies the constraint graph.

Second, only set up a potential existential conversion when
working with concrete types.  Without this, we would fail to
typecheck conversions to optional protocol types, but not
optional class/struct/whatever types.  It's not clear whether
whether we should ever really be considering conversions when
either of the types is non-concrete.

I believe it was the second fix which removed a need for a !
in the NewArray test case.

Swift SVN r14637
2014-03-04 08:20:04 +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
Joe Pamer
e06f98cabd Protect against upstream errors when resolving the 'self' type of an initializer method.
When type checking constructors, ensure that any upstream errors in the resolution of the self type are accounted for (rather than assuming that the self type is always well-formed).  Not doing so can be especially problematic within the context of a type extension, since there may not even be a self type to resolve to.

Swift SVN r13506
2014-02-05 21:06:35 +00:00
Doug Gregor
69a25768b4 Teach the solver to consider the scalar field of a tuple for a subtype binding.
Fixes <rdar://problem/15888736>.

Swift SVN r12877
2014-01-23 21:46:57 +00:00
John McCall
9c415a3bed Remove the TrivialSubtype conversion kind and implement
its basic logic in libAST, which both makes it easier to
implement and makes it possible to use in the places that
should care about it, i.e. in IR-gen and SIL-gen.

Per Doug, none of the places that were introducing
trivial-subtype constraints really needed to do so rather
than just using subtype constraints.

Swift SVN r12679
2014-01-22 00:19:56 +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
9ae289de46 Drive the semantic wedge harder into lvalues. Now, instead of having one LValueType
with qualifiers on it, we have two distinct types:
 - LValueType(T) aka @lvalue T, which is used for mutable values on the LHS of an
   assignment in the typechecker.
 - InOutType(T) aka @inout T, which is used for @inout arguments, and the implicit
   @inout self argument of mutable methods on value types.  This type is also used
   at the SIL level for address types.

While I detangled a number of cases that were checking for LValueType (without checking
qualifiers) and only meant @inout or @lvalue, there is more to be done here.  Notably,
getRValueType() still strips @inout, which is totally and unbearably wrong.



Swift SVN r11727
2013-12-29 22:23:11 +00:00
Chris Lattner
18a9193452 Redesign how @inout propagation works in the typechecker:
- Switch all the 'self' mutable arguments to take self as @inout, since
   binding methods to uncurried functions expose them as such.
 - Eliminate the subtype relationship between @inout and @inout(implicit),
   which means that we eliminate all sorts of weird cases where they get
   dropped (see the updated testcases).
 - Eliminate the logic in adjustLValueForReference that walks through functions
   converting @inout to @inout(implicit) in strange cases.
 - Introduce a new set of type checker constraints and conversion kinds to properly
   handle assignment operators: when rebound or curried, their input/result argument
   is exposed as @inout and requires an explicit &.  When applied directly (e.g. 
   as ++i), they get an implicit AddressOfExpr to bind the mutated lvalue as an
   @inout argument.

Overall, the short term effect of this is to fix a few old bugs handling lvalues.
The long term effect is to drive a larger wedge between implicit and explicit 
lvalues.


Swift SVN r11708
2013-12-29 04:38:26 +00:00
Chris Lattner
d3c91387e9 Substantially simplify the API to LValueType now that nonsettable is gone.
Swift SVN r11703
2013-12-28 22:48:44 +00:00
Chris Lattner
d7621b5a7b Remove the concept of a "nonsettable lvalue": Now everything that is
nonsettable is represented as an rvalue.  Yay for one less concept in
the AST.


Swift SVN r11640
2013-12-25 22:20:01 +00:00
Chris Lattner
1472e4d914 Remove the ASTContext argument from LValueType::get(). It is already
only two loads away from the type argument passed in.



Swift SVN r11496
2013-12-20 01:28:50 +00:00
Doug Gregor
3825df464a Allow delayed-identifier expressions (.Foo) to meaningfully produce lvalues.
Swift SVN r11384
2013-12-17 17:03:16 +00:00
Dmitri Hrybenko
90f285fccb Restore compatibility with libstdc++
Swift SVN r11312
2013-12-14 12:18:24 +00:00
Doug Gregor
74784f89c4 Fold checking of the subexpression in "x as T" into the enclosing constraint system.
Previously, we had an artificial separation between the subexpression
"x" and the context of the expression "x as T". This breaks down when
the subexpression includes a reference to an anonymous closure
argument (e.g., $0) from a single-expression closure. By merging the
systems, we fix the crasher (<rdar://problem/15633178>) and allow
improved type inference for these expressions.



Swift SVN r11235
2013-12-13 04:30:20 +00:00
Doug Gregor
645f85a726 Don't try to bind incompatible type variables together.
Doing so causes the solver to loop infinitely. Fixes <rdar://problem/15536725>.


Swift SVN r11198
2013-12-12 19:13:55 +00:00
Doug Gregor
34c5c96a8b Only visit supertypes when we inferred from a constraint that permits supertypes.
Swift SVN r11100
2013-12-10 23:37:08 +00:00
Doug Gregor
61318e33f0 Compute potential bindings with the help of the constraint graph.
Rather than performing a two-pass walk over all of the constraints in
the system to attach them to type variables, use the existing type
variable -> constraints mapping in the constraint graph to make this a
faster single-pass process. Also clarify the type bindings a little
bit. Improves type checking time for the standard library by ~3%.



Swift SVN r11098
2013-12-10 23:25:37 +00:00
Doug Gregor
6fb1860f45 Replace multiple generated constraint sets with a single vector.
Swift SVN r11078
2013-12-10 16:46:46 +00:00
Doug Gregor
3755e6d556 Replace worklist deque with Active/Inactive constraint lists.
Swift SVN r11077
2013-12-10 16:36:36 +00:00
Doug Gregor
2d61bd31f8 Always use the constraint graph and worklist.
Since it takes the code in <rdar://problem/15476050> from > 10 minutes
to 4 seconds.


Swift SVN r11064
2013-12-10 01:25:56 +00:00
Doug Gregor
e4343a0f9d Don't infer [auto_closure] types; use the result type.
Swift SVN r11061
2013-12-10 00:39:22 +00:00
Doug Gregor
eaae20303d Look through one-tuples when deciding on a variable binding.
Swift SVN r11059
2013-12-10 00:30:36 +00:00
Doug Gregor
3040f2195b Factor our the selection of "alternative" literal type suggestions.
Swift SVN r11035
2013-12-09 19:19:21 +00:00
Doug Gregor
4ddd82cc89 As soon as a (partial) solution becomes worse than the best solution, stop.
This shaves about 10% off the number of solution states explored when
type-checking the standard library, although it doesn't improve
overall time by much. In a more targeted benchmark, 1 + 2.0 + 1, we
get a 21% speedup.


Swift SVN r11033
2013-12-09 18:13:37 +00:00
Doug Gregor
79f8175e0b Solver: Keep track of a solution's score as we're computing it.
No functionality change here; just staging for some future optimizations.


Swift SVN r11028
2013-12-09 17:12:07 +00:00
Doug Gregor
5bb053c0dd Fix renamed file names
Swift SVN r11017
2013-12-09 14:20:33 +00:00
Doug Gregor
ee545e9f68 Rename TypeCheckConstraintsFoo.cpp to CSFoo.cpp.
It's more idiomatic and easier to type.


Swift SVN r11015
2013-12-09 14:09:54 +00:00