Commit Graph

827 Commits

Author SHA1 Message Date
Mark Lacey
289b97134b Ensure we account for force unwrapping in scoring solutions.
This disappeared in the rework of IUOs but is needed when we have
multiple potential solutions involving different sets of overloads or
type bindings.

Fixes rdar://problem/37475971.
2018-04-11 11:45:31 -07:00
Sho Ikeda
4ba2303163 Merge pull request #15706 from ikesyo/sema-using-over-typedef
[gardening][Sema] Replace `typedef` with `using`
2018-04-04 19:34:13 +09:00
Mark Lacey
72f4b3d3b8 NFC: Minor cleanup to make createTypeVariable options default to zero.
Many (perhaps most?) calls to createTypeVariable explicitly pass 0 for
options. This change just defaults the parameter to 0 and removes all
the explicit 0's in the code.
2018-04-03 10:19:38 -07:00
Sho Ikeda
3c399de5bd [gardening][Sema] Replace typedef with using 2018-04-03 22:12:48 +09:00
Pavel Yaskevich
4aad9322c1 Merge pull request #15581 from apple/remove-narrow-perf-hack
[CSSolver] Remove tuple-to-tuple narrow perf hack
2018-03-29 00:22:19 -07:00
David Zarzycki
d4fd608ac9 Merge pull request #15580 from davezarzycki/remove_majority_of_TVO_CanBindToInOut
[Sema] Remove unneeded uses of TVO_CanBindToInOut
2018-03-28 18:32:26 -04:00
Pavel Yaskevich
641b80b861 [CSSolver] Remove tuple-to-tuple narrow perf hack
Don't try to short-circuit disjunctions if one of the choices
produced tuple-to-tuple conversion since that doesn't mean
that there are no other choices out there.
2018-03-28 14:02:43 -07:00
David Zarzycki
c8e17157af [Sema] Remove unneeded uses of TVO_CanBindToInOut 2018-03-28 14:25:13 -04:00
Pavel Yaskevich
298bf2aed4 [CSBindings] Cleanup literal binding inference
Don't attempt to store literal bindings directly to `PotentialBindings`
since they might get superseded by non-literal bindings deduced from
other constraints, also don't attempt to check literal protocol conformance
on type variables or member types since such types would always end-up
returning trivial conformance which results in removal of viable literal types.

Resolves: rdar://problem/38535743
2018-03-27 22:51:37 -07:00
Pavel Yaskevich
fc93edbc96 [CSSolver] Attempt unavailable overloads only in "diagnostic" mode
Such overloads are not going to result in viable solutions anyway,
so it makes sense to attempt them only if solver failed to deduce
proper solution.

Helps to improve type-checking performance of operators which have
multiple unavailable overloads for compatibility reasons.
2018-03-21 18:17:22 -07:00
Mark Lacey
587fde5262 In -debug-constraints, only attempt to print types that we've cached.
Calling getType() when the type is not in the cache results in an
assert.
2018-02-22 12:58:35 -08:00
Mark Lacey
50b189bf1b [ConstraintSystem] Print cached expr types when debugging constraint solver. 2018-02-15 15:21:28 -08:00
Mark Lacey
37009b0d8b [ConstraintSystem] Remove constraint propagation.
The current implementation isn't really useful in the face of generic
overloads. It has never been enabled by default, and isn't useful to
keep around if it is disabled. If we ever want to bring it back,
we know where to look!
2018-02-12 21:30:39 -08:00
Pavel Yaskevich
3b7e555c7e [CSSolver] Fix performance regression related to contraction of closure parameters
Improve situation around closure parameter/argument contractions
by allowing such action if it can be proved that none of the bindings
would result in solver attempting to bind parameter to `inout` type.

Resolves: rdar://problem/36838495
2018-01-31 14:21:14 -08:00
Mark Lacey
ba2da1da62 IUO: Check score for fixes before skipping generic overloads.
If a prior solution required fixes, do not skip generic
overloads. They might result in a fix-free solution.

Suggested by @xedin as an adjunct to a similar change I made for
short-circuiting disjunctions.
2018-01-04 17:01:27 -08:00
Mark Lacey
d3b6d24d80 IUO: Do not short-circuit disjunctions if we had to apply fixes.
There are cases where disjunctions created for IUOs can be solved with
the Optional choice if a fix is applied. We do not want to stop with
this solution as we may be able to solve the constraint system without
a fix by selecting the non-Optional side.

I have opened a JIRA, SR-6626, to investigate one small regression in
diagnostics with this change.
2018-01-04 15:36:34 -08:00
Pavel Yaskevich
5d5872bb83 [CSBindings] Avoid binding type variables to collection types directly
Instead of binding collection types directly let's try to
bind using temporary type variables substituted for element
types, that's going to ensure that subtype relationship is
always preserved.

