Commit Graph

692 Commits

Author SHA1 Message Date
Hamish Knight
f045350266 [CS] Clean up dynamic member overload choice checking
Add `OverloadChoice::isAnyDynamicMemberLookup`,
and use it to clean up a couple of places.
2021-10-01 12:54:08 +01:00
Hamish Knight
ddff9c4c9d [CS] Store argument list mappings on solutions
Roll back argument list mappings in the constraint
system at the end of solver scopes, and copy
argument list mappings into solutions.
2021-09-06 12:54:49 +01:00
Hamish Knight
8c2b88abc0 [CS] Adopt ArgumentList
- Explicitly limit favoring logic to only handle
unary args, this seems to have always been the
case, but needs to be handled explicitly now that
argument lists aren't exprs
- Update the ConstraintLocator simplification to
handle argument lists
- Store a mapping of locators to argument lists
in the constraint system
- Abstract more logic into a getArgumentLocator
method which retrieves an argument-to-param locator
from an argument anchor expr
2021-09-01 18:40:25 +01:00
Pavel Yaskevich
6a85650573 [ConstraintSystem] Don't attempt to rollback state and scope from incorrect state 2021-08-06 12:32:17 -07:00
Pavel Yaskevich
d8cdbcd0c7 [ConstraintSystem] Add InvalidState flag to indicate that any attempt to solve should fail
As soon as `InvalidState` flag is set solving of the constraint
system as aborted and all subsequent calls to `solveImpl` would
produce no solutions.
2021-08-06 10:03:05 -07:00
Alex Hoppen
f42f961faf [Sema] Copy key path component types when merging solutions
In 2eeff365b1 I forgot to copy key path component types when applying a solution to the constraint system. That caused a crash in key path code completion.

Fixes rdar://81118700 [SR-14979]
2021-07-30 11:07:21 +02:00
Alex Hoppen
2eeff365b1 [CodeCompletion] Record key path component types in the constraint system solution
The added test case fails because the result builder inside `List2` is being type checked twice: Once for every overload of `List2`. Because of the way that result builders are being type checked right now, each overload of `List2` creates a new type variable for the key components in `foo` and the constraint system only keeps track of the key path component -> type mapping for the last solution discovered.

When we are now trying to look up the type of the first key path component for the first solution, the constraint system returns the type variable that is being used by the second solution and simplifying that type variable through the first solution fails because it doesn’t know about the type variable.

To fix the issue, make sure that the solutions keep track of the their type variables associated to key path components. That way the first solution owns its own key path component -> type variable mapping and is thus also able to simplify the type variable it has associated with the component.

Fixes rdar://80522345 [SR-14916]
2021-07-14 17:57:29 +02:00
Hamish Knight
46fa6e5721 [AST] Improve BinaryExpr
Abstract away the TupleExpr gunk and expose
`getLHS` and `getRHS` accessors. This is in
preparation for completely expunging the use
of TupleExpr as an argument list.
2021-05-19 14:48:01 +01:00
Slava Pestov
131d3f4bce Sema: Pass down a ModuleDecl instead of a DeclContext to conformsToProtocol()
... and a bunch of follow-up simplifications pushing ModuleDecls further
up, since I couldn't resist the yak shave.
2021-05-17 16:34:18 -04:00
Nathan Hawes
f75f5fe78d Merge pull request #36879 from nathawes/track-match-call-result
[ConstraintSystem] Record parameter bindings in solutions (NFC)
2021-04-18 06:10:23 +10:00
Nathan Hawes
c57c403ffa [ConstraintSystem] Record parameter bindings in solutions (NFC)
This saves us from needing to re-match args to params in CSApply and is also
useful for a forthcoming change migrating code completion in argument position
to use the solver-based typeCheckForCodeCompletion api.

rdar://76581093
2021-04-16 18:32:06 +10:00
Pavel Yaskevich
d57c112845 [ConstraintSystem] NFC: Replace isOperatorBindOverload with isOperatorDisjunction 2021-04-14 10:34:17 -07:00
Pavel Yaskevich
fef108f2ac [ConstraintSystem] NFC: Move partitioning methods to DisjunctionChoiceProducer 2021-04-14 09:54:39 -07:00
Pavel Yaskevich
985843a21f [ConstraintSystem] Add a new transitive conformance constraint
Conformance constraints could be transferred through conversions,
but that would also require checking implicit conversions
such as optional and pointer promotions for conformance is the
type itself doesn't conform, for that let's add a special constraint
`TransitivelyConformsTo`.
2021-04-07 17:55:11 -07:00
Pavel Yaskevich
0e6198d477 [CSSolver] Shrinking should avoid solutions with implicit conversions
Just like generic overloads, `shrink` should always avoid any solutions
with implicit conversions.

