Commit Graph

2166 Commits

Author SHA1 Message Date
Doug Gregor
1ac5cedebf When performing name lookup into a member of an archetype, substitute the 'This' type through. Fixes <rdar://problem/12959759>.
Swift SVN r3694
2013-01-05 18:08:39 +00:00
Dave Zarzycki
8e0a421a93 XFAIL: constraint checker vs static funcs in protocols
<rdar://problem/12959759> Constrait checker cannot handle:
	func foo<T : P>(arg : T) -> T { return T.foo(arg) }

Swift SVN r3682
2013-01-04 22:19:03 +00:00
Doug Gregor
1224ff5b8e Extend the constraint-based type checker to support assignment
statements. The approach is fairly simple: generate constraints for
both the destination and source expressions, then turn the destination
type into a type containing only rvalues and convert the source
expression to that type.


Swift SVN r2925
2012-10-02 22:40:33 +00:00
Doug Gregor
b6af1cc01d Implement support for calling operators declared in protocols when
using archetypes so that, e.g., an archetype T that conforms to
Ordered can be compared with <. Requires the introduction of
'archetype' constraints, so that we don't run amok and allow the use
of operators in protocols for *any* type that meets the requirements
of the protocol. This may change later, with default implementations,
of course.

The egregious hack introduced in Char.isSpace() works around known,
massive performance problems with the solver's exploration of the
state space. In this case, we have 6 instances of ==, each of which
has 18 overloads, for a large state space. However, we compound the
problem significantly by trying many possibilities for the ~30 type
variables in each state, rather than concluding quickly (as we should)
that most of those branches don't make sense.



Swift SVN r2922
2012-10-02 18:27:21 +00:00
Doug Gregor
91ffa957b9 Add very basic support for selecting the best solution when the
constraint solver produces multiple solutions. The criteria for "best"
are fairly simple: we compare the bindings for each type variable
bound in both solutions:

  - If the binding in the first solution is a subtype of the binding
    in the second solution, but not vice-versa, the first solution is
    at least as good as the second
  - If the type variable has a literal constraint on it, and the bound
    type in the first solution matches the default literal type for
    that literal kind, the first solution is as good as the second.

From there, we follow the obvious rules for picking a winner: if some
of the type variables in the first solution are as good as the same type
variables in the second solution, but none of the type variables are
worse, then the first solution is better.

We can now type-check "1 + 2.0". Take *that*, TypeCheckCoercion.cpp.



Swift SVN r2894
2012-09-21 18:31:25 +00:00
Doug Gregor
d09688d9e1 When we don't have any useful upper or lower bounds on any type
variables to pick as potential bindings, try the default literal
types corresponding to literal constraints on a type variable.


Swift SVN r2883
2012-09-20 22:10:22 +00:00
Doug Gregor
5dfd6e8f2d Implement support for allocating a new array within the
constraint-based type checker.


Swift SVN r2808
2012-08-29 22:32:47 +00:00
Doug Gregor
31e7be143a Introduce support for the type coercion syntax
T(x)

where T is the name of a type. This syntax either coerces 'x' to the
type T or, failing that, enumerates the constructors of T and invokes
one of them.

Note that, syntactically, this coercion is syntactically identical to
a function application

  f(x)

We distinguish these cases with a simple, syntax-based scheme: if the
'function' subexpression of the application can be trivially
determined to have metatype type, then we consider this a
construction. Otherwise, we assume that it's a function
application. This disallows some crazy coercions---e.g., those that
involve overloaded variables of metatype type---but should feel fairly
intuitive, and it keeps the constraint systems simpler.



Swift SVN r2802
2012-08-28 23:38:23 +00:00
Doug Gregor
bd571b7476 Introduce a new kind of constraint that binds a type variable directly
to a type, without removing the lvalueness of the replacement
type. Keeping the lvalueness is important when referring to a
declaration, because that reference might be an
lvalue. Properties/subscripts are working better now.


Swift SVN r2796
2012-08-28 04:35:36 +00:00
Doug Gregor
6d514c17cf When type-checking explicit closure expressions within the
constraint-based type checker, include the body of the explicit
closure within the set of constraints. This allows type information to
flow from the body expression, so that we can type-check, e.g.,

  map(new Int[N], { $0.toString() })

to a String[] without context information. Fixes <rdar://problem/11229738>.


Swift SVN r2794
2012-08-27 19:01:29 +00:00
Doug Gregor
725fecd773 Allow the scalar -> tuple conversion as a trivial subtyping, rather
than simply a subtyping. Add some basic tests for accessing members of
a class.


Swift SVN r2790
2012-08-27 15:29:14 +00:00
Doug Gregor
fa474ee750 Implement simplification of conversion constraints for user-defined
conversions. We limit the relationship between the result of the
conversion and the actual expected type to a subtyping relationship,
which effectively limits us to applying a single user-defined
conversion function (rather than a chain of such conversions).

Later, we can consider extending this to a chain of conversion
functions, but that will require us to cope with cyclic conversions
and minimizing conversion sequences (e.g., if A -> B -> C and A -> C
are both possible, we should prefer A -> C).


Swift SVN r2730
2012-08-23 23:25:02 +00:00
Doug Gregor
8015fcecf8 Implement subtyping of classes in the constraint-based type checker.
Swift SVN r2724
2012-08-23 21:55:57 +00:00
Doug Gregor
cc133b2b46 Implement subtyping and conversion for existential types. The only
difference is that a concrete type's conformance to an existential
type is considered a conversion (but not a subtyping). Relationships
between two existential types are (non-trivial) subtyping relationships.


Swift SVN r2718
2012-08-23 00:29:35 +00:00
Doug Gregor
fd37448f22 Implement tuple shuffling and variadic tuple semantics for tuple
conversion constraints.


Swift SVN r2713
2012-08-22 19:07:38 +00:00
Doug Gregor
d7e0e15090 Add a helper function to determine whether a particular constraint
system has been "solved", meaning that all type variables have been
bound to concrete types or are completely free. Add the solvedness of
a particular system to the debug output.

Start adding some simple test cases.



Swift SVN r2706
2012-08-22 00:26:01 +00:00