Resolves: rdar://problem/35541153
2017-12-01 23:04:19 -08:00
Pavel Yaskevich
b56786fc03 Merge pull request #12986 from xedin/rdar-35540159
[CSSolver] Prune disjunction choices based on their equivalence class
2017-11-17 13:05:04 -08:00
Pavel Yaskevich
b16add7685 [CSSolver] Prune disjunction choices based on their equivalence class
There are situations where we know equivalence relationship between
multiple disjunctions, let's prune dependent choice space based on
choice picked for the parent disjunction.

Resolves: rdar://problem/35540159
2017-11-16 19:35:14 -08:00
Pavel Yaskevich
7b121de1a0 [CSRanking] Change ranking to weight overload choices in evaluation order
Consider different overload choices for the same location in evaluation
order, this makes overload resolution more predictable because it's going
to follow expression bottom-up, that prevents situations when some
expressions are considered ambigious because choices taken further up
equate the score, instead each level is given distinct weight
based on evaluation order.

Resolves: rdar://problem/31888810
2017-11-16 13:38:24 -08:00
Pavel Yaskevich
03a39337a5 [ConstraintSolver] Add debug logging of failed constraints while solving 2017-10-04 12:13:38 -07:00
Pavel Yaskevich
80e4a2226b [ConstraintGraph] Don't try to contract edge of parameter bindings with inout attribute
Currently edge related to the parameter bindings is contracted
without properly checking if newly created equivalence class has
the same inout & l-value requirements. This patch improves the
situation by disallowing contraction of the edges related to parameter
binding constraint where left-hand side has `inout` attribute set.

Such guarantees that parameter can get `inout` type assigned when
argument gets `l-value` type.

Resolves: rdar://problem/33429010
2017-09-22 17:23:12 -07:00
Pavel Yaskevich
c8fad863c4 [ConstraintSolver] NFC: Refactor PontentialBindings to reference type variable they belong to 2017-09-16 23:35:44 -07:00
Pavel Yaskevich
3792ada50b [ConstraintSolver] Attempt literal bindings earlier
If the best bindings we could get on the current step are bindings
to literal type without any other type variable involved, let's try
to attempt them right away, that should help to prune search space.
2017-09-16 23:28:00 -07:00
Robert Widmann
87c5f199fb Merge pull request #11760 from CodaFi/inout-knockout
[NFC] Scale back more uses of InOutType
2017-09-07 13:25:58 -04:00
Pavel Yaskevich
9d3a8584b4 [ConstraintSolver] NFC: Integrate type-check timeout timer into shrinking phase
To bound the amount of time shrinking is allowed to run, it has to be
integrated with timeout timer allocated for base constraint system.
2017-09-06 19:08:49 -07:00
Robert Widmann
abce63a1b3 [NFC] Scale back more uses of InOutType 2017-09-05 21:56:58 -04:00
Mark Lacey
c63e279966 [Constraint system] Allow the solver to bind collection literal types earlier.
When this kicks in it can result in substantially speeding up type
inference for collection literals.
2017-08-29 00:39:19 -07:00
swift-ci
fc8c1e3b89 Merge pull request #11632 from xedin/conversion-propagation 2017-08-28 18:34:38 -07:00
Pavel Yaskevich
562608bad8 [ConstraintSolver] Apply explicit coercions early to prune search space
When dealing with explicit coercions apply their conversions
early to avoid searching for solutions with incorrect types,
and therefore prune search space.
2017-08-28 17:42:05 -07:00
Pavel Yaskevich
8bf03b5c43 [ConstraintSolver] Add Component class as an isolated "solvable" unit
Move disjunction selection logic one level up from the `solveSimplified`
which allows to simplify its logic and avoid collecting disjunctions
multiple times for each solver step.

Sort constraint components/buckets based on how many disjunctions
they have, that helps to prune some of the branches with incorrect
solutions early which limits overall depth of the search.

Resolves: SR-4714
2017-08-28 13:39:29 -07:00
Pavel Yaskevich
47353c25e2 [ConstraintSolver] Skip performance hacks in presence of unavailable overloads
Limit the scope of the performance hacks which currently exist in the
solver even further by disallowing it to skip generic overlaods or stop
in case when previous solutions involve unavailable overloads, which
otherwise might lead to producing incorrect overall solutions.
2017-08-21 14:55:17 -07:00
Pavel Yaskevich
25988e5d26 [ConstraintSolver] NFC: Remove outdated comment about Swift 3 mode behavior 2017-08-18 11:43:54 -07:00
Pavel Yaskevich
7a1bae85ae [ConstraintSolver] NFC: refactor candidate solver to use constraint system arena
While shrinking we have to allocate containers for the reduced domains
for some of the candidates, it's currently done using permanent arena
of the `ASTContext` allocator. This patch changes candidate solver to
use arena associated with the parent constraint system, which significantly
limits lifetime of domain containers.
2017-08-14 12:44:38 -07:00
Mark Lacey
9e7b5b22db Remove -swift-version 3 checks for "expression too complex".
This was initially added to avoid "expression was too complex" in a
case where we were not previously reporting it for -swift-version 3
but should have been. In retrospect this seems misguided since
although we would not like to regress on "too complex" expressions, we
really don't want to silently continue in the cases where we decide an
expression is "too complex", but where we have a solution that we
could use. It's better to fail.
2017-08-03 20:33:07 -07:00
Doug Gregor
1e3bd76b75 [Constraint solver] Teach checkTypeOfBinding() to avoid dependent member types.
We don't want to explore these bindings anyway, so reject them earlier.
2017-07-12 12:51:24 -07:00
Pavel Yaskevich
78aa1e0cd6 [ConstraintSolver] Fix shrink to use correct primary expression as a candidate
When trying to identify candidates for shrinking we are missing the case
when apply expression is a source of the assignment operator, which leads
to incorrect results in some situations, because shrink is going to miss
some required contextual information about assignment.

