Commit Graph

751 Commits

Author SHA1 Message Date
Pavel Yaskevich
2dccdbfabf [ConstraintSystem] NFC: Remove workarounds related to (now deprecated) CSDiag 2020-02-18 10:13:09 -08:00
Pavel Yaskevich
b905113f5c [ConstraintSystem] Remove now completely obsolete CSDiag 2020-02-18 09:12:56 -08:00
Pavel Yaskevich
0c451bb2a9 [Diagnostics] Diagnose ambiguities related to ephemeral pointers
Diagnose ambiguity related to overloaded declarations where only
*some* of the overload choices have ephemeral pointer warnings/errors
associated with them. Such situations have be handled specifically
because ephemeral fixes do not affect the score.

If all of the overloads have ephemeral fixes associated with them
it's much easier to diagnose through notes associated with each fix.
2020-02-17 16:09:11 -08:00
Luciano Almeida
a32e3f4598 [docs] Updating TypeChecker.rst 2020-02-16 18:41:57 -03:00
Luciano Almeida
6c617f9718 [ConstraintSystem] Removing check related to ArgumentMismatch in CSDiag. 2020-02-16 16:51:41 -03:00
Puyan Lotfi
b707b7f0b3 Fixing build breaks for master-next against latest llvm.org.
There were changes due to the StringRef to std::string conversion, changes
in the Debug Info DIBuilder::createModule API, and a drop in the using for
PointerUnion4 since PointerUnion is now a variadic template and will do in its
place.
2020-02-13 14:12:21 -08:00
Pavel Yaskevich
355148dbe8 Merge pull request #29746 from hborla/ambiguity-with-fixes
[Diagnostics] Refactor diagnoseAmbiguityWithFixes.
2020-02-13 02:42:43 -08:00
Pavel Yaskevich
172c2003ea [Diagnostics] NFC: Add a comment about special handling of opaque result types 2020-02-13 00:54:51 -08:00
Pavel Yaskevich
b872bdfca1 [Diagnostics] Replace llvm::find_if with llvm::any_of in diagnoseAmbiguityWithFixes 2020-02-13 00:45:44 -08:00
Pavel Yaskevich
60a210b657 [ConstraintSystem] NFC: Fix a couple of typos in comments 2020-02-13 00:44:20 -08:00
Pavel Yaskevich
3f10bfa74e [Diagnostics] NFC: Rename diagnoseConflictingArguments into diagnoseConflictingGenericArguments 2020-02-12 18:17:10 -08:00
Pavel Yaskevich
af65c0e2f3 [Diagnostics] Prioritize contextual type mismatch other ambiguities 2020-02-12 17:55:32 -08:00
Pavel Yaskevich
5437622d2d [Diagnostics] Diagnose ambiguity with conflicting arguments to generic parameters
It's done by first retrieving all generic parameters from each solution,
filtering boundings into distrinct set and diagnosing any differences.

For example:

```swift
func foo<T>(_: T, _: T) {}
func bar(x: Int, y: Float) {
  foo(x, y)
}
```
2020-02-12 17:53:31 -08:00
Robert Widmann
054d7b9913 Merge pull request #29713 from CodaFi/unused-unwanted-unloved
[Gardening] Silence Some Warning Spew
2020-02-11 15:46:16 -08:00
Holly Borla
d1f6b3e2ef [Diagnostics] When diagnosing an ambiguous overload, don't mention "call"
if the expression is not a function application.
2020-02-11 14:53:27 -08:00
Holly Borla
1a628f3107 [Diagnostics] Simplify logic in diagnoseAmbiguityWithFixes for emitting
the ambiguity diagnostic by combining a few special errors into one.
2020-02-11 14:53:27 -08:00
Holly Borla
651c27b50b [Diagnostics] Add CSFix::diagnoseForAmbiguity for diagnosing common
fixes that appear in all solutions.
2020-02-11 14:53:27 -08:00
Holly Borla
54706ba79b [Diagnostics] Simplify diagnoseAmbiguityWithFixes by removing AmbiguityKind. 2020-02-11 14:53:27 -08:00
Holly Borla
607c298493 [Diagnostics] Refactor diagnoseAmbigutiyWithFixes to use the differences between
solutions in order to figure out the source of ambiguity.
2020-02-11 14:52:41 -08:00
Pavel Yaskevich
b3590c5f1d Merge pull request #29734 from LucianoPAlmeida/remove-diag-parameters-errors
[Diagnostics] Remove `FailureDiagnosis::diagnoseParameterErrors` from CSDiag
2020-02-11 01:32:31 -08:00
Luciano Almeida
46092aff3e [tests] Adjusting tests under type/opaque 2020-02-10 07:48:34 -03:00
Luciano Almeida
449ab7383f [ConstraintSystem] Disambiguate cases of argument/param mismatches involving generic functions 2020-02-09 21:19:01 -03:00
Doug Gregor
d70c055888 [Constraint system] Sink more init logic into SolutionApplicationTarget
More steps toward eliminating ExprTypeCheckListener.
2020-02-07 22:46:05 -08:00
Robert Widmann
d2360d2e8c [Gardening] dyn_cast -> isa 2020-02-07 16:09:31 -08:00
Doug Gregor
36366bc3e4 [Constraint solver] One SolutionApplicationTarget instance to rule them all.
Capture the peculiarities of contextual types vs. types used to generate
conversion constraints, as well as the behavior of “optional some” patterns
as used by if let / while let, within SolutionApplicationTarget. This allows
us to use a single target throughout setup / solving / application, rather
than mapping between two similar-but-disjoint targets.
2020-02-03 22:02:21 -08:00
Doug Gregor
9278fb8c22 [Constraint system] Eliminate TypeCheckExprFlags::ConvertTypeIsOpaqueReturnType
We can compute this information based solely on the SolutionApplicationTarget,
so do it.
2020-02-02 23:41:24 -08:00
Doug Gregor
52da2d6c4c [Constraint system] Extend SolutionApplicationTarget with an init pattern.
Initializer expressions are always type checked against a pattern, so also
include the pattern in the solution application target and use that to
compute the contextual type from the pattern type.
2020-02-02 22:31:27 -08:00
Doug Gregor
3b761dcae1 [Constraint system] Add a SolutionApplicationTarget-based typeCheckExpression
Rework most of typeCheckExpression() to use SolutionApplicationTarget,
folding more information into that data structure and sinking more
expression-checking behavior down into the more general solver and
solution-application code.
2020-02-01 23:46:13 -08:00
Doug Gregor
133439dcbb [Constraint solver] Request contextual type information per expression.
When requesting information about the contextual type of a constraint
system, do so using a given expression rather than treating it like
the global state that it is.
2020-01-23 11:46:17 -08:00
Doug Gregor
8283a67648 Revert "Revert "Reimplement function builders as statement transformations."" 2020-01-21 10:07:20 -08:00
Doug Gregor
86c13d3c74 Revert "Reimplement function builders as statement transformations." 2020-01-17 15:52:49 -08:00
Doug Gregor
bfa6d7316d [Function builders] Fake Expr-based locators for now.
The right solution is to extend the notion of the "anchor" of a locator
to also cover statements (and TypeReprs, and Patterns, and more), so
this is a stop-gap.
2020-01-16 13:19:21 -08:00
Doug Gregor
3a51d5b9b2 [WIP] Reimplement function builders as statement transformations. 2020-01-16 13:18:33 -08:00
Pavel Yaskevich
8269522f86 Merge pull request #28837 from xedin/rdar-56340587
[ConstraintSystem] Delay constraint generation for single-statement closure body
2020-01-16 00:29:11 -08:00
Pavel Yaskevich
d318b5d0f6 [ConstraintSystem] Fix getArgumentExpr to check number of tuple elements before access
Fix `getArgumentExpr` to not assume that constraint system
always asks for index that exists in an argument tuple,
because sometimes arguments could be synthesized (such
arguments do not have corresponding expression).

Resolves: rdar://problem/56221372
2020-01-14 17:44:32 -08:00
Pavel Yaskevich
0aadb7c6a5 [CSDiag] NFC: Move findResolvedMemberRef to ConstraintSystem.cpp
This method is used by diagnostics and CSApply at this point.
2020-01-14 12:51:58 -08:00
Pavel Yaskevich
cf2cad0cd5 [ConstraintSystem] Add more information retrieval callbacks to getCalleeLocator
`getCalleeLocator` has to be able to:

