Commit Graph

1106 Commits

Author SHA1 Message Date
Pavel Yaskevich
374a10c55f [ConstraintSystem] Overload choice should not be required to refer to declaration to have a fix
We should be able to attach fixes to overload choices that don't
refer to declarations e.g. keypath applications which refer to
`AnyObject` is a base type.
2019-04-12 14:54:37 -07:00
Pavel Yaskevich
34960788aa Merge pull request #23741 from xedin/verify-kp-subscript-hashable-via-solver
[CSSolver] Move keypath subscript index Hashable conformance verification to solver
2019-04-11 00:48:26 -07:00
Pavel Yaskevich
93f9cb1d2a [ConstraintLocator] Identify whether locator is a result of keypath dynamic member lookup or belongs to keypath subscript component 2019-04-10 13:51:19 -07:00
Pavel Yaskevich
c982706f0d [CSFix] Fix keypath subscript index to conform to Hashable 2019-04-10 13:51:04 -07:00
Slava Pestov
1c17ccfd3c AST: Add TypeBase::isNoEscape() 2019-04-09 15:02:14 -04:00
Pavel Yaskevich
16b65018b4 Merge pull request #23436 from xedin/keypath-dynamic-lookup
[SE-0252][TypeChecker] Keypath Dynamic Member Lookup
2019-04-05 00:10:53 -07:00
Slava Pestov
6bb36b5c01 Sema: Subscript default arguments
Fixes <https://bugs.swift.org/browse/SR-6118>.
2019-04-02 20:37:01 -04:00
Pavel Yaskevich
8f880545cd [TypeChecker] Add ReferenceWritableKeyPath support to keypath dynamic member lookup 2019-04-01 12:41:55 -07:00
Pavel Yaskevich
41f6eb9a15 [ConstraintSystem] Don't introduce implicit keypath choice for keypath dynamic member lookup 2019-04-01 12:41:55 -07:00
Pavel Yaskevich
d4bbcc1953 [TypeChecker] Add subscript support keypath dynamic member lookup 2019-04-01 12:40:39 -07:00
Pavel Yaskevich
2c82882b8f [ConstraintSystem] Move unviable keypath dynamic member check into performMemberLookup 2019-04-01 12:40:39 -07:00
Pavel Yaskevich
fb30555952 [ConstraintSystem] NFC: Extract check whether storage for keypath is read-only 2019-04-01 12:40:39 -07:00
Pavel Yaskevich
f95d9b092e [TypeChecker] Add new type of overload choice to support keypath dynamic lookup 2019-04-01 12:40:39 -07:00
Slava Pestov
b9ef5708e2 Sema: Simplify representation of vararg forwarding
VarargExpansionExpr shows up in call argument lists in synthesized
initializers and modify accessors when we need to forward arguments
to a call taking varargs.

Previously we would say that the type of VarargExpansionExpr is
$T when its subexpression type is [$T]. matchCallArguments() would
then 'collect' the single VarargExpansionExpr into a variadic
argument list with a single element, and build an ArgumentShuffleExpr
for the argument list.

In turn, SILGen would peephole vararg emission of a variadic
argument list with a single entry that happens to be a
VarargExpansionExpr, by returning the subexpression's value,
which happened to be an array of the right element type,
instead of building a new array containing the elements of the
variadic argument list.

This was all too complicated. Instead, let's say that the type of
a VarargExpansionExpr is [$T], except that when it appears in a
TupleExpr, the variadic bit of the corresponding element is set.

Then, matchCallArguments() needs to support a case where both
the parameter and argument list have a matching vararg element.
In this case, instead of collecting multiple arguments into a
single variadic argument list, we treat the variadic argument like
an ordinary parameter, bypassing construction of the
ArgumentShuffleExpr altogether.

Finally, SILGen now needs to be able to emit a VarargExpansionExpr
in ordinary rvalue position, since it now appears as a child of a
TupleExpr; it can do this by simply emitting the sub-expression
to produce an array value.
2019-03-28 23:23:58 -04:00
Pavel Yaskevich
fe7ea486a1 [CSSimplify] Teach disjunction filtering that some enum cases have curried self
Cases with arguments form `(Self.Type) -> (Arg...) -> Self`
function types, so `areConservativelyCompatibleArgumentLabels`
should remove curried self before trying to match argument/parameter
labels.

