Commits

Doug Gregor committed fda1ea571b3
Introduce equivalence classes for type variables within the constraint system, using a simple union-find model. When we discover a that two type variables must be equivalent, merge their equivalence classes. When we determine a fixed type for a type variable, each of the types in that equivalence class gets the same fixed type. Unrelatedly, but important for my basic example (below), improve the handling of type "matching" for function and tuple types: - For function types, fix a stupid typo that meant that we weren't actually matching up the input types at all. They're contravariant, of course. - For tuple types, implement the scalar -> tuple conversion. My simple example: swift> func ident<T>(x : T) -> T { return x } swift> var i : Int swift> :dump_constraints ident(i) ---Initial constraints for the given expression--- (call_expr type='$T2' (declref_expr type='(x : $T0) -> $T0' decl=ident) (paren_expr type='[byref(heap)] Int' (declref_expr type='[byref(heap)] Int' decl=i))) ---Type Variables--- $T0 $T1 $T2 ---Constraints--- (x : $T0) -> $T0 == $T1 -> $T2 [byref(heap)] Int << $T1 ---Simplified constraints--- ---Type Variables--- $T0 equivalent to $T2 $T1 as (x : $T0) $T2 ---Constraints--- [byref(heap)] Int << $T0 Constraint system is still viable The simplified constraint system says that the reference to 'ident' has type (x : $T0) -> $T0 and that [byref(heap)] Int must be convertible to $T0. It's up to the solver (to be implemented later) to determine that the best type for $T0 is 'Int'. Swift SVN r2635