Commit Graph

844 Commits

Author SHA1 Message Date
Pavel Yaskevich
a9bb68cea7 [ConstraintSystem] Extend TypeBinding to look more like a base class
Add all of the important information to the `TypeBinding` which covers
both type variable and disjunction choices.
2018-09-04 22:27:46 -07:00
Pavel Yaskevich
e5b63fa16c [ConstraintSystem] NFC: Unify type variable and disjunction choice representation
Introduce `TypeBinding` interface with a single `attempt` method
which is useful to encapsulate specific binding logic used for
attempting disjunction choices and type variable bindings under
a single interface. This makes it easier to unify top-level logic
responsible for binding enumeration.

It should also make it possible to introduce unified binding producer
interface in the future.
2018-09-03 23:27:41 -07:00
Pavel Yaskevich
d560b36c5c [ConstraintSystem] NFC: Move allowFreeTypeVariableBindings into SolverState
Currently `allowFreeTypeVariableBindings` flag has to be passed all
the way down from top-level `solve` call to `finalize` that forms
(partial and complete) solutions. Instead of doing that, let's just
make it a part of the solver state, which is already present
throughout whole solver run.
2018-08-31 19:51:11 -07:00
Pavel Yaskevich
f5aaa15df7 [CSSolver] NFC: Refactor tryTypeVariableBindings to use generator
Encapsulate most of the logic related to new binding generation
and iteration into `TypeVarBindingGenerator`. `tryTypeVariableBindings`
is only responsible for attempting bindings and recording results.

One more step towards iterative solver.
2018-08-31 00:53:03 -07:00
Pavel Yaskevich
f110942097 Merge pull request #19066 from xedin/try-typevar-bindings-cleanup
[CSBindings] Cleanup `tryTypeVariableBindings`
2018-08-30 16:12:51 -07:00
Pavel Yaskevich
2ae8e8d0cb [CSBindings] Cleanup tryTypeVariableBindings
* Move logic to ensure that r-value type var would get r-value type to `PotentialBindings`;
* Strip uncessary parens directly when creating `PotentialBinding`;
* Check if the binding is viable before inclusion in the set, instead of filtering it later;
* Assert that bindings don't have types with errors included in the set.
2018-08-30 00:08:26 -07:00
Mark Lacey
1d9d2049e4 Merge pull request #19063 from rudkx/a-few-less-scopes
[ConstraintSystem] Minor refactor to avoid creating scopes we don't n…
2018-08-29 20:09:18 -07:00
Mark Lacey
026d41556d [ConstraintSystem] Minor refactor to avoid creating scopes we don't need.
This probably won't hit much, and shouldn't change behavior in any way
outside of statistics we generate about the number of scopes that get
opened.
2018-08-29 18:32:48 -07:00
Pavel Yaskevich
012315fcaf [ConstraintSystem] NFC: Refactor solveForDisjunctionChoices to use iterator
Instead of passing a set of choices, locator and other flags to
`solveForDisjunctionChoices` directly, let's wrap all that information
into "disjunction" iterator which returns `DisjunctionChoice`s
directly.
2018-08-29 13:34:24 -07:00
Pavel Yaskevich
3be5c203e3 [ConstraintSystem] NFC: Move isExplicitConversion to Constraint
Since this logic is tightly coupled to constraint, it makes sense
to move just there, also it's easier to re-use it elsewhere since
it doesn't have to be `private` anymore.
2018-08-29 00:01:36 -07:00
Slava Pestov
2975f145a1 Sema: Remove ArgumentTupleConversion constraint now that its no longer used 2018-08-28 14:40:56 -07:00
Doug Gregor
8dc20dfcac [Type checker] Move TypeChecker::resolveType() into TypeResolution.
Now that type resolution is (almost completely) separated from the type
checker instance, move resolveType() out to TypeResolution where it
belongs.
2018-08-20 22:31:59 -07:00
Doug Gregor
7fa4f1df54 Merge pull request #18859 from DougGregor/type-resolution-stage
[Type Checker] Add TypeResolution(Stage) to describe type computations.
2018-08-20 18:44:31 -07:00
Doug Gregor
79a55895de [Type Checker] Replace GenericTypeResolver with a TypeResolution.
Replace the GenericTypeResolver type hierarchy with TypeResolution,
which more simply encapsulates the information needed to resolve
dependent types and makes explicit those places where we are
using resolution to contextual types.
2018-08-20 16:53:44 -07:00
Pavel Yaskevich
e81ce930ca [CSSolver] Refactor selectBestBindingDisjunction
Add an assert which verifies that all of the disjunction
choices has the same type variable on the left-hand side.

