Commit Graph

264 Commits

Author SHA1 Message Date
Doug Gregor
08893199b5 Pre-calculate and store the type variables referenced by a constraint.
This is a micro-optimization that doesn't seem to matter much at the
moment.


Swift SVN r11012
2013-12-09 13:39:16 +00:00
Doug Gregor
52d611a683 Add, use factory methods to create constraints.
Swift SVN r11011
2013-12-09 13:09:45 +00:00
Doug Gregor
dfe6646d5a Micro-optimization: replace ActiveConstraints set with a bit on Constraint.
No functionality change.


Swift SVN r10940
2013-12-06 21:41:51 +00:00
Doug Gregor
3d4da69b08 In "x as T", type-check the subexpression "x" using "T" as the context type.
Using "T" as the contextual type, either for an implicit conversion
(in the coercion case) or as a downcast (for the checked-cast case),
opens up more type-inference opportunities. Most importantly, it
allows coercions such as "1 as UInt32" (important for
<rdar://problem/15283100>). Additionally, it allows one to omit
generic arguments within the type we're casting to.

Some additional cleanup to follow.


Swift SVN r10799
2013-12-04 22:32:28 +00:00
Joe Groff
d873764add Sema: Allow an implicit conversion from T? to U? if T can be converted to U.
Similar to the T -> U? conversion, allow T? to be converted to U? through a bind-convert-inject chain. Naively adding this conversion creates ambiguities in the type checker, opening up multiple paths to the same solution in certain cases, so add a a special case to the solver that avoids introducing the conversion if a solution is already available by other means. (Doug figured out that part; thanks Doug!)

This still introduces a regression in test/Constraints/optional.swift, rendering a call ambiguous when overloaded on argument types. <rdar://problem/15367036>

Swift SVN r9857
2013-10-31 22:51:36 +00:00
Doug Gregor
e45254857a Tighten the constraint on the base of a '.' expression for protocol members.
The "conversion" constraint was far too loose, because we don't want
to permit arbitrary conversions on the left-hand side of the
'.'. Conformance constraints aren't correct either, because an
existential that does not conform to itself can still be used on the
left-hand side of a '.', so we introduce a new kind of constraint for
this.


Swift SVN r9630
2013-10-23 21:25:00 +00:00
Dmitri Hrybenko
acdd5b120a Make type checker debug output redirectable
Introduce a replaceable TypeCheckerDebugConsumer for this.


Swift SVN r9555
2013-10-21 20:26:32 +00:00
Doug Gregor
1e975393de Model lvalue-to-rvalue conversion as a conversion restriction.
Swift SVN r9414
2013-10-16 18:02:45 +00:00
Doug Gregor
e980d87f1a Explicitly model the single-element-tuple-to-scalar conversion.
Cleaner modeling of this conversion from (a : T) to T helps simplify
some of the type matching.


Swift SVN r9410
2013-10-16 15:56:45 +00:00
Doug Gregor
cf146ecaac Use disjunctions for "deep" equality match vs. user-defined conversions.
This should fix <rdar://problem/13140447> completely.


Swift SVN r9388
2013-10-15 23:36:40 +00:00
Doug Gregor
f57e20edd1 Use disjunctions for subclass-to-superclass vs. user-defined conversions.
This fixes the superclass conversion issue in <rdar://problem/13140447>.


Swift SVN r9337
2013-10-14 23:42:42 +00:00
Doug Gregor
8a896ef59a Use disjunction conversions to handle T -> U? conversion ambiguity.
The constraint solver was eagerly applying the T -> U? conversion
rule, which only succeeds when T is convertible to U. Thus, we would
reject valid code where T has a user-defined conversion to
U?. Instead, introduce a disjunction conversion to try either T -> U?
by converting T to U or via a user-defined conversion. 

Most of this is infrastructure for the introduction of constraint
restrictions, which specify that a particular constraint (say, a
conversion constraint) should only try a single direct path:
scalar-to-tuple, value-to-optional, user-defined, etc. Each term in the
disjunction created for the T -> U? case is restricted to a particular
conversion rule, so that checking it does not create another
disjunction.

Keep track of the constraint restrictions we used within a given
solution, so that we can replay those steps during the application
phase. There is a bunch of inactive code here at the moment, which
will become useful as we start creating disjunctions for other
ambiguous conversions.



Swift SVN r9318
2013-10-14 18:08:12 +00:00
Doug Gregor
16901477c2 Introduce an overload-binding constraint.
Overload bindings constraints bind a given type to a specific overload
choice. This is a step toward moving overload sets into normal
disjunction constraints.

Part of the work here is to eliminate the constraint system's
dependence on OverloadSet, which will be going away in favor of a
disjunction constraint.


Swift SVN r9209
2013-10-11 18:27:51 +00:00
Doug Gregor
2d215d68d3 Split Constraint and ConstraintLocator into their own headers.
No functionality change.


Swift SVN r9204
2013-10-11 17:24:46 +00:00