Commit Graph

15871 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
Slava Pestov
aeb894f36c Merge pull request #29898 from slavapestov/self-but-not-self
Sema: Prefer an outer type named 'Self' over the SE-0068 behavior
2020-02-18 12:32:17 -05:00
Pavel Yaskevich
b905113f5c [ConstraintSystem] Remove now completely obsolete CSDiag 2020-02-18 09:12:56 -08:00
Slava Pestov
eaee6faa00 Sema: Prefer an outer type named 'Self' over the SE-0068 behavior
This fixes a recent source break. We need to perform the normal
unqualified lookup before we handle the special case of 'Self',
because there might be a type named Self defined in an outer
context.

Fixes <https://bugs.swift.org/browse/SR-12133> / <rdar://problem/59216636>
2020-02-17 22:24:40 -05:00
Slava Pestov
0555de5469 Sema: Remove a couple of calls to clearLookupCache()
Tests seem to pass without these.

Two calls still remain, in ModuleDecl::addFiles() and removeFiles().
It will take a bit more refactoring to eliminate those.
2020-02-17 21:49:02 -05:00
Pavel Yaskevich
81c3f62638 [CSGen] Validate presence of _MaxBuiltinFloatType before generating constraints for float literals 2020-02-17 16:09:11 -08:00
Pavel Yaskevich
3edefea8d3 [ConstraintSystem] Don't attempt to solve closures with error expressions inside
Problem(s) which caused `ErrorExpr` to be added to AST should be
diagnosed already and solver wouldn't be able to produce a viable
solution in such case anyway.
2020-02-17 16:09:11 -08:00
Pavel Yaskevich
15036bcead [ConstraintSystem] Fix unwrap optional base fix to preserve l-valueness of a member type 2020-02-17 16:09:11 -08:00
Pavel Yaskevich
8722530943 [CSDiag] NFC: Move diagnoseDeprecatedConditionalConformanceOuterAccess to CSApply 2020-02-17 16:09:11 -08:00
Pavel Yaskevich
2565d418c7 [ConstraintSystem] NFC: Remove obsolete CalleeCandidateInfo 2020-02-17 16:09:11 -08:00
Pavel Yaskevich
81addcc8c3 [CSDiag] NFC: Remove visitApplyExpr and associated logic 2020-02-17 16:09:11 -08:00
Pavel Yaskevich
ca91a1bee0 [ConstraintSystem] Detect and diagnose OoO arguments in call to binary functions/operators
Identify problems like:

```swift
func foo(_ x: Int, _ y: String) {}

func bar(a: Int, b: String) {
  foo(b, a) // Instead of `foo(a, b)`
}
```

Where arguments are out-of-order and repair it by using OoO fix on the
parent locator.
2020-02-17 16:09:11 -08:00
Pavel Yaskevich
e17df6bcdf [CSGen] Don't try to infer closure types with destructured parameters
If one of the parameters represents a destructured tuple
e.g. `{ (x: Int, (y: Int, z: Int)) in ... }` let's fail
inference and not attempt to solve the constraint system because:

a. Destructuring has already been diagnosed by the parser;
b. Body of the closure would have error expressions for
   each incorrect parameter reference and solver wouldn't
   be able to produce any viable solutions.
2020-02-17 16:09:11 -08:00
Pavel Yaskevich
df21cbf85c [ConstraintSystem] Ignore attempt to bind type var to dependent member with incorrect base
Just like in cases where both sides are dependent member types
with resolved base that can't be simplified to a concrete type
let's ignore this mismatch and mark affected type variable as a hole
because something else has to be fixed already for this to happen.
2020-02-17 16:09:11 -08:00
Pavel Yaskevich
79b757d3cd [ConstraintSystem] Detect and diagnose mismatches in single parameter function conversions
When there is a conversion from e.g. `(A) -> Void` to `(B) -> Void`
matching between `A` and `B` is going to have a special locator which
doesn't end in `TupleElement`, so `repairFailures` has to account
for that and fix it just like regular argument mismatch.

Resolves: rdar://problem/59066040
2020-02-17 16:09:11 -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
Pavel Yaskevich
f6b7df161c [ConstraintSystem] Increase impact of a missing conformance related to stdlib type
Prioritize type mismatches over conformance failures when stdlib
types are involved because it wouldn't be appropriate to suggest
to add such a conformance, so the problem is most likely related
to something else e.g. other overload choice has a better fix.

Consider following example:

```swift
struct S {
  init(_: Double) {}
  init<T: BinaryInteger>(_: T) {}
}

_ = S(Double("0"))
```

