Commit Graph

998 Commits

Author SHA1 Message Date
Doug Gregor
05452e0872 Replace MemberLookup with TypeChecker::lookupMember() throughout the type checker.
Swift SVN r5861
2013-06-28 00:25:48 +00:00
Dave Abrahams
3bd556a4f7 [constraint-checker] Fix an assertion
Swift SVN r5749
2013-06-21 18:21:19 +00:00
Doug Gregor
96f819ce97 [Constraint solver] Don't guess at type variable bindings that are guaranteed to be fully bound by other constraints.
A type variable can be fully bound by either an overload set (when
selecting an overload will provide a binding for the type variable) or
by a member constraint (when the base type is determined, the member
type will be known). This keeps the solver from making really, really
bad type variable bindings based on context information.


Swift SVN r5634
2013-06-17 23:38:32 +00:00
Doug Gregor
ec12ee1b2e [Constraint solver] Dump failures as part of --debug-constraints.
Swift SVN r5627
2013-06-17 20:50:49 +00:00
Doug Gregor
491de4fc55 [Overload resolution] +1 for binding a literal expression to its default literal type.
Move this computation into the "fixed" part of the scoring, because it
is not actually relative. Collapses the linear-time check down to a
constant-time check based on the locator.

Also, unify the constraint generation logic for all of the basic type
literals (integer, float, character, string) now that we have a common
mapping from expression to literal protocol.


Swift SVN r5590
2013-06-14 22:37:01 +00:00
Doug Gregor
5711d09989 Associate locators with each of the type variables.
Swift SVN r5589
2013-06-14 22:10:32 +00:00
Doug Gregor
731782db6d [Overload resolution] Penalize user-defined conversions at -2.
This also starts to separate out the fixed part of a solution's score
from the part that is relative to another solution's score.


Swift SVN r5584
2013-06-14 18:36:55 +00:00
Doug Gregor
01c80ebc9b Produce a "diff" of type bindings and overload choices in a set of viable solutions.
Use this N-way solution "diff" when comparing two solutions to
determine which is better. No actual functionality change here,
because we're still not comparing overload choices.


Swift SVN r5518
2013-06-07 20:26:58 +00:00
Joe Groff
f0f8be9a1a Sema: Typecheck AssignExprs within the constraint system.
Set up constraints for AssignExprs within the constraint system instead of using typeCheckAssignment to set up their own isolated system. Kill the goofy hack not to consider a single-AssignExpr closure to be single-expression-body, because single-assign-expr-body closures now type-check successfully.

typeCheckAssignment still lingers because of a couple uses in typeCheckConstructorBody, but those should be easy to kill off next.

Swift SVN r5504
2013-06-07 05:15:04 +00:00
Doug Gregor
bd8e8b6afd Remove the last remnants of LiteralKind; it's no longer useful.
Swift SVN r5491
2013-06-06 06:25:51 +00:00
Doug Gregor
ac5474095b Remove literal constraints entirely; we use formal protocols now.
Swift SVN r5490
2013-06-06 06:12:56 +00:00
Doug Gregor
b8a2426673 Introduce the formal protocol IntegerLiteralConvertible for integer literals.
This eliminates the last of the old "convert literal to specific type"
code, as all of the basic literal kinds now go directly through formal
protocols. One minor casualty of this change is that we've lost the
"integer constant too large" warning. Filed as
<rdar://problem/14070127>, which is likely to be addressed in SIL.


Swift SVN r5477
2013-06-05 16:42:06 +00:00
Joe Groff
0959d96a64 Sema: Pass DeclContexts down into expression type-checking.
Thread the current DeclContext down into expression type-checking so that we will be able to set up ImplicitClosureExprs with the right parent context. (Don't actually set the right decl context when creating an ImplicitClosureExpr yet, since IRGen isn't quite ready to handle specialized partial applications and crashes on the emitted SIL if we do.)

Swift SVN r5431
2013-06-01 21:48:48 +00:00
Doug Gregor
b99375fe9f Switch type checking of float literals over to the formal protocol.
Swift SVN r5422
2013-05-31 18:43:51 +00:00
Doug Gregor
7a6e1dfce2 Introduce conformance constraints into the constraint system for float literals.
Another baby step toward relying completely on formal protocols for
float literals.


Swift SVN r5421
2013-05-31 18:18:28 +00:00
Doug Gregor
0698ace066 Introduce "shallow" type checking for expressions.
Add a version of TypeChecker::typeCheckExpression() that performs a
"shallow" type-check of just the top-level expression, rather than a
"deep" type-check of the full expression. Use it to eliminate
TypeChecker::semaApplyExpr(). 


Swift SVN r5394
2013-05-29 23:52:23 +00:00
Doug Gregor
31e19f095f Constraint generation rewrites some already-type-checked expression nodes; make those rewrites stick.
We were generating constraints from a slightly different expression
than we were applying the constraints to, which could produce odd
crashes. Be more principled about using the modified expression.