- Retrieve type for given expression via `getType`;
- Simplify given type via `simplifyType`; and
- Retrieve a selected overload choice for a given locator via `getOverloadFor`.
2020-01-14 00:09:33 -08:00
Pavel Yaskevich
8f68a68c70 [ConstraintSystem] Augment getCalleeLocator with getType callback
This is necessary for ambiguity diagnostics because none of the
solutions are applied back to the constraint system which means
that `getCalleeLocator` needs an ability to query information
from different sources e.g. constraint system and/or solution.
2020-01-14 00:09:32 -08:00
Pavel Yaskevich
66fe1ec2b2 Merge pull request #29053 from xedin/port-ternary-diags
[Diagnostics] Detect and diagnose ternary branch type mismatches
2020-01-08 00:27:32 -08:00
Holly Borla
43712bb860 [Diagnostics] Diagnose general ambiguity failures in diagnoseAmbiguityWithFixes. 2020-01-07 15:05:54 -08:00
Pavel Yaskevich
e19ef090b4 [ConstraintSystem] Add a new locator element to denote branches of ternary operator
`TernaryBranch` with a boolean flag to identify "then" (true) or
"else" (false) branches of the ternary operator expression.
2020-01-07 09:11:37 -08:00
Holly Borla
475b5591ed Merge pull request #28979 from hborla/ambiguous-call-diagnostics
[ConstraintSystem] Start to allow diagnosing ambiguity with fixes for solution sets with more than one fix.
2020-01-03 08:49:30 -08:00
Holly Borla
9e73bb3176 [ConstraintSystem] Start to allow diagnosing ambiguity with fixes
for solution sets with more than one fix.
2020-01-02 23:48:16 -08:00
Hamish Knight
40d11716f7 [CS] Use custom locator element for callAsFunction
Introduce a `ImplicitCallAsFunction` locator path
element to represent an implicit member reference
to `callAsFunction`. Then adjust CSApply a little
to check whether it's finishing an apply for a
callable type, and if so build the implicit member
access.
2019-12-18 11:43:45 -08:00
Hamish Knight
cefc03f0e2 [CS] Resolve callees for key path dynamic members
Change the locator for the applicable fn
constraint for the inner subscript reference in an
implicit `outer[dynamicMember: \Inner.[0]]` expr
such that it uses the member locator with a
KeyPathDynamicMember element.

Then add a case to `getCalleeLocator` to handle
these locators. We also need to handle this
specially in `getArgumentInfoLocator` due to the
fact that the argument labels for the inner
subscript reference correspond to those written
by the user for the outer subscript reference.

Resolves SR-11933.
Resolves rdar://problem/57824025.
2019-12-16 10:04:24 -08:00
Brent Royal-Gordon
7543a89cc4 Merge pull request #27683 from brentdax/i-understood-that-reference
[NFC] Distinguish references to names from declarations of those names by type
2019-12-11 10:50:57 -08:00
Brent Royal-Gordon
6a8598a99c [NFC] Remove DeclNameRef staging calls 2019-12-11 00:55:18 -08:00
Brent Royal-Gordon
addbe3e5ed [NFC] Thread DeclNameRef through most of the compiler
This huge commit contains as many of the mechanical changes as possible.
2019-12-11 00:55:18 -08:00
Hamish Knight
bea99b194b [CS] Attempt to simplify a member constraint immediately
Now that overload binding for dynamic member
lookup occurs after having recorded the
`subscript(dynamicMember:)` overload, we can
attempt simplification of this constraint right
away.
2019-12-10 18:02:15 -08:00
Hamish Knight
58884002d8 [CS] Don't adjust opened types of @dynamicMemberLookup overloads
Rather than adjusting the opened types for choices
referring to `subscript(dynamicMember:)` down to
the result type, only use the result type to
bind the overload type variable. This avoids the
need for a couple of special cases in CSApply.

To facilitate this change, add
`ConstraintSystem::bindOverload`, which deals with
adding the necessary constraints to bind the
overload's type variable. The eventual goal here
is to remove `adjustTypeOfOverloadReference`, with
adjustments to the opened type being moved to
`getTypeOfMemberReference`, and the adding of
constraints being moved to `bindOverloadType`.
2019-12-10 18:02:14 -08:00