Reducing disjunction domains becaused on solutions with implicit
conversions could have negative performance impact due to the
increase in total number of solutions that have to be examined
as a result.
2021-03-17 00:18:48 -07:00
Pavel Yaskevich
cd3ec8c508 [ConstraintSystem] Allow attempting generic unary operators in presence of Double<->CGFloat conversion
Not all of the unary operators have `CGFloat` overloads,
so in order to preserve previous behavior (and overall
best solution) with implicit Double<->CGFloat conversion
we need to allow  attempting generic operators for such cases.

```swift
let _: CGFloat = -.pi / 2
```

`-` doesn't have `CGFloat` overload (which might be an oversight),
so in order to preserve type-checking behavior solver can't be
allowed to pick `-(Double) -> Double` based on overload of `/`,
the best possible solution would be with `/` as `(CGFloat, CGFloat) -> CGFloat`
and `-` on a `FloatingPoint` protocol.
2021-03-17 00:18:19 -07:00
Pavel Yaskevich
c77d0862bb [ConstraintSystem] Record all Double <-> CGFloat conversions performed along a current solver path
This information makes it easier to compute a score for the next
implicit value conversion solver would have to perform.
2021-03-17 00:18:15 -07:00
Pavel Yaskevich
31ccd6099a [ConstraintSystem] Maintain insertion order of all shrunk expressions and their overload sets 2021-03-05 00:07:30 -08:00
Pavel Yaskevich
bcd58edcef [ConstraintSystem] Remove unused default parameter from ConstraintSystem::simplify 2021-02-26 13:11:26 -08:00
Holly Borla
8325a52b41 [ConstraintSystem] Teach the constraint system about property wrapper
parameters.
2021-02-25 18:35:13 -08:00
Pavel Yaskevich
fbc11f410a [ConstraintSystem] Implement incremental binding computation 2021-02-24 10:37:20 -08:00
Pavel Yaskevich
db7ee5f7eb Merge pull request #36059 from xedin/nfc-remove-argument-info-collector
[ConstraintSystem] NFC: Remove `ArgumentInfoCollector` which was part…
2021-02-22 10:48:31 -08:00
Pavel Yaskevich
1eb478870a [ConstraintSystem] NFC: Remove ArgumentInfoCollector which was part of designated operator work 2021-02-19 13:45:40 -08:00
Frederick Kellison-Linn
e508fb3733 [Sema] Introduce placeholder handler to TypeResolver
For now, don't do anything useful in clients. Specifying a placeholder type is still an error
2021-02-16 22:59:18 -05:00
Holly Borla
56cc31f1e8 [ConstraintSystem] Only consider the number of resolved argument types
if the two disjunctions have the same number of active choices.
2021-02-04 23:05:22 -08:00
Holly Borla
b5e17fb6d7 Merge pull request #35744 from hborla/solver-disjunction-selection
[ConstraintSystem] Tweak disjunction selection
2021-02-04 09:01:47 -08:00
Holly Borla
752cf7f2ac [ConstraintSystem] Consider the number of resolved argument types
for applied overloads when selecting a disjunction to attempt.
2021-02-03 13:26:57 -08:00
Holly Borla
a9e300b637 [ConstraintSystem] Before checking if an argument type to an applied
disjunction conforms to a known protocol, grab its fixed type.
2021-02-02 18:40:23 -08:00
Holly Borla
1ef2174bc2 Merge pull request #35025 from hborla/generic-overload-search-space
[ConstraintSystem] Implement heuristics for pruning the generic operator overload search space
2021-01-22 09:12:50 -08:00
Holly Borla
a3957b987e [ConstraintSystem] Only do the work of partitioning the generic operator
overloads if generic operators are not going to be skipped.
2021-01-14 13:49:57 -08:00
Pavel Yaskevich
2a6f279b45 [ConstraintSystem] NFC: Remove obsolete used/checked conformances cache 2021-01-08 12:55:49 -08:00
Pavel Yaskevich
fc05d4a6db Merge pull request #35225 from xedin/refactor-literal-bindings
[CSBindings] Refactor literal protocol requirement handling
2021-01-07 17:34:05 -08:00
Holly Borla
daec9c9eb7 [ConstraintSystem] Only attempt the refinement overload heuristic
for arithmetic operators.