Swift SVN r5384
2013-05-29 19:53:36 +00:00
Doug Gregor
0158f71192 When opening up the context type for a member, open up all levels of archetypes.
Swift SVN r5370
2013-05-29 14:12:49 +00:00
Doug Gregor
718eb46c66 Initially, only record unavoidable failures when solving constraint systems.
If we fail to find a solution, solve the system again and track the
remaining failures. Provides a 13% improvement in the time to parse
swift.swift.


Swift SVN r5344
2013-05-25 18:46:42 +00:00
Doug Gregor
f10be3c003 Separate unavoidable failures from failures that occur under some set of assumptions.
The former should always be recorded, because they are always
reported, and require far less effort to report. The latter can be
lazily computed (only when we found no solution and no unavoidable
failures) and will require far more work to diagnose. No functionality
change.


Swift SVN r5340
2013-05-25 18:37:58 +00:00
Doug Gregor
1e90f0fd08 Make the "should we record failures?" question a parameter of constraint solving.
This will let us turn it off for the initial solve, which saves ~10%
on a debug build of swift.swift.


Swift SVN r5339
2013-05-25 18:17:52 +00:00
Doug Gregor
2fb9d8310b Clean up the ConstraintSystem interface a bit.
Swift SVN r5338
2013-05-25 17:59:48 +00:00
Doug Gregor
32ffdf7d7a Migrate ConstraintSystem::SavedBindings into SolverState.
This eliminates tracking of type variable bindings we've made during
initial constraint generation, where we wouldn't ever undo those
changes anyway.


Swift SVN r5337
2013-05-25 17:52:18 +00:00
Doug Gregor
e320f4c04a Eliminate ConstraintSystem::State; it's no longer useful.
Swift SVN r5336
2013-05-25 17:43:05 +00:00
Doug Gregor
221180d13a Factor the solving loop that attempts type bindings out of the main solver.
No functionality change.


Swift SVN r5335
2013-05-25 17:37:30 +00:00
Doug Gregor
9d34624669 [Constraint solver] Don't attempt obviously-wrong tuple-to-tuple conversions when scalar-to-tuple might work.
When we're trying to convert one tuple to another, and we hit a
problem that doesn't require us to actually perform more type
comparisons (mismatched labels, not enough elements, etc.), fall back
to attempt a scalar-to-tuple conversion when the target tuple can be
initialized by a scalar.

This is *not* a complete solution to this problem. It handles the
obvious cases, but for the non-obvious cases we'll have to pursue both
paths separately to see which one pans out.

Nonetheless, this fixes most of <rdar://problem/11293232>, as well as
<rdar://problem/13820721> and <rdar://problem/13394261>.


Swift SVN r5295
2013-05-24 00:16:08 +00:00
Doug Gregor
f2b6008871 Collapse ConstraintSystem::SharedState; it's all shared now.
Swift SVN r5283
2013-05-23 20:45:42 +00:00
Doug Gregor
3c3c56a200 [Constraint solver] Remove code unused in the current solver.
No functionality change.


Swift SVN r5282
2013-05-23 20:37:55 +00:00
Doug Gregor
27575443e2 [Constraint solver] Use the new constraint solver, start deleting the old one.
The new constraint solver is very close to providing parity with the
old solver, and is significantly faster, so cut over to the new
solver. There are minor adjustments to two tests: one where we're
losing sugar (Int becomes Int64) and another where our ignorance of
overload resolution means we don't reject something silly that we
should.

Note that this only affects the *solver* component of the
constraint-based type checker; we haven't completely obsoleted the old
type checker yet.



Swift SVN r5281
2013-05-23 20:18:22 +00:00
Doug Gregor
6e1859e106 [Constraint solver] Introduce a workaround to avoid processing the same constraint twice during simplification.
We'll want to rework the way simplification processes and retires
constraints, but it's easier to do once the old solver is gone. Down
to four failures with the new constraint checker as the default.


Swift SVN r5279
2013-05-23 16:35:48 +00:00
Doug Gregor
00c8099fe6 [Constraint solver] Initial work on a less horrible solver.
This solver handles most of what the old solver does (enabling it by
default only causes 9 test failures), but is radically simpler and
already significantly faster (~50% slower than the old-old type
checker on swift.swift). There are some egregious hacks here to still
be eliminated (see FIXMEs), but it's a start.


Swift SVN r5272
2013-05-22 20:01:32 +00:00
Doug Gregor
d8152fe3a7 [Constraint application] Handle substitution/conformance computation for member access directly.
This eliminates the use of
TypeChecker::substBaseForGenericTypeMember() from constraint
application, which relies on the existing type checker's
isCoercibleToType(). The standalone version is a bit cleaner.


