Commit Graph

201 Commits

Author SHA1 Message Date
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
Doug Gregor
4ea395f7ac [Constraint solver] Track whether type variables can bind to lvalues.
The type checker has a poor habit of inferring lvalue types where it
shouldn't, or (more rarely) dropping lvalue types when it should keep
them. Only allow a type variable to bind to an lvalue type in specific
situations where it makes sense (e.g., the type variable represents an
overload set that may contain a variable). Fixes <rdar://problem/13827562>.



Swift SVN r7179
2013-08-12 22:28:18 +00:00
Doug Gregor
f4e9c17032 [Constraint solver] Eliminate rvalue equality constraints.
We were only using these constraints in one place, where they had no
value.


Swift SVN r7166
2013-08-12 18:00:55 +00:00
Doug Gregor
a583ea585c const'ify Constraint dump and print methods.
Swift SVN r7164
2013-08-12 17:36:31 +00:00
Dmitri Hrybenko
de59d8dcd4 Remove unneeded llvm:: qualifier for llvm::StringRef and llvm::SmallVector
Swift SVN r7089
2013-08-09 18:41:46 +00:00
Doug Gregor
45a8e79021 [Constraint solver] Properly find and substitute deduced associated types.
Normal type lookup would find and substitute deduced associated types
appropriately, but the constraint solver's handling of member
references failed to account for them. Make sure we handle them now,
fixing <rdar://problem/14638725>.

The bulk of this change actually fixes the type vs. value member
confusion within the solver. Previously, our notion of an overload
choice lost track of whether we were looking for a type vs. a
value. This meant that we would end up getting metatypes when in fact
we expected types, and we had a few workarounds in the solver and in
the protocol conformance checker to work around that bug. Track that
we're looking for a type in OverloadChoice, so we can propagate that
information. Consequently, eliminate all of the hackarounds involving
metatypes that shouldn't be metatypes.



Swift SVN r7009
2013-08-07 22:36:49 +00:00
Doug Gregor
0dd4aedc14 [Constraint solver] Point at specific parameter or function in diagnostic.
When we're diagnosing an error during the initialization of a
parameter from an argument, point at the actual parameter (if we can
find it) or at least the function (if we can't) where the call
failed. Baby steps:

t2.swift:3:4: error: '(x : Int, y : Int)' is not a subtype of 'Int'
f3(f3b)
   ^
t2.swift:1:9: note: in initialization of parameter 'x'
func f3(x : (x : Int, y : Int) -> ()) {}
        ^



Swift SVN r6924
2013-08-05 23:39:50 +00:00
Doug Gregor
60caf622da [Constraint solver] Don't eagerly build constraint locators.
Swift SVN r6908
2013-08-05 18:19:57 +00:00
Doug Gregor
6400fdc814 [Constraint solver] Track resolved overload sets more efficiently.
Rather than maintain a big DenseMap that was only ever used for
iteration, use a constraint-system--allocated linked list with a
shared head. Good for 1.5% compile time on the standard library, and a
necessary refactor for tracking more information for diagnostics.


Swift SVN r6907
2013-08-05 18:16:54 +00:00
Doug Gregor
64afdba89f Simplfiy the check for free type variables.
Eliminates another unnecessary use of simplifyType(). No performance impact.



Swift SVN r6899
2013-08-05 15:49:23 +00:00
Dmitri Hrybenko
e1c4ae3174 Wrap llvm::SourceMgr in swift::SourceManager so that we can add new members
to the source manager.


Swift SVN r6815
2013-08-01 20:39:22 +00:00
Jordan Rose
674a03b085 Replace "oneof" with "union"...everywhere.
We haven't fully updated references to union cases, and enums still are not
their own thing yet, but "oneof" is gone. Long live "union"!

Swift SVN r6783
2013-07-31 21:33:33 +00:00
Joe Groff
b11169b5db Sema: Coerce SuperRefExprs by changing the type directly.
A SuperRefExpr semantically includes an upcast, and coercing it to a deeper subclass by wrapping it in a DerivedToBaseExpr is redundant and confuses SILGen. Instead, update the type of the SuperRefExpr directly before loading from it. Fixes <rdar://problem/14581294>.

Swift SVN r6720
2013-07-29 22:52:01 +00:00
Anna Zaks
bf6c0e2cb3 Better way of type checking ApplyExpr in presence of attributes.
Add the new ApplicableFunction constraint to represent loose function
type equality - one type is applicable to another, if their inputs
and outputs match. I've removed the hack on [auto_closure], so
type checking a call to a function with attributes
("auto_closure" or "noreturn") is handled in the same way now.

Disables a test case (added in r6598) that was relying on the previous
behavior. Doug has offered to fix it.

Swift SVN r6629
2013-07-26 00:32:23 +00:00
Doug Gregor
59535bc751 Use the correct locator when converting an expression to its contextual type.
We were inferring the locator from an already-rewritten expression,
which resulted in a completely useless locator. Use the correct
(pre-rewrite) locator. Also, eliminate the Solution::coerceToType()
overload that infers the locator, since it was inferred the wrong
thing in two out of the three callers. Fixes <rdar://problem/14429520>.


Swift SVN r6448
2013-07-22 14:59:13 +00:00
Anna Zaks
d84a075bc6 Type check noreturn attribute.
Slightly modified the constraint construction for ApplyExpr to not
include checking of the attributes.

Swift SVN r6392
2013-07-19 21:28:48 +00:00
Doug Gregor
d52750a730 Match default arguments to the function or constructor declaration they came from.
When we form a tuple that uses default arguments, find the source of
the default arguments (which will be a function or constructor
declaration). This information will eventually be introduced into the
AST.


Swift SVN r6277
2013-07-16 00:58:54 +00:00
Dmitri Hrybenko
aa46064432 Pass a const ASTContext and const DeclContext whenever possible. This makes it
possible to use lookupVisibleDecls() with a const DeclContext.


Swift SVN r6274
2013-07-15 23:39:00 +00:00
Doug Gregor
9ba865e852 Diagnose ambiguity type-checks by pointing to candidates.
Introduces very basic support for diagnosing ambiguous expressions,
where the source of the ambiguity is a reference to an overloaded
name. Simple example:

t.swift:4:1: error: ambiguous use of 'f0'
f0(1, 2)
^
t.swift:1:6: note: found this candidate
func f0(i : Int, d : Double) {}
     ^
t.swift:2:6: note: found this candidate
func f0(d : Double, i : Int) {}
     ^

There's a lot of work needed to make this cleaner, but perhaps it will
ease the pain of developing the library <rdar://problem/14277889>.


Swift SVN r6195
2013-07-12 00:45:17 +00:00
Doug Gregor
fc1c256ef5 Allow references to deduced associated types.
When checking a type's conformance against a protocol, we can deduce
the values of associated types. Make these associated types visible to
qualified name lookup so that (for example) VectorEnumeratorType does
not need to define the Element type. It is deduced from the signautre
of next(), and made available as, e.g.,
VectorEnumeratorType<Int>.Element through the Enumerator protocol
conformance. Fixes <rdar://problem/11510701>, but with some lingering
dependencies on lazy type resolution (<rdar://problem/12202655>).

Note that the infrastructure here is meant to be generalized to
support default implementations in protocols, but there are several
pieces still not in place.



Swift SVN r6073
2013-07-08 22:32:27 +00:00