Commit Graph

998 Commits

Author SHA1 Message Date
Greg Titus
c95cfc6f69 Merge pull request #18950 from gregomni/rvalue-as-lvalue
[Diagnostics] Adding assignments directly to CS and diagnosing from there.
2018-08-26 11:12:57 -07:00
Pavel Yaskevich
ea62075766 [ConstraintSystem] NFC: Move diagnoseAmbiguity methods from CSDiag to ConstraintSystem` 2018-08-24 23:18:49 -07:00
gregomni
821f63fe98 Make assignments and assignment failure diagnoses directly in the CS.
More specific diagnoses for assigning to read-only keypaths.
'computeAssignDestType' is dead code now.
ConstraintFix shouldRecordFix()
2018-08-24 20:39:03 -07:00
Pavel Yaskevich
16fc3117cc [ConstraintSystem] Diagnose ambiguities related to solutions with fixes
If all of the solutions in the set have a single fix, which points
to the common anchor, attempt to diagnose the failure as an
ambiguity with a list of candidates and their related problems as notes.

Having richer message like that helps to understand why something is
ambiguous e.g. if there are two overloads, one requires conformance
to some protocol and another has a same-type requirement on some type,
but neither matched exactly, having both candidates in the diagnostic
message with associated errors, instead of simplify pointing to related
declarations, helps tremendously.
2018-08-24 11:20:49 -07:00
Pavel Yaskevich
cc436e313a [Diagnostics] Decouple FailureDiagnostic from Solution 2018-08-21 23:45:17 -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
Greg Titus
8f41ee7750 Merge pull request #18324 from gregomni/opty2
[Sema] More unwrap fixits
2018-08-14 09:12:35 -07:00
Pavel Yaskevich
ebb9f86bee [ConstraintSystem] NFC: Remove obsolete Fix struct
Also clean up `ConstraintSystem` interface from the storage
supporing `Fix` such as missing types, decl names, conformances etc.
2018-08-13 18:10:40 -07:00
Pavel Yaskevich
e631a37ef6 [ConstraintSystem] Replace Fix with ConstraintFix throughout solver 2018-08-13 18:10:27 -07:00
gregomni
36cf24fb9e When we diagnose an unwrap, if the expression being unwrapped is a sole reference to a local let/var, and the local's type is inferred, offer fixits on the initializer as well. In this position we can also reasonably offer 'guard let'. Since we're identifying the implicitly typed initializer now, we can give a specific explanation of how IUOs get turned into optional types with the new IUO implementation.
Pass constraint system down into offering force unwrap fixits so that we can identify the type of the last member chosen for an optional chain. If there's a chain and the last member's return type isn't optional, then it's cleaner to offer to change that last '?' into a '!' to perform the force, rather than parenthesize the whole expression and force the result.
2018-08-12 12:57:20 -07:00
Pavel Yaskevich
a564042fdc [Diagnostics] Port missing explicit conversion to new abstraction 2018-08-09 17:01:54 -07:00
Pavel Yaskevich
0bd682ef82 Merge pull request #18512 from xedin/refactor-fix-diagnostics-into-class
[ConstraintSystem] Add new FailureDiagnostic abstraction
2018-08-06 18:35:22 -07:00
Mark Lacey
6ccc2acb06 [ConstraintSystem] Remove disjunction number as we're not currently
using it.

It was added to use for selecting the order we visit disjunctions, but
this order turned out to not be great (and I don't think there are
simple variations on the creation order, like reverse order), that
will work well either.
2018-08-06 16:00:26 -07:00
Pavel Yaskevich
776485878f [ConstraintSystem] NFC: Move new diagnostics into separate files - Diagnostics.(h|cpp) 2018-08-06 13:08:47 -07:00
Pavel Yaskevich
bda60b4ea2 [Diagnostics] NFC: Reword FailureDiagnostic::diagnose comment 2018-08-04 17:10:16 -07:00
Pavel Yaskevich
dee221c199 [Diagnostics] Add emitDiagnostic method to FailureDiagnostic
Instead of having to obtain type-checker instance through
constraint system, let's have `emitDiagnostic` do that and
forward all of the argument for easy access.
2018-08-04 17:01:46 -07:00
Pavel Yaskevich
d201e552e5 [Diagnostics] Move re-labeling diagnostic to use new abstraction 2018-08-04 16:52:45 -07:00
Pavel Yaskevich
5750b07daa [ConstraintSystem] Add new FailureDiagnostic abstraction
Aim of this new diagnostic abstraction is to encapsulate each
individual failure into its own class with some shared base.
Good example of this - diagnostics related to generic requirement
failures, where each kind (conformance, same-type etc.) has
some specific logic e.g. diagnostic message but the all share
the same traits like affected declaration/requirement.
2018-08-04 11:25:54 -07:00
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