Commit Graph

830 Commits

Author SHA1 Message Date
Pavel Yaskevich
0f9f4e99ce [ConstraintSystem] NFC: Move getOverloadChoice{IfAvailable} to Solution
Since information comes from `Solution` anyway, it's good to have
that logic localized, but it's also useful for diagnostics based on
fixes attached to solutions.
2018-08-03 20:50:54 -07:00
Pavel Yaskevich
f15e17a629 [Sema] NFC: reword "only concrete types can conform to protocols" diagnostic 2018-08-03 14:27:00 -07:00
Pavel Yaskevich
cfc5b97dc2 [ConstraintSystem] Move score kind for Fix before Unavailable
Any solution which doesn't require source changes should be considered
better than any other solution which does.

Otherwise solutions with fixes are always considered better than
solutions with unavailable overloads, which isn't correct especially
considering that different types of errors are now diagnosed via
forming solutions with fixes.
2018-08-02 16:40:58 -07:00
Pavel Yaskevich
29e34e66e7 [ConstraintSystem] Diagnose missing conformance requirements via "fixes"
If fixes are allowed let solver record missing protocol conformance
requirements and assume that `conformsTo` constraint is successfully
solved, this helps to diagnose such errors without involving
heavy-weight expression based diagnostics.

Resolves: rdar://problem/40537858
2018-08-02 16:40:34 -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
Pavel Yaskevich
f9c6ed54ed [Sema] NFC: Refactor getUnopenedTypeOfReference to accept callback for type 2018-07-28 20:28:41 -07:00
Pavel Yaskevich
d62be440ce [CSSolver] Split `getType(ValueDecl*) into three - getType{OrNull, OrInterfaceType} 2018-07-28 20:28:41 -07:00
Pavel Yaskevich
398abdfb7c [CSSolver] Add closure parameter type caching
While inferring avoid associating type variables with closure
parameters, use cache instead and only set types when everything
is properly type-checked, this avoids multiple problems one of
them - leaking type variables outside of constraint system they
belong to.
2018-07-28 20:28:41 -07:00
Mark Lacey
8f9fcaa275 Merge pull request #18325 from rudkx/minor-refactoring
[ConstraintSystem] Some small clean-ups to getFixedType, getFixedTypeRecursive, and simplifyType
2018-07-28 19:15:12 -07:00
Mark Lacey
b900b5df0b [ConstraintSystem] Tiny simplification of function. 2018-07-27 19:34:12 -07:00
Doug Gregor
d9c6fcfefa Merge pull request #18305 from DougGregor/constraint-solver-timer-perf
[Constraint solver] Reduce timer overhead associated with "expression too complex"
2018-07-27 17:11:28 -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
gregomni
5faa8bf4d1 Don't offer force-unwrap of the base as a possible fixit for optional
member access if optional chaining is sure to be valid.
2018-07-27 13:56:24 -07:00
Pavel Yaskevich
dfad872cea [ConstraintSystem] Attempt to apply fixes in AST walker order
This makes sure that the diagnostics appear in the stable order
which is closer to what users would expect e.g. evaluation
order, otherwise, because disjunctions are currently attempted
based on their size, ordering of error messages produced by
applying fixes is completely arbitrary.
2018-07-25 13:32:16 -07:00
Pavel Yaskevich
62eccd53ad [ConstraintSystem] Use fixes to diagnose missing argument labels
Let the solver disregard missing argument labels and record correct
ones, so such problem could be diagnosed later on iff there were no
other more serious failures.
2018-07-24 22:11:56 -07:00
Pavel Yaskevich
91e330c289 [TypeChecker] Improve argument label matching
* Improve label mismatch callback:
 - Split "missing label" callback into 3 - missing, extraneous, incorrect (with typo(s));
 - Allow label callbacks to indicate if it's a fatal error or not;
* Improve matching of the variadic parameters;
* Improve matching of the parameters with defaults;
* Try to look for an argument with matching label before fallback to
  forced claming (if allowed).
2018-07-21 23:21:42 -07:00
Mark Lacey
c0007f8168 Revert "[ConstraintSystem] Fix the ordering of functions with optional parame…" 2018-07-19 00:21:12 -07:00
Mark Lacey
186c2f251a [ConstraintSystem] Fix the ordering of functions with optional parameters.
Treat non-optional generic parameters as being more specialized than
optional generic parameters, and penalize any solutions that involve
generic arguments that are themselves Optional.

By doing these things, we can remove the special-cased code for the
two overloads of '??' in the stdlib, instead treating the (T?, T)
overload as better than the (T?, T?) overload except where a user
actually passes an optionally-typed value as the second parameter.

Fixes: rdar://problem/19748710
2018-07-18 11:43:44 -07:00
Mark Lacey
f826dbb06e [ConstraintSystem] Lift code attempting choices in a disjunction out
of solveSimplified.
2018-07-17 11:02:10 -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
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
Pavel Yaskevich
45634bd262 Merge pull request #17947 from xedin/rdar-42056741
[Diagnostics] Transfer previously resolved types directly from expressions
2018-07-14 12:14:42 -07:00
Pavel Yaskevich
11e1d1328d [ConstraintSystem] NFC: remove obsolete transferExprTypes 2018-07-13 20:13:41 -07:00
Doug Gregor
5db1901d57 [Type checker] Emit coalesce-or-force-unwrap Fix-Its for necessary unwraps more consistently.
Replace the last (and most obscure) use of the poor “use ‘?’ or ‘!’” diagnostic with the
new, more explanatory version that provides separate notes with Fix-Its for coalescing or
force-unwrapping the value.

Finishes rdar://problem/42081852.
2018-07-13 16:48:15 -07:00
Doug Gregor
e7eac0af22 [Type checker] Extend the diagnostics for unwrapping the base of a member access.
Introduce a new fix kind into the constraint solver to cover unwrapping the base
of a member access so we can refer to the a member of the unwrapped base.
Wire this fix kind to the just-added diagnostic that suggests either the
chaining ‘?’ or the force-unwrap ‘!’ via separate, descriptive Fix-Its.

Example:

error: value of optional type 'X?' must be unwrapped to refer to member 'f' of wrapped base type 'X'
  let _: Int = x.f()
               ^
note: chain the optional using '?' to access member 'f' only for non-'nil' base values
  let _: Int = x.f()
               ^
                ?
note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
  let _: Int = x.f()
               ^
                !

Before this, we would sometimes get a Fix-It for just ‘?’ and sometimes get a Fix-It for the
coalescing ‘??’, neither of which is likely to be right.

More work on rdar://problem/42081852.
2018-07-13 16:26:03 -07:00
Ding Ye
95b91ee953 Apply git-clang-format. 2018-07-11 15:26:56 +10:00
Ding Ye
4a05369b5a Improve interface of InputMatcher with some renaming and rephrasing;
split test cases into different files for different swift versions.
2018-07-11 15:26:56 +10:00
Ding Ye
9648371339 Extract some logic of matching parameters from isDeclAsSpecializedAs,
and reuse it to match parameters and arguments.
2018-07-11 15:26:56 +10:00
Slava Pestov
381483bd74 AST: Remove Expr's LValueAccessKind 2018-07-05 23:54:13 -07:00
Mark Lacey
bb339316a4 Revise the "too complex" heuristic.
Revise the heuristic so that it does not differ between Swift
versions, and so that it is always based on the number of scopes we've
opened.

The memory threshold and (very long) timer are also still in place as
well.
2018-07-01 19:40:21 -07:00
Mark Lacey
93dbb54e68 [ConstraintSystem] Add some counters helpful for understanding solver behavior. 2018-06-19 12:30:56 -07:00
Matt Diephouse
456f69e01f Add root type constraint between KeyPath expressions and applications 2018-06-13 12:38:46 -04:00
Joe Groff
3b227e9928 Merge pull request #17066 from jckarter/defer-let-inout-bug-2
DI: Consider capture of `let`s to be a read-only use.
2018-06-11 14:24:26 -07:00
Joe Groff
711984234d Sema: Pass the useDC down to getTypeOfReference.
This fixes a subtle issue where, during single-expression closure type inference, we would ask for the settability of local variables from the outer function's context, leading us to mistakenly consider them mutable inside single-expression closure contexts. DI would catch some but not all violations of the expected semantics here.
2018-06-11 10:53:00 -07:00
Mark Lacey
d135daae44 [ConstraintSystem] Honor -solver-memory-threshold if present.
If the user specifies a memory threshold on the command-line, try to
honor that value and consider expressions too complex if we end up
allocating more memory than they specify.

Fixes rdar://problem/40952582 (aka https://bugs.swift.org/browse/SR-7525).
2018-06-08 17:38:52 -07:00
Robert Widmann
6585c92395 Merge pull request #16935 from CodaFi/mos-def
[NFC] Refactor default argument info
2018-06-04 14:57:31 -07:00
Pavel Yaskevich
a22b360294 Merge pull request #16903 from xedin/fix-constrainted-expr-typealias
[CSSolver] Make sure generic requirements are checked for typealiases
2018-06-01 11:17:34 -07:00
Pavel Yaskevich
d57330975a [CSSolver] Make sure generic requirements are checked for typealiases
If solver encounters a typealias inside of constrainted extension
make sure to add its requirements to the constraint system, otherwise
it might produce invalid solutions.
2018-06-01 00:23:36 -07:00
Robert Widmann
24abf3ea09 [NFC] Refactor default argument info
Refactor the interface to return a bit vector. Along the way, fix up
the callers and remove some dead usages of the defaults information
that were copied and pasted around Sema.
2018-05-31 17:28:04 -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
31f2617054 NFC. Move paired methods together in a header file.
They are used together - move the implementations together.
2018-05-25 16:06:47 -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