Commit Graph

875 Commits

Author SHA1 Message Date
Pavel Yaskevich
f70c43a028 Merge pull request #23085 from xedin/diag-OoO-arguments
[ConstraintSystem] Diagnose out-of-order arguments via fixes
2019-03-05 00:52:23 -08:00
Pavel Yaskevich
1d2c3633fb [ConstraintSystem] Fix out-of-order arguments
Detect and fix out-of-order arguments by moving them into correct
positions.
2019-03-04 20:03:48 -08:00
Pavel Yaskevich
5dd5454a75 [CSSimplify] Determine if argument is out-of-order while matching labels
Instead of rerouting out-of-order into re-labeling during diagnostics,
let's do that as part of the label matching algorithm.
2019-03-04 20:03:30 -08:00
swift-ci
5ec8f96fd3 Merge pull request #23077 from DougGregor/revert-common-type 2019-03-04 17:04:47 -08:00
Doug Gregor
2e2ba8fde7 [Constraint solver] Check labels of unresolved member references.
We don’t really allow overloading of case names based on labels, so we can’t
really test this, but we’re supposed to so I’ll fix the code ;)
2019-03-04 15:00:34 -08:00
Pavel Yaskevich
9c916fc2e5 Merge pull request #23072 from xedin/diag-closure-param-destructuring
[ConstraintSystem] Diagnose closure parameter destructuring via fixes
2019-03-04 14:46:11 -08:00
Pavel Yaskevich
8f85b848cc [ConstraintSystem] Fix closure parameter destructuring
Detect and fix closure parameter destructuring where
it's not currently allowed e.g. free standing closures
with contextual type `let _: ((Int, Int)) -> Void = { $0 + $1 }`
2019-03-04 11:02:15 -08:00
Doug Gregor
8151a34f6a [Constraint solver] Merge the two areConservativelyCompatibleArgumentLabels()
The decl-based version is only used by the OverloadChoice-based version
anyway.
2019-03-03 22:51:33 -08:00
Doug Gregor
c8d7059863 Merge pull request #23012 from DougGregor/apply-filter-disjunctions
[Constraint solver] Do argument label matching during apply simplification
2019-03-02 16:09:41 -08:00
Doug Gregor
7249c92c00 Use ErrorType as a sentinel type rather than Optional<Type> 2019-03-02 10:50:51 -08:00
Doug Gregor
603d5d6f20 [Constraint solver] Synchronize argument label setting/retrievable.
The walker that was setting argument labels was looking through ! and ?
postfix expressions, but the lookup code itself was not, leading to missed
opportunities for filtering based on argument labels. Generalize the
transformation that maps from the function expression down to the locator
for which we will retrieve argument labels.
2019-03-01 21:45:39 -08:00
Doug Gregor
233cf6ffa6 [Constraint solver] Address feedback from Pavel and Slava. 2019-03-01 20:54:48 -08:00
Doug Gregor
1b2b6f92e8 [Constraint solver] Restrict key path application to subscript[keyPath:].
Extend argument label matching to handle key path application choices,
which are accessed via subscript syntax with the argument labels “keyPath:”.
This gets us to the point where it’s possible to filter down to a single
subscript if there is no type-based overloading going on.
2019-03-01 09:43:37 -08:00
Doug Gregor
c6631ec83d [Constraint solver] Match call arguments for subscripts.
Record the argument labels provided to a subscript in the solver, and
use that to filter out subscript declarations with non-matching
argument labels during function application. This reduces the number of
overloaded subscript declarations that will be considered in later
steps in the solver, reducing the solution space.

*Disable* this optimization in the normal member-lookup path, which is
intended to go away in the near future. This limits the scope of the
change somewhat, so we can separately tackle the diagnostics issue.
The one diagnostics change here is probably an improvement, because
the user explicitly stated the argument labels, and is more likely
missing a conversion on the argument than having typed the wrong
label.
2019-03-01 09:18:53 -08:00
Doug Gregor
bdc961d8c6 [Constraint solver] Do argument label matching during apply simplification.
When simplifying a function application constraint, check the argument
labels for that application against the disjunction containing the overload
set, disabling any overloads with mis-matching labels. This is staging for
several different directions:

* Eliminating the argument label matching from performMemberLookup, where it
does not belong
* More aggressively filtering the overload set when we have some concrete
information about argument types
* Identifying favored constraints when we have some concrete information
about argument types

