Commit Graph

1364 Commits

Author SHA1 Message Date
Hamish Knight
c6b6e72aac [CS] Tighten up assertions for getCalleeDeclAndArgs
Assert that we have a correct locator and that we
recorded argument information for it, rather than
returning no information.

In addition, always return the callee locator,
even if there is no callee.
2020-01-08 13:38:59 -08:00
Luciano Almeida
4d982f3430 [CSSimplify] Do not record fix to coerce with existential restriction 2020-01-08 07:07:49 -03:00
Luciano Almeida
fc49af2949 [CSSimplify] Handle coercion to wrong type for function result locator 2020-01-08 07:07:49 -03:00
Luciano Almeida
0e1a03dc61 [CSSimplify] Handle optional wrong type conversion 2020-01-08 07:07:49 -03:00
Luciano Almeida
06201a64be [Sema] Diagnose wrong type coercion involving metatypes 2020-01-08 07:07:49 -03:00
Pavel Yaskevich
9a62701e95 [ConstraintSystem] Use new branch element and fix mismatch between ternary branches 2020-01-07 13:50:09 -08:00
Pavel Yaskevich
36fff23077 Merge pull request #29011 from LucianoPAlmeida/coercion-handle-contextual-mismatch
[Diagnostics] Handle CoerceExpr conversion failure in contextual mismatch
2020-01-06 11:31:12 -08:00
Holly Borla
94bbb8f76e [ConstraintSystem] Finish porting unresolved member reference failures.
This covers member failures where the error is at the declaration, so
the result of member lookup is "already diagnosed".
2020-01-05 11:33:02 -08:00
Luciano Almeida
f145264fc7 [tests] Fix parser recover tests 2020-01-05 00:23:15 -03:00
Luciano Almeida
533d9acf73 [CSSimplify] Fallback to contextual mismatch in repair failures for CoerceExpr 2020-01-04 15:54:46 -03:00
Doug Gregor
bbcaf8c669 [Type checker] Introduce value witness constraints.
Introduce a new kind of constraint, the "value witness" constraint,
which captures a reference to a witness for a specific protocol
conformance. It otherwise acts like a more restricted form of a "value
member" constraint, where the specific member is known (as a
ValueDecl*) in advance.

The constraint is effectively dependent on the protocol
conformance itself; if that conformance fails, mark the type variables
in the resolved member type as "holes", so that the conformance
failure does not cascade.