Resolves: rdar://problem/33190087
2017-07-10 12:28:54 -07:00
Mark Lacey
7cd4102d01 [Constraint system] Begin refactoring type variable binding selection.
Split out the code for selecting potential bindings into a separate file
as a first step before refactoring it for improved clarity and ease of
modification.
2017-07-09 10:29:42 -07:00
Robert Widmann
957d633185 Rename getInOutOrLValueObjectType to getWithoutSpecifierType
Prepares the AST for a future in which more than just inout and
@lvalue need to be stripped off of ephemeral types.
2017-07-06 09:35:04 -07:00
Pavel Yaskevich
71c2c1e44a Merge pull request #10484 from xedin/rdar-32726044
[ConstraintSolver] Use a flag to prevent solver from removing possible solutions
2017-06-22 14:41:55 -07:00
Pavel Yaskevich
6231f85be9 [ConstraintSolver] Use a flag to prevent solver from removing possible solutions
In some situations e.g. while trying to shrink domains of the type
variables before attempting search, use a flag to tell constraint
system to retain all of the viable solutions otherwise solver could
loose some of the information required to produce complete solution.

Resolves: rdar://problem/32726044
2017-06-22 00:11:32 -07:00
Mark Lacey
fb593f5404 Merge pull request #10475 from rudkx/time-out-solver
Update determination of "too complex" expression to take time into account.
2017-06-21 20:51:27 -07:00
Mark Lacey
e51e3e4bd4 Update determination of "too complex" expression to take time into account.
By default, end expression type checking after the elapsed process time
is more than 60 seconds for the current expression. This threshold can
be overridden by using -solver-expression-time-threshold=<seconds>.

Resolves rdar://problem/32859654
2017-06-21 16:26:34 -07:00
Mark Lacey
05e79e6b02 Refactor how the expression type checker timer is set up.
Preparation for adding the ability for the expression type checker to be
halted after a period of time.
2017-06-21 14:18:25 -07:00
Pavel Yaskevich
c46e3e83e8 [QoI] Improve diagnostics for single argument calls with trailing closures
Calls involving single trailing closure arguments require special
handling because we don't have as much contextual information
about function/argument types as in with regular calls, which means
that diagnosing such situations only by `visitApplyExpr`
yields subpar results.

Resolves: SR-4836.
2017-06-21 11:26:38 -07:00
Pavel Yaskevich
3781877b93 [ConstraintSystem] Track conformance checking done while solving to validate solution
Track outcomes of `conformsToProtocol` calls in `simplifyConformanceConstraints`
to be able to validate conformances when solution is formed to avoid returning
solutions with nominal types with invalid conformances to protocols.
2017-06-15 14:18:36 -07:00
Robert Widmann
abd5aa8e6d Rename some X-Value-related entities
* Rename coerceToMaterializableValue to coerceToRValue

* Rename isLValueType to hasLValueType to better match the
intended semantics of the member.
2017-06-14 13:18:45 -07:00
Mark Lacey
65e338ea4a [Constraint solver] Do not allow unavailable decls to be favored.
There is a short-circuiting hack in the constraint solver that speeds up
solving, but isn't generally sound. If we allow unavailable decls to be
considered "favored", this can fire and result in our choosing a
solution that involves the unavailable decl where other solutions exist.

Fixes rdar://problem/32570734.
2017-06-06 13:38:36 -07:00
Pavel Yaskevich
9a4255e4bf Merge pull request #9717 from xedin/rdar-32034560
[ConstraintSystem] Prevent `shrink` from solving "too complex" sub-expressions
2017-06-01 21:47:47 -07:00
Pavel Yaskevich
1bc7a1edb9 [ConstraintSolver] Skip generic overloads only if non-generic choices produce higher score solutions
Restrict skipping of the generic overloads only to the situations
when non-generic solution doesn't have any restrictions/fixes, because
there is a possibility that generic overload could produce a better
solution.

Resolves: rdar://problem/32204609.
2017-06-01 14:43:43 -07:00