In cases like that it's better to prefer failable initializer
which takes a `String` and returns `Double?` and diagnose a
problem related to missing optional unwrap instead of missing
conformances related to a `String` argument of other `Double`
initializer just because it returns a concrete type.
2020-02-17 16:09:11 -08:00
Pavel Yaskevich
bb656e120d [CSFix] Teach getStructuralTypeContext about tuple initialization calls 2020-02-17 16:09:11 -08:00
Pavel Yaskevich
802e141be9 [Diagnostics] Diagnose mismatches related to use of === and !== via a tailored fix 2020-02-17 16:09:11 -08:00
Pavel Yaskevich
0a8de8bda8 [ConstraintSystem] Allow simplifyRestrictedConstraintImpl to diagnose contextual failures with optionals
Since `simplifyRestrictedConstraintImpl` has both parent types and
does nested type matching it's a good place to diagnose top-level
contextual problems like mismatches in underlying types of optionals.
2020-02-17 16:09:11 -08:00
Suyash Srijan
d62411535b [CSSimplify] Guard against null locator in isSelfRecursiveKeyPathDynamicMemberLookup (#29886) 2020-02-17 21:28:44 +00:00
Pavel Yaskevich
48f24b02d6 Merge pull request #29866 from xedin/rdar-57356196
[CSApply] Always use `String` type for ObjC interop key path
2020-02-17 10:50:31 -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
Pavel Yaskevich
4b2b436033 Merge pull request #29845 from omochi/trailing-closure-position
[ConstraintSystem] Accept trailing closure if multiple defaulted parameters after last function parameter
2020-02-15 19:50:08 -08:00
omochimetaru
252e82ff7b [ConstrainySystem] Accept trailing closure if multiple...
defaulted parameters are after last function parameter
2020-02-16 07:48:39 +09:00
Suyash Srijan
a0d3542d08 [Typechecker] Covariant subscript check must also take into consideration that there may be a type mismatch (#29828) 2020-02-15 12:52:53 +00:00
Pavel Yaskevich
ae79b0d0bd [CSApply] Always use String type for ObjC interop key path
If it's possible to build an Objective-C key path for key path
expression make sure that its implicitly generated string literal
expression has a `String` type.

Resolves: rdar://problem/57356196
2020-02-15 00:04:09 -08:00
Holly Borla
c0d936ec8d [Sema] Implement type checking for the typeEraser attribute. 2020-02-14 17:47:23 -08:00
Jonas Devlieghere
784006911b Merge pull request #29822 from plotfi/master
Fixing build breaks against latest llvm.org (that can go into master).
2020-02-13 22:58:20 -08:00
Robert Widmann
1f867edfd4 Merge pull request #29833 from CodaFi/do-the-cupid-shuffle
[Sema] Warn About Tuple Shuffles
2020-02-13 19:33:55 -08:00
Varun Gandhi
d58bf546be [Diagnostics] Improve diagnostics for implicit (un)tupling. (#28076)
Fixes rdar://problem/56436226.
2020-02-13 17:38:21 -08:00
Robert Widmann
a9e871a0b1 [Sema] Warn About Tuple Shuffles
Emit a warning that tuple shuffling is deprecated across the board. In
the future, we should try to unshuffle these expressions where we can,
but that's a diagnostic improvement for another day.

See also https://forums.swift.org/t/deprecating-tuple-shuffles-round-2/16884/30
2020-02-13 17:29:03 -08: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
Doug Gregor
72d29cfcab [Constraint solver] Remove performance hacks for pattern type computation.
We shouldn't need these.
2020-02-13 13:28:36 -08:00
Doug Gregor
5e28c7c886 [Constraint System] Move bindVariablesInPattern into the constraint system.
This general notion of wiring up the types of variables that occur
within a pattern to the types in the produced pattern type is useful
outside of function builders, too.
2020-02-13 10:51:26 -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
Slava Pestov
aa417c306b Merge pull request #29793 from slavapestov/small-misc-cleanups
Small miscellaneous cleanups
2020-02-13 00:04:24 -05:00
Doug Gregor
08315b102d Merge pull request #29786 from DougGregor/function-builders-let-decls
Allow initialized let/var declarations in function builders.
2020-02-12 20:50:28 -08:00
Doug Gregor
d4cd5e0ebc Merge pull request #29801 from DougGregor/constraint-solver-rewrite-target
[Constraint system] Factor out application to a SolutionApplicationTarget
2020-02-12 20:24:41 -08:00
Luciano Almeida
968a37d221 [Diagnostics] Tailored diagnostic message for conditional downcast involving literals that can be statically coerced 2020-02-13 01:04:15 -03:00
Pavel Yaskevich
3f10bfa74e [Diagnostics] NFC: Rename diagnoseConflictingArguments into diagnoseConflictingGenericArguments 2020-02-12 18:17:10 -08:00
Pavel Yaskevich
4d5c676ca9 [ConstraintSystem] NFC: Remove obsolete code related to fixes from Solution 2020-02-12 17:57:36 -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
Doug Gregor
2347829324 [Constraint System] Allow initialized let/var declarations in function builders.
Introduce support for initialized let/var declarations within function
builder closures, e.g.,

    let (a, b) = c()

We generate constraints for the declarations as elsewhere, but the types of
the declared variables (a and b in this case) are bound to the type of the
pattern by one-way constraints, to describe the flow of type information
through the closure.

Implements rdar://problem/57330696.
2020-02-12 17:51:48 -08:00
Doug Gregor
7f9029071d [Constraint system] Adopt rewriteTarget for function builder transform.
When applying a function builder to a closure to produce the final,
type-checked closure, use the new rewriteTarget() so it’s performed on
a per-target basis. Use this to eliminate some duplicating in the handling
of return types.
2020-02-12 17:51:47 -08:00