Commit Graph

1082 Commits

Author SHA1 Message Date
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