Commit Graph

827 Commits

Author SHA1 Message Date
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
Mark Lacey
14fe171343 Merge pull request #17991 from rudkx/remove-binding-optimization-2
[ConstraintSystem] Remove an attempted optimization that we've not
2018-07-16 22:34:08 -07:00
Mark Lacey
c29f660652 [ConstraintSystem] Remove an attempted optimization that we've not
seen benefit from.

This was added at one point after the observation that it may in
theory allow us to solve constraint systems more quickly, but there
wasn't really a motivating test case and we do not know of any real
code that it helps with.

We currently have a problem in the solver in that we are both
short-circuiting evaluation of constraints systems, *and* do not have
a stable order that we visit disjunctions. These in combination can
result in inconsistent and unpredictable results, so I am moving to
enforce a stable order for visiting disjunctions, and that requires
this code to be removed.
2018-07-16 16:12:43 -07:00
Pavel Yaskevich
c997080283 Merge pull request #17980 from xedin/disable-diagnostics-for-codecompletion
[TypeChecker] Disable expression diagnostics for code completion
2018-07-16 16:08:56 -07:00
Mark Lacey
8b2b4a7a70 Small simplification resulting from using std::min_element. 2018-07-16 11:48:07 -07:00
Mark Lacey
6fa403dc7d [ConstraintSystem] Change the order in which we attempt disjunctions
to be stable.

We currently will stop visiting the elements of a disjunction under
certain circumstances once we have found a solution. The result we get
is inherently dependent on the order in which we determine to visit
the disjunctions themselves (in addition to the elements of the
disjunction).

This change makes the order in which we visit disjunctions
stable. Future commits will create a stable ordering for the elements
of disjunctions. Once we also have that stable ordering in place we
can in theory short circuit more often as part of changing the way in
which we decide what the "best" solution is to a system.

This results in an expression in
validation-test/stdlib/AnyHashable.swift.gyb no longer being able to
typecheck in a reasonable amount of time, so I had to tweak that
expression.
2018-07-16 09:32:14 -07:00
Mark Lacey
e82fcb8487 [ConstraintSystem] Move disjunction selection closer to where selected
disjunction is used.
2018-07-16 08:49:58 -07:00
Pavel Yaskevich
10ddb04613 [ConstraintSystem] Add SuppressDiagnostics/AllowUnresolvedTypeVariables flags
Instead of mixing flags between type-checker and constraint solver, let's
move the ones which are useful in constraint system there. Doing
so allows for `solveForExpression` to be moved from `TypeChecker` to
`ConstraintSystem` which consolidates solver logic.

It also allows to set these flags as part of constraint generation/solving,
which is sometimes important.
2018-07-15 23:23:45 -07:00
Mark Lacey
93dbb54e68 [ConstraintSystem] Add some counters helpful for understanding solver behavior. 2018-06-19 12:30:56 -07:00
Mark Lacey
14f3f3e08a Add a frontend option to disable the "shrink" part of the solver.
We sometimes see expression type checking times increase dramatically
when this is enabled, and having a way to disable will make it
possible to easily do measurements to determine the cost/benefit of
having this enabled.
2018-06-19 10:21:19 -07:00
Pavel Yaskevich
5bbd67cad0 Merge pull request #17170 from mdiep/remove-redundant-simplification
[Sema] Remove redundant simplification
2018-06-14 00:10:15 -07:00
Slava Pestov
296ce3f312 AST: Remove hack-around for getInterfaceType() on ParamDecl returning InOutType
Most callers did not want the InOutType here, and checked
the ParamDecl's flags instead.
2018-06-13 15:38:52 -07:00
Matt Diephouse
4d19d9f648 Remove redundant simplification
The call to `solveRec`, below, immediately performs this same check. While that doesn't result in an early return from `solve`, the effect appears to be the same.
2018-06-13 11:27:11 -04:00
Mark Lacey
ccd21718f4 Merge pull request #16911 from rudkx/minor-constraint-stuff
Minor constraint system stuff
2018-05-30 14:23:08 -07:00
Mark Lacey
656952af9d [ConstraintSystem] Add a way to get the elapsed time we've spent in a SolverScope. 2018-05-26 10:28:04 -07:00
Mark Lacey
1e4721df09 [ConstraintSystem] Move tracking of solver depth/states into SolverState.
Instead of doing this when scopes are created and destroyed, do this
when scopes are registered and rolled back on the SolverState.

NFC.
2018-05-25 16:06:47 -07:00
Mark Lacey
c35e50e63b [ConstraintSystem] Prefer disjunctions of bindings over other disjunctions. 2018-05-23 23:05:54 -07:00
Mark Lacey
b92649a013 [ConstraintSystem] Attempt to select disjunctions that split constraint systems.
When selecting the next disjunction to attempt, try to find one that
is a disjunction of bindings where the type being bound is the
converted-to type in a conversion constraint. Attempting these early
makes it possible to split constraint systems, eliminating exponential
behavior.

Fixes: rdar://problem/40344044
2018-05-23 16:52:43 -07:00