At present, the only easily-visible effect of this change is that
we now properly handle argument label matching for non-member functions.
2019-02-28 23:53:08 -08:00
Doug Gregor
9e5d8ee222 Merge pull request #22977 from DougGregor/constraint-solver-common-result-type
[Constraint solver] Compute common apply result type in the solver.
2019-02-28 23:48:17 -08:00
Doug Gregor
a11a14acf4 [Constraint solver] Add debug dumps + a test for common result types. 2019-02-28 09:49:50 -08:00
Pavel Yaskevich
846ae44a1f [CSSimplify] Implode parameters into a tuple through a type variable
There are cases where SE-0110 allows tuple splatting behavior,
so to aid diagnostics let's use a new type variable to represent
a tuple type formed from existing arguments instead of imploding
them directly.
2019-02-28 01:41:01 -08:00
Doug Gregor
5f99d91ea8 [Constraint solver] Compute common apply result type in the solver.
Constraint generation for function application expressions contains a simple
hack to try to find the common result type for an overload set containing
callable things. Instead, perform this “common result type” computation
when simplifying an applicable function constraint, so it is more
widely applicable.
2019-02-27 23:30:03 -08:00
Pavel Yaskevich
502e88deff [CSSimplify] Tuple splat should account for single dependent member parameters
12a65fffee restricted tuple splat
to a single tuple or type variable parameter, but it has to
support dependent member types as well because they could be
resolved to `Void` (or empty tuple).

Resolves: rdar://problem/48443263
2019-02-27 12:20:11 -08:00
Pavel Yaskevich
9d4116d46e [CSSimplify] NFC: Extract isSingleTupleParam and missing arguments fix from matchFunctionTypes 2019-02-26 18:50:49 -08:00
Pavel Yaskevich
c664ac0ed7 [CSSimplify] While attempting to synthesize missing arguments account for "implode" case
In situations like this:

```swift
func foo(_: (Int, Int) -> Void) {}
foo { $0.0 + $0.1 }
```