Based on that fact, refactor `selectBestBindingDisjunction`
to only check first choice to find suitable "bind" disjunctions
to favor.
2018-08-17 17:46:58 -07:00
John McCall
f6d933b032 When picking a binding disjunction, try to simplify to a common TV. 2018-08-16 18:27:29 -04:00
gregomni
0db31c9f94 Don't attempt invalid bindings that we expect to need fixes if shouldAttemptFixes is off. 2018-08-14 09:14:59 -07:00
gregomni
4d862d50cb In tryTypeVariableBindings, if T? fails, try T for all binding kinds (previously just allowed for Subtypes). This allows us to always find MissingOptionalUnwrapFailures, so that all the unwrap fixit code can be moved into CSDiagnostics and made static. 2018-08-14 09:14:59 -07:00
David Zarzycki
6b6ef5af24 [Sema] NFC: Refactor most TypeResolutionFlags into a traditional enum
TypeResolutionFlags is overly complicated at the moment because the vast
majority of flag combinations are impossible and nonsensical. With this
patch, we create a new TypeResolverContext type that is a classic enum
and far easier to reason about. It also enables "exhaustive enum"
checking, unlike the "flags" based approach.
2018-08-13 08:18:40 -04:00
Slava Pestov
f2ae23a2ab AST: Remove TupleType::getElementForScalarInit()
This is a legacy holdover from when tuple types had default
arguments, and also the constraint solver's matching of function
types pre-SE-0110.

Well, move the last live usage to CSDiag, where it can die a slow
painful death over time. The other usages were not doing anything.
2018-08-11 22:26:44 -07:00
Mark Lacey
6ade7c1253 Merge pull request #18523 from rudkx/bail-early
[ConstraintSystem] In selectDisjunction, bail early if we find no dis…
2018-08-06 16:19:39 -07:00
Mark Lacey
aabe7c217b [ConstraintSystem] In selectDisjunction, bail early if we find no disjunctions. 2018-08-06 14:29:11 -07:00
Mark Lacey
3c9cb97c86 [ConstraintSystem] Add an option to disable the constraint solver perf hacks.
This is helpful in experimenting with constraint solver changes that
might help us remove some of these unsound options. It's not ever mean
to be enabled, but if we're able to remove the things guarded by the
option we can eventually remove the option.
2018-08-06 11:48:19 -07:00
Mark Lacey
efcf87a04b [ConstraintSystem] Cleanup - remove else after return 2018-08-03 12:54:33 -07:00
Mark Lacey
94f14d4a46 Merge pull request #18386 from rudkx/simplify-state-for-disjunction-choice
[ConstraintSystem] Split the main loop attempting disjunction choices…
2018-07-31 09:55:48 -07:00
Mark Lacey
e84b372586 [ConstraintSystem] Split the main loop attempting disjunction choices out.
Make it a separate function that takes an ArrayRef<Constraint *> so
that we can call it with different collections of constraints.
2018-07-30 23:15:41 -07:00
swift-ci
e472e84691 Merge pull request #18371 from DougGregor/constraint-solver-expr-too-complex-fix 2018-07-30 22:33:45 -07:00
Mark Lacey
128a7ffa5d Merge pull request #18359 from rudkx/simplify-state-for-disjunction-choice
[ConstraintSystem] Hold slightly less state in DisjunctionChoice.
2018-07-30 18:31:20 -07:00
Doug Gregor
50eec8cb61 [Constraint solver] Check "expression too complex" more consistently.
Also, cache the result; once we've hit a too-complex expression, we
always have a too-complex expression in that constraint system.
2018-07-30 16:43:18 -07:00
Mark Lacey
7abf4b6206 [ConstraintSystem] Hold slightly less state in DisjunctionChoice.
We only care about whether the disjunction was created for an explicit
conversion.
2018-07-30 13:29:25 -07:00
Pavel Yaskevich
2ddeef7bcf [ConstraintSystem] Remove ExprCleaner and its uses 2018-07-28 20:28:41 -07:00
Greg Titus
a726deefc8 Merge pull request #18188 from gregomni/disambiguateOptionalPatternBinding
[Sema] Constrain result type of expressions in optional pattern bindings
2018-07-28 12:53:41 -07:00
Pavel Yaskevich
ae4e106491 Merge pull request #18281 from xedin/gather-constraints-improvements
[Perf Experiment][ConstraintGraph] Gather constraints improvements
2018-07-28 00:27:36 -07:00
gregomni
775cca60b6 Constrain type checking of expressions in optional pattern bindings
so that they must result in an optional type.