Swift SVN r5156
2013-05-13 17:21:02 +00:00
Doug Gregor
87d2a580a6 Use the ArrayBound protocol for type-checking array bounds.
This only applies to the new type checker. The old type checker still
uses the informal protocol.


Swift SVN r5144
2013-05-10 17:46:58 +00:00
Doug Gregor
d6ca87b614 [Constraint checker] Implement typeCheckCondition() with a constraint system.
Introduce the LogicValue protocol, which is used to establish when a
particular type can be used as a logical value in a condition. Make
Bool conform to this protocol.

Rename the Builtin.i1-returning Bool.getLogicValue() to
_getBuiltinLogicValue(), because this is meant to be a builtin hook
for the compiler. We can add more underscores here if needed to hide
this further from users. 

Move the implementation of _getBool() into C code. It was performing
an 'if' on a Builtin.i1, which does not (and should not!) conform to
the LogicValue protocol. Once more oneof IR generation comes online,
we'll be able to write both this and _getBuiltinLogicValue in Swift
directly.



Swift SVN r5140
2013-05-10 15:42:41 +00:00
Doug Gregor
25e67b2792 FunctionConversionExpr supports arbitrary conversions, not just subtyping.
Fixes regression introduced in r5126.


Swift SVN r5129
2013-05-09 22:31:49 +00:00
Doug Gregor
543c1d36f3 Use the constraint system to determine subtyping relationships.
Eliminates another tie to the old type checker.


Swift SVN r5128
2013-05-09 22:18:37 +00:00
Doug Gregor
1db6dcd8c4 [Constraint application] Remove the now-unused isAssignment flag.
Swift SVN r5115
2013-05-09 17:19:26 +00:00
Doug Gregor
5349f9e551 [Constraint application] Thread more locators through constraint application.
As part of exercising this, tighten up the handling of user-defined
conversions: we always need to find an overload choice in the solution
that tells us what conversion function to use. Fix some
locator-synchronization issues between constraint generation and
constraint application; these need to match up exactly.


Swift SVN r5104
2013-05-08 23:07:29 +00:00
Doug Gregor
c1039b3e55 [Constraint application] Move coerceToType() into ExprRewriter.
We need more of the facilities of ExprRewriter to handle user-defined
conversions. This is a step in that direction. No functionality
change.


Swift SVN r5098
2013-05-08 20:12:33 +00:00
Doug Gregor
376089190d [Constraint application] Thread locators through coercions.
No functionality change, yet.


Swift SVN r5097
2013-05-08 18:39:20 +00:00
Doug Gregor
22859a119b [Constraint checker] A solution should know about the constraint system it solves.
No functionality change here. As a drive-by, fix the locator for
user-defined conversions.


Swift SVN r5091
2013-05-08 17:56:31 +00:00
Doug Gregor
e114abe21c [Constraint application] Coerce tuples to tuples.
Start factoring out the logic that computes the mapping from one tuple
type to another. We're only using it in one place now (the
tuple-to-tuple coercion), but it should be picked up by the constraint
checker's type-matching code.

Also, fix the temporary statistics covering how much is going through
the old coercion code. With this change, we're only missing 40 of 4548
of the coercions in swift.swift (all of which appear to be string
interpolations, function type conversions, or user-defined
conversions).


Swift SVN r5087
2013-05-08 04:03:53 +00:00
Doug Gregor
7b03a4dfed Move the constraint checker's type-coercion logic into Solution.
No functionality change (yet).


Swift SVN r5067
2013-05-06 22:52:01 +00:00
Joe Groff
635b84a228 Sema: Get metatypes for type member constraints inside addTypeMemberConstraint.
This eliminates some boilerplate from the call sites where addTypeMemberConstraint is used correctly, fixes bugs where it isn't (viz. in openType, where we were matching secondary archetypes to the metatype types of the associated types rather than to the associated types themselves), and should prevent the same class of bug from being introduced by new type member constraint generators.

Swift SVN r5041
2013-05-05 17:29:22 +00:00
Doug Gregor
2c85604e14 Remove the T(x)-as-coercion syntax from the type checker.
Swift SVN r5008
2013-05-01 04:17:21 +00:00
Doug Gregor
9b4757b288 Minor formatting cleanups.
Swift SVN r4640
2013-04-09 21:43:36 +00:00
Joe Groff
4923acce2b Use C++11 alignof(T) instead of llvm::AlignOf<T>.
Swift SVN r4583
2013-04-03 02:41:29 +00:00
Doug Gregor
be66b4546f Split the constraint-based type checker into five parts.
The five parts are:
  - Support code and high-level entry points
  - Constraint generation
  - Constraint solving
  - Constraint application
  - Diagnostics

No functionality change.


Swift SVN r4447
2013-03-19 16:04:31 +00:00