Commit Graph

733 Commits

Author SHA1 Message Date
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
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
Hamish Knight
73098687b0 [CS] Pass SelectedOverload in a couple of places (#28649)
[CS] Pass SelectedOverload in a couple of places
2019-12-10 11:13:46 -08:00
Hamish Knight
54bfa59348 [CS] Suppress a no-asserts warning 2019-12-09 15:27:58 -08:00
Holly Borla
edb4e70d66 Merge pull request #28600 from hborla/tuple-mismatch-diagnostics
[ConstraintSystem] Port tuple type mismatch diagnostics
2019-12-09 13:26:34 -08:00
Pavel Yaskevich
b0d01de99a [ConstraintSystem] Add a special locator element for implicit @dynamicCallable calls 2019-12-06 16:43:18 -08:00
Holly Borla
1e013a02cf [ConstraintSystem] Move FailureDiagnostic::getFunctionArgApplyInfo
into `ConstraintSystem`.
2019-12-06 15:43:39 -08:00
Hamish Knight
8a83440ce1 [CS] Resolve callees for callAsFunction ".member" exprs
Apply the same checks as ApplyExprs to
UnresolvedMemberExprs in getCalleeLocator to
resolve callees in cases where they're used with
`callAsFunction` in addition to a weird edge case
where we currently allow them with constructor
calls, e.g:

```
struct S {
  static let s = S.self
}

let x: S = .s()
```

Arguably we should be representing ".member()"
expressions with an UnresolvedMemberExpr + CallExpr,
which would avoid the need to apply these special
cases, and reject the above syntax for not using
an explicit ".init". Doing so will likely require
a bit of hacking in CSGen though.

Resolves SR-11909.
2019-12-06 11:21:37 -08:00
Hamish Knight
a97328dcbf [CS] Use a MapVector to cache resolved overloads
Rather than maintaining a linked list of overload
choices, which must be linearly searched each time
we need to lookup an overload at a given callee
locator, use a MapVector which can be rolled back
at the end of a scope.

Remove ResolvedOverloadSetListItem in favor of
using SelectedOverload, which avoids the need to
convert between them when moving from
ConstraintSystem to Solution.
2019-12-05 14:47:52 -08:00
Pavel Yaskevich
1d393ebdd4 [ConstraintSystem] Guard against infinite recursion in key path dynamic member lookup
It's possible to construct subscript member responsible for key path
dynamic member lookup in a way which is going to be self-recursive
and an attempt to lookup any non-existent member is going to trigger
infine recursion.

Let's guard against that by making sure that the base type of the
member lookup is different from root type of the key path.

Resolves: rdar://problem/50420029
Resolves: rdar://problem/57410798
2019-12-05 12:42:17 -08:00
Pavel Yaskevich
3116d6ef8a Merge pull request #28539 from xedin/remove-constraint-handling-from-csdiag
[Diagnostics] Port diagnostics related to ambiguities and constraints
2019-12-04 12:15:26 -08:00
Pavel Yaskevich
1be60a7c56 [ConstraintSystem] NFC: While diagnosing operator ambiguity use Identifier::is to compare names 2019-12-04 10:40:20 -08:00
Varun Gandhi
e7be41d0cb Merge pull request #27479 from varungandhi-apple/vg-track-clang-function-types
Track Clang function types in the AST
2019-12-04 08:47:35 -08:00
Pavel Yaskevich
ebdb5c7776 [ConstraintSystem] Improve handling of ambiguities related to fixes
Solutions passed to `diagnoseAmbiguityWithFixes` aren't filtered
so we need to remove all of the solutions with the score worse
than overall "best". Also logic has to account for some fixes being
"warnings".
2019-12-03 12:07:16 -08:00
Pavel Yaskevich
34f5b52db1 [Diagnostics] Diagnose ambiguities related to contextual type mismatch
If none of the candidates produce expected contextual type, record
all of the posibilities to produce a note per and diagnose this as
contextual type mismatch instead of a reference ambiguity.
2019-12-03 12:07:15 -08:00
Pavel Yaskevich
a9f11445c0 [Diagnostics] Diagnose an attempt to assign a value to an overloaded name
Example:

```swift
struct X {
}

func X(_: Int) -> Int {
  return 42
}

X = 42
```
2019-12-03 12:07:15 -08:00
Slava Pestov
3aa70827e0 Merge pull request #28465 from zoecarver/feature/variadic-args-key-path-subscript
Fix variadic args in key path subscript
2019-12-02 21:35:53 -05:00
Hamish Knight
bf0e9c727d [CS] Resolve callees for implicit callAsFunction
Add a case to getCalleeLocator to return the
appropriate locator for a call to an implicit
callAsFunction member reference.

Resolves SR-11386 & SR-11778.
2019-12-02 15:29:21 -08:00
Hamish Knight
a014f15e75 [CS] Enforce that withPathElement is called on an lvalue
Locator builders keep a pointer to their underlying
locator, so it's not generally sound to extend an
rvalue locator builder.

This commit enforces that withPathElement is called
on an lvalue, and adds a couple more overloads of
getConstraintLocator to make it more convenient to
extend locators with multiple elements.
2019-11-27 17:13:50 -08:00
zoecarver
c19f3cefec Remove silgen changes and use getParameterType in CSApply 2019-11-26 00:07:31 -08:00