Add constraint locator path for identifying constraints/variables that are part of the convert type passed into the system.
2018-07-27 18:05:21 -07:00
Pavel Yaskevich
624c183fe0 [ConstraintGraph] Change gatherConstraints to take SetVector
For stable iteration order, let's switch from `SmallPtrSet`
to `SetVector` which ensures insertion order iteration.
2018-07-27 15:34:15 -07:00
Doug Gregor
55302987a8 [Constraint solver] Measure “expression too complex” only at decision points.
Polling the timers used to measure “expression too complex” is not *that*
cheap. When the constraint solver is doing a lot of work, the overhead can
add up. Reduce the number of places where we poll the timer down to
main decision points (i.e., before exploring a disjunction or binding a
new type variable), taking the timing overhead from ~3.7% —> ~1.7%.
2018-07-27 14:33:20 -07:00
Doug Gregor
0af09d3f25 Revert "[ConstraintSystem] Add a way to get the elapsed time we've spent in a SolverScope."
This reverts commit 656952af9d.
2018-07-27 14:12:27 -07:00
Pavel Yaskevich
48dd1e837b [ConstraintGraph] Add filtering to gatherConstraints per type variable
Most of the use-cases of `gatherConstraints` require filtering
at least based on the constraint kind that caller is interested in,
so instead of returning unrelated results and asking caller to
filter separately, let's add that functionality directly to
`gatherConstraints`.
2018-07-26 22:41:15 -07:00
Pavel Yaskevich
dd798accd8 [ConstraintGraph] Use set to gather constraints for type variables
Since it's possible to find the same constraint through two different
but equivalent type variables, let's use a set to store constraints
instead of a vector to avoid processing the same constraint multiple
times.
2018-07-26 22:41:07 -07:00
Mark Lacey
11b19103cc [ConstraintSystem] Minor tweak to short-circuiting logic in solver.
Rather than avoiding short-circuiting if we've selected any
unavailable overload or applied any fixes as part of the previously
found solution, only avoid short-circuiting if selecting those
overloads or applying those fixes was a direct result of the
disjunction choice we were visiting in the previously found solution.
2018-07-25 16:35:10 -07:00
John McCall
7a4aeed570 Implement generalized accessors using yield-once coroutines.
For now, the accessors have been underscored as `_read` and `_modify`.
I'll prepare an evolution proposal for this feature which should allow
us to remove the underscores or, y'know, rename them to `purple` and
`lettuce`.

`_read` accessors do not make any effort yet to avoid copying the
value being yielded.  I'll work on it in follow-up patches.

Opaque accesses to properties and subscripts defined with `_modify`
accessors will use an inefficient `materializeForSet` pattern that
materializes the value to a temporary instead of accessing it in-place.
That will be fixed by migrating to `modify` over `materializeForSet`,
which is next up after the `read` optimizations.

SIL ownership verification doesn't pass yet for the test cases here
because of a general fault in SILGen where borrows can outlive their
borrowed value due to being cleaned up on the general cleanup stack
when the borrowed value is cleaned up on the formal-access stack.
Michael, Andy, and I discussed various ways to fix this, but it seems
clear to me that it's not in any way specific to coroutine accesses.

rdar://35399664
2018-07-23 18:59:58 -04:00
Slava Pestov
e1da265873 Sema: Remove uses of AbstractFunctionDecl::getParameterLists() 2018-07-19 21:21:17 -07:00
Mark Lacey
5828a98874 Merge pull request #18032 from rudkx/restore-order
Return to the old disjunction ordering until some test regressions are addressed.
2018-07-17 20:19:35 -07:00
Pavel Yaskevich
a9660c7bc5 Merge pull request #17860 from xedin/SE-0213
[TypeChecker] SE-0213: Implement literal init via coercion
2018-07-17 17:53:25 -07:00
Mark Lacey
8b62b1327e Revert "[ConstraintSystem] Remove an attempted optimization that we've not"
I am reverting the effect of 6fa403dc7d
in 7fd052efd8, and removing this
optimization was dependent on that change in ordering.

This reverts commit c29f660652.
2018-07-17 17:28:43 -07:00
Mark Lacey
7fd052efd8 Revert the effect of 6fa403dc7d.
For the moment, return to the old ordering for disjunctions as the new
ordering regressed some type checker performance tests.
2018-07-17 17:27:19 -07:00
Mark Lacey
71656c72af Merge pull request #18012 from rudkx/refactor-disjunction-selection
Refactor disjunction selection
2018-07-17 14:05:58 -07:00
Pavel Yaskevich
aa9b3d8474 [TypeChecker] SE-0213: Implement literal init via coercion
Implementation is as follows: In `preCheckExpression` try to
detect if there is `T(literal)` call in the AST, replace it with
implicit `literal as T`, while trying to form type-checked AST,
after constraint solving, restore source information and drop
unnecessary coercion expression.

Resolves: rdar://problem/17088188
Resolves: rdar://problem/39120081
Resolves: rdar://problem/23672697
Resolves: rdar://problem/40379985
2018-07-17 12:08:59 -07:00
Mark Lacey
4ed56a1189 [ConstraintSystem] Refactor so the common path is earlier. 2018-07-17 11:28:19 -07:00
Mark Lacey
f826dbb06e [ConstraintSystem] Lift code attempting choices in a disjunction out
of solveSimplified.
2018-07-17 11:02:10 -07:00