Commit Graph

370 Commits

Author SHA1 Message Date
Doug Gregor
3b63fac07e Handle dynamic lookup through the "new" generic type path.
No functionality change; just another step in subsuming the
archetype-based path.


Swift SVN r9772
2013-10-30 00:08:35 +00:00
Doug Gregor
769ed07a6d Use the opened type of a subscript reference to compute substitutions.
This eliminates the need to separately reconstruct all of the
substitutions for the base type of the subscript; our solution already
has all of that information.


Swift SVN r9771
2013-10-29 23:49:39 +00:00
Doug Gregor
45d840edfe Factor out the opening of generic function types.
No functionality change.


Swift SVN r9763
2013-10-29 21:11:09 +00:00
Doug Gregor
eecac1fd9c Eliminate the last few sources of SpecializeExprs.
All of these are dead code anyway, made redundant by ConcreteDeclRef's
elsewhere.


Swift SVN r9715
2013-10-28 18:42:24 +00:00
Doug Gregor
a000a25776 Open EnumElementDecl references via their generic function types.
Eliminates another use of SpecializeExpr.


Swift SVN r9711
2013-10-28 17:45:01 +00:00
Doug Gregor
37a803a314 For type checking, open constructor references based on their interface types.
Eliminates another use of SpecializeExpr.


Swift SVN r9690
2013-10-26 03:46:24 +00:00
Doug Gregor
a8aef7a10f Open references to protocol methods via their interface type.
Swift SVN r9641
2013-10-24 17:56:53 +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
Doug Gregor
8681e0abf9 Open operators in protocols with their interface types.
Rather than jumping through special hoops to deal with operators in
protocols, just open those methods via their interface types (which
are generic function types). This eliminates a number of special cases
for protocol methods.



Swift SVN r9626
2013-10-23 17:36:15 +00:00
Doug Gregor
905078a278 Open method references via the interface type rather than the polymorphic type.
Once we've opened method references via the interface type, we then
fold all levels of generic argument specialization into the
DeclRefExpr, rather than using SpecializeExpr. For reference, the call
to x.f in this example:

struct X<T> {
  func f<U>(u : U) { }
}

func honk(x: X<Int>) {
  x.f("hello")
}