Note that the resolved overload for this constraint always refers to
the requirement, rather than the witness, so we will end up recording
witness-method references in the AST rather than concrete references,
and leave it up to the optimizers to perform devirtualization. This is
demonstrated by the SIL changes needed in tests, and is part of the
wider resilience issue with conformances described by
rdar://problem/22708391.
2020-01-02 12:06:23 -08:00
Pavel Yaskevich
b03b356bfa Merge pull request #28880 from xedin/port-multi-stmt-closure-diags
[Diagnostics] Diagnose inability to infer (complex) closure return type
2019-12-19 14:17:34 -08:00
Pavel Yaskevich
8bcc192591 [Diagnostics] Diagnose inability to infer (complex) closure return type 2019-12-19 12:16:30 -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
56265a26bf [CS] Resolve callees for key path dynamic members (#28807)
[CS] Resolve callees for key path dynamic members
2019-12-16 17:52:22 -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
Pavel Yaskevich
d77e34925f [ConstraintSystem] Lift a restriction on fixing of non-function calls on Any/AnyObject
Detect and diagnose situations where call is attempted directly on
`Any` or `AnyObject` or member calls with `AnyObject` base which
didn't match.
2019-12-13 22:50:04 -08:00
Pavel Yaskevich
a9106cafca [ConstraintSystem] Account for missing unwrap(s) in call to optional Objective-C members 2019-12-13 22:50:04 -08:00
Hamish Knight
f1e690c07e Merge pull request #28775 from hamishknight/dynamic-lookup-attr-req
Requestify hasDynamicMemberLookupAttribute for Sema too
2019-12-13 14:40:13 -08:00
Pavel Yaskevich
5ba2e59c63 Merge pull request #28752 from xedin/simplify-potential-binding
[ConstraintSystem] Record originator constraint for each type variable binding
2019-12-13 11:50:02 -08:00
Hamish Knight
36cecb4015 Requestify hasDynamicMemberLookupAttribute for Sema too
Previously we had a request for this in
IDETypeChecking, but this wasn't used for queries
made from Sema. Move the request into Sema, and
move `hasDynamicMemberLookupAttribute` onto
TypeBase.
2019-12-13 11:04:00 -08:00
Pavel Yaskevich
fb764969c0 Merge pull request #28770 from xedin/rdar-57843297
[Diagnostics] Upon keypath result contextual mismatch try to match ob…
2019-12-13 10:12:27 -08:00
Pavel Yaskevich
47c7b9b910 [Diagnostics] Upon keypath result contextual mismatch try to match object types
If there was a mismatch between last component type and contextual
key path result type, let's try to re-match the types with all optionals
stripped off. In cases where the problem is optionality difference
e.g. `[Int] vs. [Int]?` that propagates contextual information to
the last component which facilitates better diagnostics.

Resolves: rdar://problem/57843297
2019-12-13 00:50:54 -08:00
Pavel Yaskevich
f259286bd7 [CSFix] Convert missing explicit @escaping fix to be a contextual mismatch
Sometimes diagnostic needs both sides of the conversion e.g.
when there is an attempt to bind generic argument to non-escaping type.
2019-12-12 12:42:08 -08:00
Holly Borla
3d1ab4da67 Merge pull request #28712 from hborla/function-parameter-mismatch-diagnostics
[ConstraintSystem] Port function parameter type mismatch diagnostics.
2019-12-11 14:33:07 -08:00
Holly Borla
51c7c8c8f1 [ConstraintSystem] Port function parameter type mismatch diagnostics. 2019-12-11 10:45:52 -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
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
Holly Borla
50abedd45c [Diagnostics] Keep track of the indices of the tuple elements whose
types do not match in AllowTupleTypeMismatch/TupleContextualFailure.
2019-12-09 11:04:34 -08:00
Pavel Yaskevich
3d7306a066 Merge pull request #28630 from xedin/dynamic-member-diagnostics
[Diagnostics] Port/Improve diagnostics for `@dynamicCallable` and `callAsFunction`
2019-12-09 10:24:27 -08:00
Pavel Yaskevich
61b7b3b28d Merge pull request #28626 from xedin/rdar-57668763
[ConstraintSystem] Fix a case of too eager force optional unwrap with…
2019-12-06 17:10:56 -08:00
Pavel Yaskevich
21a8b3c57d [Diagnostics] Port tailored diagnostics for missing dynamicallyCall methods 2019-12-06 16:43:18 -08:00
Pavel Yaskevich
328143ad4d [ConstraintSystem] Align @dynamicCallable argument locators with regular calls
Having the same locators for `@dynamicCallable` and the regular calls
make it much easier to produce diagnostics.
2019-12-06 16:43:18 -08:00
Pavel Yaskevich
08baf67677 [ConstraintSystem] Fix a case of too eager force optional unwrap with optional contextual type
If return of optional chaining is assigned to an optional type
or discarded there should be no force optional unwrap attempt
on it because type variable associated with context can be
bound to optional of any depth.

Resolves: rdar://problem/57668873
2019-12-06 15:03:19 -08:00
Holly Borla
f9a1ab28f4 [ConstraintSystem] Port tuple type mismatches to the new framework 2019-12-06 13:12:57 -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
cafa338ae3 Merge pull request #28594 from xedin/rdar-50420029
[ConstraintSystem] Guard against infinite recursion in key path dynam…
2019-12-05 14:34:10 -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
d8997c6223 Merge pull request #28573 from xedin/remove-closure-handling-from-csdiag
[Diagnostics] Port last remaining closure expression diagnostics
2019-12-05 11:37:22 -08:00
Pavel Yaskevich
bbe0c098ba [ConstraintSystem] Avoid member lookup if base type is a "hole"
Member lookup on a "hole" is not going to produce any results
and it makes sense to detect early and short-circuit the constraint.
2019-12-04 14:23:12 -08:00
Hamish Knight
66afe772d5 [CS] Fix resolution of key path component callees (#28569)
[CS] Fix resolution of key path component callees
2019-12-04 13:43:07 -08:00
Hamish Knight
7e1a963cce [CS] Fix resolution of key path component callees
Previously we were just searching for a resolved
overload with the same component index and anchor
for the key path. However unfortunately that found
dynamic member lookup overloads in certain cases,
leading to an incorrect mutability capability.

Change the logic such that it uses the callee
locator for a given key path component, ensuring
we only match against the "direct" callee, and
not any dynamic members it might be also referring
to.

Resolves SR-11896.
2019-12-04 11:47:35 -08:00
Pavel Yaskevich
5cacd1bb36 [ConstraintSystem] Fix situations when contextual base type can't be inferred
It might be either impossible to infer the base because there is
no contextual information e.g. `_ = .foo` or there is something
else wrong in the expression which disconnects member reference
from its context.
2019-12-03 12:07:16 -08:00
Pavel Yaskevich
8b1debf907 [ConstraintSystem] Detect contextual type mismatches associated with optional evaluation 2019-12-03 12:07:16 -08:00
Pavel Yaskevich
918ff24767 [ConstraintSystem] Repair type mismatches between function types
If it couldn't be determined precisely what is the structural
difference between two function types, let's still repair the
mismatch by ignoring contextual type.
2019-12-03 12:07:16 -08:00
Pavel Yaskevich
15c58d19d5 [ConstraintSystem] Detect passing array to variadic argument in function conversions
Initially this problem was only detected and diagnosed for calls.
So let's extend it to function conversions as well e.g.:

```swift
func foo<T>(_: [T]) {}
func bar<T>(_ f: (T...) -> ()) {}

bar { foo($0) }
```
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
Pavel Yaskevich
adf83fe9d5 [ConstraintSystem] Fix single tuple vs. N arguments in function conversions 2019-12-03 12:07:15 -08: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