Commit Graph

1475 Commits

Author SHA1 Message Date
Hamish Knight
aa0ad55706 [CS] Don't leave key path with holes unsolved
We currently leave a key path constraint unsolved
if one of its components hasn't yet had its
overload resolved. However, for e.g a missing
member component, the overload type variable will
be bound to a hole and an overload will never be
resolved.

Tweak the logic to consider the key path constraint
trivially solved if one of its components has been
marked as a hole, which will allow the key path
type itself to be marked as a hole.

Resolves SR-12437 & SR-12823.
Resolves rdar://62201037.
2020-05-16 16:52:35 -07:00
Pavel Yaskevich
d111f119d8 [ConstraintSystem] Detect and diagnose inability to infer type of closure parameter(s)
Detect situation when it's impossible to determine types for
closure parameters used in the body from the context. E.g.
when a call closure is associated with refers to a missing
member.

```swift
struct S {
}

S.foo { a, b in } // `S` doesn't have static member `foo`

let _ = { v in } // not enough context to infer type of `v`

_ = .foo { v in } // base type for `.foo` couldn't be determined
```

Resolves: [SR-12815](https://bugs.swift.org/browse/SR-12815)
Resolves: rdar://problem/63230293
2020-05-15 01:14:30 -07:00
Robert Widmann
2bca013457 Move "isDebugMode" into ConstraintSystem
This eliminates the final source of mutation of the TypeCheckerFlags on the ASTContext.
2020-05-13 09:13:44 -07:00
Artem Chikin
8aceb03858 Merge pull request #31716 from artemcm/UnlabeledKeypathFix
[Type-checker] Improve diagnostic for keypath used without 'keyPath:' label
2020-05-13 06:17:26 -07:00
Artem Chikin
97e32abc3c Improve diagnostic for keypath used without 'keyPath:' label 2020-05-12 15:58:11 -07:00
Luciano Almeida
02c454c976 [Diagnostics] Diagnose that we cannot infer the key path type when binding to a hole 2020-05-11 18:08:40 -03:00
Artem Chikin
3abb0bd6eb Merge pull request #31563 from artemcm/TypeCheckKeypathAsClosure
Add IgnoreContextualType fix on Keypath -> Function type mismatch.
2020-05-07 09:11:05 -07:00
Pavel Yaskevich
156066997a Merge pull request #31600 from xedin/rdar-62428353
[Diagnostics] Diagnose passing r-value without `&` to `inout` paramet…
2020-05-07 00:05:10 -07:00
Artem Chikin
7aed042817 Add fix on Keypath -> Function with multiple arguments type mismatch.
When simplifying a keypath constraint with a function type binding, single-parameter functions have the parameter type and the return type matched against the keypath root and value; whereas multiple-parameter functions cause an ambiguous failure (in `simplifyKeyPathConstraint`).

Resolves rdar://problem/57930643
2020-05-06 19:15:08 -07:00
Pavel Yaskevich
595b198f8e [Diagnostics] Diagnose passing r-value without & to inout parameter as mutability problem
If argument is immutable, with or without explicit `&`, let's
diagnose that as mutability problem because suggesting
to add `&` to immutable declaration is not the best possible fix.

Resolves: rdar://problem/62428353
2020-05-06 13:13:16 -07:00
John McCall
015d838441 Claim trailing closure arguments like we used to in error cases. 2020-05-06 01:56:40 -04:00
John McCall
882035f003 Implement the conservative option for typechecking multiple trailing closures.
The current approach for type-checking single trailing closures
is to scan backwards from the end of the parameter list, looking
for something that can be passed a closure.  This generalizes that
to perform label-matching in reverse on any later trailing closures,
then pick up from that point when trying to place the unlabeled
trailing closure.

The current approach is really not a good language rule, but changing
it as much as we'd really like will require evolution approval and a
source break, so we have to be cautious.
2020-05-06 01:56:40 -04:00
John McCall
a518e759d9 WIP for a different syntax for multiple trailing closures
that allows arbitrary `label: {}` suffixes after an initial
unlabeled closure.

Type-checking is not yet correct, as well as code-completion
and other kinds of tooling.
2020-05-06 01:56:40 -04:00
Pavel Yaskevich
191fcc49d3 Revert "[CS] Account for type variables when matching metatypes"
This reverts commit 84a3db45db.
2020-05-05 13:13:29 -07:00
Pavel Yaskevich
326b371e10 [ConstraintSystem] Switch auxiliary functions to use ASTNode instead of TypedNode 2020-04-29 17:03:45 -07:00
Robert Widmann
f9463922fd Merge pull request #31390 from CodaFi/tone-loc
Strip Out More TypeLocs
2020-04-29 16:46:00 -07:00
Pavel Yaskevich
6bdd534a9c [ConstraintSystem] Don't attempt property wrapper fixes for key path dynamic member lookup
If this is an attempt to fetch members through key path dynamic member lookup
let's not try to apply any property wrapper related fixes because modifying
base type would not change the result.

Resolves: [SR-12520](https://bugs.swift.org/browse/SR-12520)
Resolves: rdar://problem/61911108
2020-04-29 12:09:18 -07:00
Robert Widmann
5b3060318e [NFC] Strip ClosureExpr of its TypeLoc 2020-04-28 20:10:10 -07:00
Slava Pestov
742bd98402 Sema: Remove ConformanceCheckOptions::SkipConditionalRequirements
All callers can trivially be refactored to use ModuleDecl::lookupConformance()
instead. Since this was the last flag in ConformanceCheckOptions, we can remove
that, too.
2020-04-25 00:14:24 -04:00
Joe Groff
b4c7a7e85d Merge pull request #31224 from AnthonyLatsis/rename-getfullname-2
AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl
2020-04-24 12:51:28 -07:00
Pavel Yaskevich
4405768326 [ConstraintSystem] Refactor recordFix to no assume that non-augmenting fixes anchored on expressions 2020-04-23 12:01:05 -07:00
Pavel Yaskevich
4b1aa29149 [ConstraintSystem] NFC: Adjust all uses of locator anchors to work with TypedNode 2020-04-23 01:13:13 -07:00
Pavel Yaskevich
288e286efd Merge pull request #31192 from LucianoPAlmeida/SR-12425-diagnostics
[SR-12425] Improving diagnostics for key path application on non-convertible root type
2020-04-23 00:17:49 -07:00
Anthony Latsis
74252028ca AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl 2020-04-23 05:16:55 +03:00
Robert Widmann
78e07c1d41 Merge pull request #31159 from CodaFi/track-star
Remove Fallback Infrastructure For Evaluator-Based Dependencies
2020-04-22 15:37:48 -07:00
Luciano Almeida
f8cc9b52fe [tests] Adjusting SR-12425 diagnostics tests 2020-04-21 21:08:37 -03:00
Luciano Almeida
e17a934464 [CSSimplify] Recording fix for keypath application root type mismatch 2020-04-21 20:13:32 -03:00
Hamish Knight
c39c4e8aad [CS] Unify failed constraint recording
Rename `addNewFailingConstraint` to
`recordFailedConstraint`, and call into it
whenever a constraint fails, instead of setting
`failedConstraint`. This ensures that
`-debug-constraints` will always log the constraint
that failed a given scope.

In addition, introduce `retireFailedConstraint`
to cover the common case of retiring a constraint
that just failed.
2020-04-20 19:08:24 -07:00
Hamish Knight
f9c0d25c39 [CS] Deindent a few debug messages
The additional indentation implies that they're
taking place in a new solver scope, but this isn't
the case.
2020-04-20 19:08:24 -07:00
Hamish Knight
49ca2d0778 [CS] A couple of cleanups (#31155)
[CS] A couple of cleanups
2020-04-20 19:06:55 -07:00
Robert Widmann
48a5432cb7 [NFC] Remove ConformanceCheckFlags::InExpression
The last read of this bit was removed when the legacy referenced name tracker was deleted in the last commit.
2020-04-20 10:22:58 -07:00
Luciano Almeida
ab81236c8c [tests] Adding SR-12626 and SR-12425 test cases 2020-04-20 13:46:38 -03:00
Hamish Knight
44bd3fec2a [CS] Don't record a generated and retired constraint
Retired constraints get added back to the inactive
list when a scope rolls back, and generated
constraints then get removed. So adding a
constraint as both is unnecessary.

Also assert that `addNewFailingConstraint` doesn't
get called with an active constraint.
2020-04-20 08:50:56 -07:00
Luciano Almeida
6f3e2ee5dd [CSSimplify] Fail when try do simplify a key path application to a key path dynamicMemberLookup 2020-04-20 00:29:10 -03:00
Hamish Knight
78072de623 [CS] Assert that we don't end up with unsolved constraints
Make sure we don't end up in a situation where we
have unsolved constraints left over and consider
the system fully solved.

This requires tweaking the type matching code for
dependent members such that a concrete base is
considered a failure rather than being left
unsolved. This should only happen when not in
diagnostic mode, as otherwise we use a hole.
2020-04-10 10:16:08 -07:00
Hamish Knight
d69a42d656 [CS] Preserve compatibility for collection coercions
Previously we could allow some invalid coercions to
sneak past Sema. In most cases these would either
cause crashes later down the pipeline or
miscompiles. However, for coercions between
collections, we emitted somewhat reasonable code
that performed a force cast.

This commit aims to preserve compatibility with
those collection coercions that previously
compiled, and emits a warning telling the user to
use either 'as?' or 'as!' instead.
2020-04-10 10:16:07 -07:00
Hamish Knight
47541d86f7 [CS] Visit all fixed bindings for constraint re-activation
Start visiting transitive fixed bindings for type
variables, and stop visiting adjacencies for
`gatherConstraint`'s `AllMentions` mode.

This improves performance and fixes a correctness
issue with the old implementation where we could
fail to re-activate a coercion constraint, and
then let invalid code get past Sema, causing
either miscompiles or crashes later down the
pipeline.

Unfortunately this change requires us to
temporarily drop the non-ephemeral fix for a couple
of fairly obscure cases where the overload hasn't
yet been resolved. The logic was previously relying
on stale adjacency state in order to re-activate
the fix when the overload is bound, but it's not
connected on the constraint graph. We need to find
a way to connect constraints to unresolved
overloads they depend on.

Resolves SR-12369.
2020-04-10 10:16:07 -07:00
Hamish Knight
84a3db45db [CS] Account for type variables when matching metatypes
Previously we could prematurely attempt to perform
a bind of class metatypes without checking for
subtyping. Tweak the logic to not perform a bind
if we can't prove that we're dealing with non-class
types.
2020-04-10 10:16:06 -07:00
Hamish Knight
76881a39a5 [CS] Adjust applied overload simplification (#30716)
[CS] Adjust applied overload simplification
2020-04-07 19:04:27 -07:00
Pavel Yaskevich
bd44fb3ef3 Merge pull request #30838 from xedin/rdar-61347993
[ConstraintSystem] Don't bind result type of an empty closure too early
2020-04-07 10:40:12 -07:00
Pavel Yaskevich
04e2795a03 [ConstraintSystem] Don't bind result type of an empty closure too early
Instead of setting empty closure (`{}`) result type to be `Void`
while generating constraints, let's allocate a new type variable
instead and let it be bound to `Void` once the body is opened.

This way we can support an interaction with function builders which
would return a type different from `Void` even when applied to empty closure.

Resolves: rdar://problem/61347993
2020-04-06 15:55:55 -07:00
Hamish Knight
3339ea4f91 [CS] Fix invalid key path crasher
Previously we were bailing early on encountering
an optional chain in the key path. However this
could cause us to miss invalid components further
down the line. Instead, set a flag and force the
key path to be read-only if we encountered an
optional chain.

Resolves SR-12519.
2020-04-06 10:14:19 -07:00
Pavel Yaskevich
d922041ac5 Merge pull request #30740 from xedin/rdar-61084565
[ConstraintSystem] Don't include self-recursive dynamic member result…
2020-04-01 10:27:53 -07:00
Pavel Yaskevich
fdc535a691 [ConstraintSystem] Don't include self-recursive dynamic member results as "inaccessible"
Solver has to keep track of excluded dynamic member results while
performing lookup because otherwise, in diagnostic modem it might
include such results as inaccessible.

Resolves: rdar://problem/61084565
2020-03-31 16:20:20 -07:00
Pavel Yaskevich
f95cabb745 [ConstraintSystem] Allow sequence element mismatch fix to produce new holes
Type on the right-hand side of the element conversion/pattern match
should be allowed to have holes to be able to diagnose failures with
structurally incompatible types.

Resolves: rdar://problem/60832876
2020-03-30 17:48:46 -07:00
Hamish Knight
71882996ca [CS] Adjust applied overload simplification
Currently `simplifyAppliedOverloads` depends on
the order in which constraints are simplified,
specifically that a lookup constraint for a
function gets simplified before the applicable
function constraint. This happens to work out
just fine today with the order in which we
re-activate constraints, but I'm planning on
changing that order.

This commit changes the logic such that it it's no
longer affected by the order in which constraints
are simplified. We'll now run it when either an
applicable function constraint is added, or a new
bind overload disjunction is added. This also
means we no longer need to run it potentially
multiple times when simplifying the applicable fn.
2020-03-29 18:33:59 -07:00
Hamish Knight
ee3e694527 [CS] Explore additional bindings for fixes (#30686)
[CS] Explore additional bindings for fixes
2020-03-29 08:47:16 -07:00
Hamish Knight
b4c13c2c55 [CS] Adjust assessRequirementFailureImpact
- In `simplifyConformsToConstraint`, pass the LHS
type regardless of whether it is a type variable.

- Add the `choiceImpact` onto the impact for
adding a stdlib conformance.

- Treat Any and AnyObject as standard library
types.
2020-03-28 17:03:42 -07:00
Hamish Knight
dc4b089b9f [CS] Don't fix an _OptionalNilComparison argument
We should only be attempting such overloads for
nil literal args.

Resolves SR-12426.
2020-03-28 17:03:42 -07:00
Pavel Yaskevich
24bbce142f Merge pull request #30701 from LucianoPAlmeida/diagnose-key-path-refer-init
[Diagnostics] Diagnose key path referring to init method
2020-03-28 15:37:20 -07:00