goes from this double-specialized AST:

        (specialize_expr implicit type='(u: String) -> ()'
          (with U = String)
          (dot_syntax_call_expr type='<U> (u: U) -> ()'
            (specialize_expr implicit 
               type='(@inout X<Int>) -> <U> (u: U) -> ()'
              (with T = Int)
              (declref_expr type='<T> @inout X<T> -> <U> (u: U) -> ()'
        decl=t.X.f@t.swift:2:8 specialized=no))

to the cleaner, SpecalizeExpr-free:

        (dot_syntax_call_expr type='(u: String) -> ()'
          (declref_expr type='(@inout X<Int>) -> (u: String) -> ()'
            decl=t.X.f@t.swift:2:8 [with T=Int, U=String]
            specialized=no)

which handles substitutions at both levels together. The minor SILGen
tweak 

Note that there are numerous other places where we are still generated
SpecializeExprs.


Swift SVN r9614
2013-10-23 05:35:16 +00:00
Doug Gregor
1eebdc9025 Replace the free type variables in a solution with generic type parameters.
This is a cleaner approach to handling solutions with free type
variables than in r9513.


Swift SVN r9613
2013-10-23 05:21:53 +00:00
Doug Gregor
9def310d89 Give a real struct name SelectedOverload to (OverloadChoice, Type) pairs.
Swift SVN r9566
2013-10-21 23:06:37 +00:00
Doug Gregor
61a0958616 Open method references to methods using their interface type.
Rely on opening the GenericFunctionType of a method, rather than its
PolymorphicFunctionType. Alas, constraint application still falls back to
the PolymorphicFunctionType.


Swift SVN r9564
2013-10-21 22:28:46 +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
5269d99d0c Store substitutions within a DeclRefExpr.
Replace DeclRefExpr's stored ValueDecl* with a ConcreteDeclRef,
allowing it to store the complete set of substitutions applied to
the declaration. Start storing those substitutions (without using them
yet).


Swift SVN r9535
2013-10-21 14:36:23 +00:00
Doug Gregor
50cfd44b37 Separate the computation of substitutions from the creation of SpecializeExpr.
No functionality change.


Swift SVN r9534
2013-10-21 14:08:26 +00:00
Doug Gregor
26c6659298 Introduce a Solution::specialize() for generic function types.
This variant of specialize() uses the requirements list of the generic
function type to form the substitution list, rather than relying on
the polymorphic function type and all-archetypes lists.


Swift SVN r9518
2013-10-20 02:52:00 +00:00
Dmitri Hrybenko
4d03f74a9a Code completion / type checker: while type checking a base expression for code
completion, don't fail if we have unsolved type variables.  Type variables are
replaced with GenericTypeParamType types.


Swift SVN r9515
2013-10-19 02:06:51 +00:00
Doug Gregor
e3ebb03c28 Start opening GenericFunctionTypes for references to non-member functions.
When the type checker sees a reference to a generic non-member
function, open its interface type, which is expressed as a
GenericFunctionType, rather than its PolymorphicFunctionType. This is
a tiny step toward weaning the type checker off archetypes within the
interface.




Swift SVN r9504
2013-10-18 23:04:16 +00:00
Doug Gregor
dea5d156d1 Eliminate the useless distinction between "solve" and "trivially solved".
Swift SVN r9493
2013-10-18 21:06:25 +00:00
Doug Gregor
307d2c28ff Remove the "trivial" flag from ConstraintSystem::matchTypes() et al.
It's a bogus notion that we aren't using.


Swift SVN r9489
2013-10-18 20:57:27 +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
de416e2f4a Eliminate ConstraintSystem::isSubtypeOf().
Fix TypeChecker::isSubtypeOf() to actually solve the created system,
and introduce TypeChecker::isTrivialSubtypeOf() to handle the check
for trivial subtyping.


Swift SVN r9385
2013-10-15 22:58:17 +00:00
Doug Gregor
610fc5f2b6 Kill ConstraintSystem::isConvertibleTo().
Nobody should be using this ugly hack. Make
TypeChecker::isConvertibleTo() actually answer the "is convertible to"
query correctly.


Swift SVN r9384
2013-10-15 22:49:34 +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
e3a664cf90 Factor out the scalar-to-tuple type matching.
Swift SVN r9229
2013-10-11 22:30:50 +00:00
Doug Gregor
d0822c5f18 Start factoring the solver's type matching to support multiple matches.
ConstraintSystem::matchTypes() currently believes that there is only
one way in which two types might match each other. That being patently
untrue, start capturing the set of conversions that could potentially
work, so that we can turn them into disjunctions if when.

No functionality change yet; this is just refactoring.


Swift SVN r9227
2013-10-11 22:19:17 +00:00
Doug Gregor
9f0ba722da Isolate the tuple-to-tuple or scalar-to-tuple conversion decision somewhat.
Swift SVN r9220
2013-10-11 21:33:51 +00:00
Doug Gregor
120ab19042 Zap anther vestige of overload sets
Swift SVN r9216
2013-10-11 19:55:04 +00:00
Doug Gregor
249ad9e095 Remove overload sets from the contraint system.
Swift SVN r9215
2013-10-11 19:04:57 +00:00
Doug Gregor
2a0acba400 Teach ConstraintSystem::addOverloadSet() not to use OverloadSets.
Swift SVN r9214
2013-10-11 18:53:55 +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
1a95c47652 Split OverloadChoice into its own header.
Swift SVN r9205
2013-10-11 17:38:39 +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
Doug Gregor
014b63eb80 Restrict the DynamicLookup postfix '!' downcast to cast to class types.
This introduces "class" constraints into the type checker, so that we
can specify that a particular type must be a class (or an archetype
that is required to be a class). Finishes <rdar://problem/15139128>.


Swift SVN r9176
2013-10-10 21:45:55 +00:00
Doug Gregor
e7b78b7831 Introduce conjunction constraints into the type checker.
Not used for anything yet; these will be used for disjunctions that
require more than one constraint in a given term.


Swift SVN r9172
2013-10-10 21:20:25 +00:00
Doug Gregor
9b8a94bb16 Support forced downcasting of DynamicLookup lvalues via postfix '!'.
Swift SVN r9156
2013-10-10 18:39:19 +00:00
Doug Gregor
d0bf4edd06 Don't track "kind" constraints; we don't use them for anything now.
Swift SVN r9153
2013-10-10 18:23:37 +00:00
Doug Gregor
5a67d4caa9 Rename ConstraintClassification::Archetype to ConstraintClassification::TypeProperty
Swift SVN r9152
2013-10-10 18:22:39 +00:00
Doug Gregor
c6eac89836 Introduce disjunction constraints into the type checker.
Currently, there are no clients of disjunction constraints. Those are
coming.


Swift SVN r9144
2013-10-10 17:03:35 +00:00
Joe Groff
911929f1dd Parse and type check initializer closures after 'new T[n]' exprs.
Require that either T be default constructible or that the user provide a closure that maps indices to initial values. We don't actually call the closure yet to initialize the array; that's blocked on function abstraction difference <rdar://problem/13251236>.

Swift SVN r8801
2013-10-01 05:12:54 +00:00
Joe Groff
3d4c1251f1 Rename 'byref' attribute to 'inout'.
Swift SVN r8661
2013-09-25 20:56:52 +00:00
Dmitri Hrybenko
af8fa8c8cd Remove a circular dependency AST<->Sema caused by type printing
AST used to depend on Sema in type printing.  Specifically,
TypeVariableType::printImpl() is inside Sema.

This change moves the type variable identifier from
TypeVariableType::Implementation to TypeVariableType. This enables us to print
type variables in AST library.

Because type variable type is a temporary type for use inside type checker
only, I don't expect that we will modify it to be more verbose to enhance
diagnostics.  This is a job for locator printing.


Swift SVN r8559
2013-09-23 17:40:43 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Doug Gregor
2395bdfe1d Keep track of type variables for which stronger type bindings are preferable.
Fixes the awful "nil" regression caused by the id -> DynamicLookup change.


Swift SVN r8476
2013-09-20 00:39:14 +00:00
John McCall
dd90362f7e Type-check both sides of a PatternBindingDecl within the same constraint
system.

Tweak the tuple conversion rule so that labeled elements can lose
their label (but not change it or get passed as a vararg) if the
label wasn't written immediately in a tuple literal.  This permits
  var (a,b) = fn_returning_labeled_tuple()
to successfully type-check, as well as the analogous assignment.

This implies an unfortunate number of test changes, including some
QoI regressions, which I tried to limit as much as I could.

Swift SVN r8438
2013-09-19 00:54:56 +00:00
Doug Gregor
967072f4b3 Allow dynamic lookup to find a generic member.
The new ConcreteDeclRef class provides a possibly-speciaized reference
to a declaration, which allows DynamicMemberRefExpr to refer to both
generic and non-generic members. without having to split the AST node.


Swift SVN r7839
2013-09-03 14:55:31 +00:00
Doug Gregor
b06e65c3b3 Add the DynamicLookup protocol for lookup across all classes and protocols.
When performing member lookup into an existential that involves the
DynamicLookup protocol, look into all classes and protocols for that
member. References to anything found via this lookup mechanism are
returned as instances of Optional.

This introduces the basic lookup mechanics into the type
checker. There are still numerous issues to work through:
  - Subscripting isn't supported yet
  - There's no SILGen or IRGen support
  - The ASTs probably aren't good enough for the above anyway
  - References to generics will be broken
  - Ambiguity resolution or non-resolution

Thanks to Jordan for the patch wiring up DynamicLookup.


Swift SVN r7689
2013-08-28 21:38:50 +00:00