Parameters are expected to be a single tuple by mistake, to account
for that solver can generate N new arguments and bind a single existing
argument to tuple formed from them.
2019-02-26 12:03:18 -08:00
Pavel Yaskevich
1c54c5a08b [ConstraintLocator] Add special locator for synthesized arguments 2019-02-25 17:07:26 -08:00
Pavel Yaskevich
0b12c664b0 [ConstraintSystem] Fix missing arguments
While trying to match function types, detect and fix any missing
arguments (by introducing type variables), such arguments would
get type information from corresponding parameters and aid in
producing solutions which are much easier to diagnose.
2019-02-25 17:07:26 -08:00
Pavel Yaskevich
12a65fffee [CSSimplify] Further Restrict tuple splat behavior
`isSingleParam` used to return `true` regardless of type of
the identified single parameter, but splat only makes sense
if such type is a tuple or a type variable which could later
be resolved to tuple. Otherwise it makes it hard to diagnose
missing arguments.
2019-02-25 17:07:26 -08:00
Joe Groff
bb67cf815c Merge pull request #21355 from technicated/tuple-keypaths-2
Tuple KeyPaths
2019-02-25 12:56:05 -08:00
Suyash Srijan
34f8670d2a [CS] Use fixes to diagnose instance member on type (or vice versa) access (#21830)
This PR migrates instance member on type and type member on instance diagnostics handling to use the new diagnostics framework (fixes) and create more reliable and accurate diagnostics in such scenarios.
2019-02-22 16:57:26 -08:00
Pavel Yaskevich
3c9d62093f Merge pull request #22797 from xedin/diag-relabel-in-members
[Diagnostics] Improve argument labeling diagnostics
2019-02-22 00:25:36 -08:00
Pavel Yaskevich
d4b67bf3f7 [Diagnostics] Improve argument labeling diagnostics
Extend new labeling diagnostics (via fixes) to support
member references and subscripts.
2019-02-21 16:42:56 -08:00
Slava Pestov
6d19f7e0f4 Sema: Fix inconsistent behavior with SE-0110-related compatibility hack
Back when SE-0110 was implemented we decided that passing a function value
taking multiple parameters would be allowed where a function value taking
a single tuple argument was expected.

Due to quirks in the old function type representation, the "splat" in the
other direction sometimes worked too. When we redid the function type
representation we added a simulation of the old quirk for -swift-version 4
mode.

However this simulation was itself problematic because it only worked when
the function value being passed was a non-overloaded declaration reference.

Slightly broaden the hack to the overloaded case, to prevent user
confusion when adding or removing overloads.
2019-02-21 09:57:03 -05:00
Joe Groff
0cfca9496a Give opened archetypes a generic environment.
And maybe allow nested types to live on them.
2019-02-20 12:52:48 -08:00
Pavel Yaskevich
70b5bce791 [CSFix] Use fully qualified locators for requirement failures
Would help to diagnose failures where requirement comes from
contextual type, also simplifies logic around requirement fixes
to some degree.
2019-02-18 12:03:46 -08:00
technicated
d7324b977e Added more tests
Testing SILGen & IRGen tuple keypath generation
Added tuple element type check in SILVerifier
2019-02-18 10:19:42 +01:00
Andrea Tomarelli
ede47cafbd Partial AST & Sema implementation of TKP 2019-02-18 09:04:42 +01:00
Pavel Yaskevich
4f0f090e36 [CSDiagnostics] Use generic signature to retrieve failing requirement 2019-02-14 12:18:17 -08:00
Pavel Yaskevich
0d0c132ecd [Sema] NFC: Add accessors to check whether locator is type or conditional requirement 2019-02-08 15:04:44 -08:00
Pavel Yaskevich
6fd1600534 [ConstraintSystem] Diagnose conditional requirement failures via fixes
Extend existing `RequirementFailure` functionality to support
conditional requirement failures. Such fixes are introduced
only if the parent type requirement has been matched successfully.

Resolves: rdar://problem/47871590
2019-02-08 11:16:54 -08:00
Pavel Yaskevich
f2abfc547a [ConstraintSystem] Add requirement kind to conditional conformance requirement locator 2019-02-07 13:51:20 -08:00
Pavel Yaskevich
1d8cee9cb4 [ConstraintSystem] Detect invalid initializer references early
Currently invalid initializer references are detected and
diagnosed in solution application phase, but that's too
late because solver wouldn't have required information while
attempting to determine the best solution, which might result
in viable solutions being ignored in favour of incorrect ones e.g.

```swift
protocol P {
  init(value: Int)
}

class C {
  init(value: Int, _: String = "") {}
}

func make<T: P & C>(type: T.Type) -> T {
  return T.init(value: 0)
}
```

In this example `init` on `C` would be preferred since it
comes from the concrete type, but reference itself is invalid
because it's an attempt to construct class object using
metatype value via non-required initalizer.

Situations like these should be recognized early and invalid
use like in case of `C.init` should be ranked lower or diagnosed
if that is the only possible solution.

Resolves: rdar://problem/47787705
2019-02-05 10:25:36 -08:00
Pavel Yaskevich
462cb1ffb1 Merge pull request #22124 from xedin/diagnose-partial-applies
[CSDiagnostics] Diagnose invalid partial application
2019-01-28 10:44:56 -08:00
Pavel Yaskevich
1c79380a12 [CSFix] Couple of small cleanups related to ForceOptional
* Make sure that base and unwrapped types aren't null
* Don't allocate `ForceOptional` fix if nothing has been unwrapped
  in `simplifyApplicableFnConstraint`
* Add sugar reconstitution support to `FailureDiagnostic::resolveType`
* Format diagnostics a bit better
2019-01-26 00:48:01 -08:00
Pavel Yaskevich
b4fb25f66d Merge pull request #22050 from theblixguy/fix/SR-9201
[Diag] Fix incorrect diagnostic when unwrapping double optional
2019-01-25 23:07:09 -08:00
Suyash Srijan
614f72f85d [cs] use simplifyLocatorToAnchor and revert changes to some test diagnostic messages 2019-01-26 00:29:46 +00:00
Suyash Srijan
8845fcbbfe [cs] use anchor from locator when creating a ForceOptional fix 2019-01-25 21:41:05 +00:00
Suyash Srijan
6a0a1dec05 [cs] use anchor instead of locator, etc 2019-01-25 21:36:07 +00:00
Pavel Yaskevich
7d830cee8b [ConstraintSystem] Add a fix to detect invalid partial application
Currently supported only partial applications of instance methods
marked as `mutating`.
2019-01-25 13:29:11 -08:00
Suyash Srijan
76b8209b25 [cs] store base type and unwrapped type in the fix 2019-01-25 10:13:37 +00:00
Pavel Yaskevich
57a9d3fc6d [ConstraintSystem] Warning fixes shouldn't affect solution ranking 2019-01-21 01:07:56 -08:00
Slava Pestov
e99607c421 Sema: Use ConstraintKind::Bind where possible instead of ::Equal
Solving Bind is a little easier than Equal. The only remaining uses of Equal
are in the .member syntax and keypaths; if we can refactor those, we might be
able to simplify LValue handling in the type checker in general.
2019-01-14 14:55:16 -05:00
Slava Pestov
52c1c8caaf Sema: Clean up solving BindParam constraint
- Avoid creating an unnecessary type variable
- Even if both sides are type variables we can solve them if the LHS cannot
  bind to an InOut or the RHS cannot bind to an LValue; in this case the two
  types are identical and we can merge them
2019-01-12 18:03:01 -05:00