Resolves: rdar://problem/49159472
2019-03-25 19:37:05 -07:00
Suyash Srijan
5a8e1fa955 [cs] extract computed property fix-it into separate method 2019-03-25 00:07:41 +00:00
Suyash Srijan
9750762b75 [csdiag] missing function call failure here as a backup 2019-03-23 02:11:13 +00:00
Suyash Srijan
1b62039c76 [cssimplify] add a fix for contextual type conversion for function type 2019-03-22 23:40:43 +00:00
Pavel Yaskevich
196f732cc8 [CSFix] Introduce a fix for inaccessible members
If there are no other choices, let's attempt to
use any available inaccessible candidates.
2019-03-18 13:44:30 -07:00
Pavel Yaskevich
852169a5f5 [ConstraintSystem] Split unviable lookup result storage into candidates & reasons
That makes it easy to process unviable choices the same way as viable
ones and request rejection reasons only when necessary.
2019-03-14 22:20:20 -07:00
Pavel Yaskevich
fd377dc46b [CSSimplify] Fix unviable "instance member on metatype" choice
Adjust base type and reference kind so it looks as-if
it is a correct reference when used by constraint system.
2019-03-14 13:34:39 -07:00
Pavel Yaskevich
8de1763ba0 [ConstraintSystem] Record both viable and unviable candidates produced by lookup
Try to form a "complete" set of overload choices based on lookup
results, which means include both viable and unviable-but-fixed
candidates for solver to attempt. Latter are going to be skipped
until "salvage" mode so there should be no overhead for the solver
in "performance first" mode.
2019-03-14 13:18:42 -07:00
Pavel Yaskevich
7633d012e5 [ConstraintSystem] Attach fixes to incorrectly referenced or unviable overloads
Instead of waiting until the overload is attempted, let's figure out
if there is anything wrong with it beforehand and attach a fix to the
"bind overload" constraint representing it.
2019-03-13 12:09:12 -07:00
Pavel Yaskevich
70c59afb40 [ConstraintSystem] Move "outer" candidates handling to simplifyMemberConstraint
Further simplify `addOverloadSet` and move "outer" candidate handling
to the only place where it comes up - `simplifyMemberConstraint`.
Also move constraint generation for choices into a separate method.

This is a stepping stone on the path to enable attaching fixes to
the overload choices.
2019-03-12 14:46:35 -07:00
Pavel Yaskevich
a5485d8ae2 [CSSimplify] Detect missing optional unwraps in operator/call arguments 2019-03-07 14:51:55 -08:00
Doug Gregor
2c744b4d50 [Constraint solver] Remove a dubious hack introduced with SR-2505 2019-03-06 08:58:56 -08:00
Doug Gregor
b83bb70bac [Constraint solver] Look through optional binding for overload sets.
When we’re trying to find the overload set corresponding to a particular
type variable, look through “optional object of” constraints that represent
the use of ? binding or ! forcing. This allows us to find overload sets
when referring to, e.g., @objc optional protocol requirements.
2019-03-05 21:40:48 -08:00
Doug Gregor
b993c6e076 [Constraint solver] Move tryOptimizeGenericDisjunction() into partitioning
This narrow favoring rule makes more sense as part of disjunction
partitioning, because it is not dependent on the use site at all and
should only kick in when other options fail.
2019-03-05 15:01:46 -08:00
Doug Gregor
fae2d1b2ac Merge pull request #23088 from DougGregor/solver-disjunction-favoring
[Constraint solver] Generalize disjunction favoring
2019-03-05 14:41:56 -08:00
Doug Gregor
20bb077229 [Constraint solver] Use tryOptimizeGenericDisjunction() during application.
Use tryOptimizeGenericDisjunction() as part of simplifying apply
constraints.
2019-03-05 10:30:51 -08:00
Doug Gregor
d2c7c8d5ee [Constraint solver] Enable favoring of disjunction constraints during solving
Allow constraints to be favored during solving, and unwound after exiting
that particular solver scope. We're not using this yet.
2019-03-05 10:30:51 -08:00
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