Only sort overloads that are related, e.g. Sequence
overloads. Further, choose which generic overloads
to attempt first based on whether any known argument types
conform to one of the standard arithmetic protocols.
2021-01-07 14:13:30 -08:00
Holly Borla
e24ac86eaf [ConstraintSystem] Cache applied disjunction constraints in the
constraint system to use later in DisjunctionStep.
2021-01-06 13:36:38 -08:00
Holly Borla
7783f6bb2b [ConstraintSystem] Rename IsDeclSubstitutableRequest to
IsDeclRefinementOfRequest to better reflect what it computes.
2021-01-06 13:36:38 -08:00
Holly Borla
62305d003f [ConstraintSystem] Use isDeclSubstitutable instead of compareDeclarations
to order generic operator overload choices.
2021-01-06 13:36:38 -08:00
Holly Borla
c62d898169 [ConstraintSystem] Only attempt generic overload pruning heuristics for
operators for now.
2021-01-06 13:36:38 -08:00
Holly Borla
27b1394430 [ConstraintSystem] Within the generic disjunction choice partition,
attempt the most specific choices first. Then, if the solver finds
a solution with one choice, it can skip any subsequent choices that
can be unconditionally used in place of the successful chioce and produce
the same solution.
2021-01-06 13:36:38 -08:00
Pavel Yaskevich
2393a7c9a4 [CSBindings] Represent literal requirements as a struct instead of a tuple
Doing so streamlines access to the information associated with literal
protocol requirements and allows to add more helpers.

Also cache default type in the struct itself for easy access.
2021-01-04 10:32:08 -08:00
Pavel Yaskevich
e676e05f13 [CSBindings] Transform literal requirements into bindings when type variable is attempted 2021-01-04 09:20:14 -08:00
Slava Pestov
e675bee26c AST: Split off DependencyCollector.h from EvaluatorDependencies.h
Also remove some unnecessary #includes from DependencyCollector.h,
which necessitated adding #includes in various other files.
2020-12-23 00:00:25 -05:00
Pavel Yaskevich
22b34e8f36 [CSBindings] Let producer record a binding for a hole
As a step towards making binding inference more incremental, let's
make producer responsible for adding hole type binding instead of
doing so in `finalize`.
2020-12-10 15:39:38 -08:00
Pavel Yaskevich
2619e2d8ac [ConstraintSystem] Track adjacent type variables while inferring bindings
Replaces `InvolvesTypeVariables` flag with a set of adjacent type
variables found during binding inference.

This approach is more suitable for incremental binding computation
because it allows to maintain a list of type variables that affect
ranking and check whether something has been resolved without having
to re-evaluate constraints associated with the given type variable.
2020-12-08 13:22:30 -08:00
Holly Borla
a647f0fb5b Merge pull request #34399 from hborla/optimize-linked-operator-solving
[Constraint System] Implement heuristics for linked operator expressions in the solver proper.
2020-11-08 13:22:40 -08:00
Holly Borla
abfc90303c [ConstraintSystem] For generic operators, only consider exact decls that
are already bound elsewhere for existingOperatorBindingsForDisjunction,
rather than also considering overload choices with the same type.
2020-11-05 09:56:00 -08:00
Holly Borla
099560813e [ConstraintSystem] Only factor in existing operator bindings in
selectDisjunction if both disjunctions are operator bindings.
2020-11-04 15:23:12 -08:00
Holly Borla
0d8a1619c6 [NFC][ConstraintSystem] Update the documentation for
existingOperatorBindingsForDisjunction.
2020-10-30 17:25:57 -07:00
Holly Borla
c9100c46e7 [ConstraintSystem] Instead of favoring existing operator bindings,
order them first in the main disjunction partition.
2020-10-29 19:49:47 -07:00
Doug Gregor
6d41524fe6 [SE-0289] Finish renaming source code, tests to "result builders" 2020-10-20 22:18:51 -07:00
Doug Gregor
0d568a93d4 [SE-0289] Update diagnostics & many other strings to "result builders" 2020-10-20 21:44:09 -07:00