Commit Graph

827 Commits

Author SHA1 Message Date
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