Commit Graph

827 Commits

Author SHA1 Message Date
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
gregomni
ab6d92b1cd Favor operators based on existing binds via both basename and type 2020-10-15 09:03:45 -07:00
Holly Borla
b06f749f0e [ConstraintSystem] Fix build failures and formatting. 2020-10-15 09:03:45 -07:00
gregomni
2edba9dfbd Instead of chaining binops, favor disjunctions with op overloads whose types match existing binding choices 2020-10-15 09:03:45 -07:00
Holly Borla
4c0f49f7a6 [ConstraintSystem] Remove selectApplyDisjunction, which was only used
by the operator designated types implementation.
2020-10-14 17:28:33 -07:00
Holly Borla
1e0038c3be [ConstraintSystem] Remove implementation of operator designated types
in the solver.
2020-10-14 16:05:54 -07:00
Pavel Yaskevich
461eafff54 [ConstraintSystem] NFC: Move ConstraintSystem.h to include/swift/Sema 2020-10-08 10:45:47 -07:00
Pavel Yaskevich
ab951c208a [ConstraintSystem] NFC: Move ConstraintGraph{Scope}.h to include/swift/Sema 2020-10-08 10:42:58 -07:00
Pavel Yaskevich
767c1a0ed6 [ConstraintSystem] NFC: Move SolutionResult.h to include/swift/Sema 2020-10-08 10:42:08 -07:00
Pavel Yaskevich
f94be56468 [Sema] Decouple ConstraintSystem and TypeChecker headers 2020-10-06 13:18:49 -07:00
Nathan Hawes
a1ef6e4dac Merge pull request #33749 from nathawes/new-member-completion
[CodeCompletion] Update member completion to handle ambiguous and invalid base expressions
2020-09-09 18:51:22 -07:00
Pavel Yaskevich
627a1c0037 [TypeChecker/CodeCompletion] Move hole -> archetype conversion logic into sawSolution
Instead of exposing archetypes during solution generation, let's
do that based on solution data when a type of code completion
expression is requested by code completion callback.
2020-08-31 16:54:12 -07:00
Pavel Yaskevich
8d5c94f232 [TypeChecker/CodeCompletion] Implement a fallback from code completion to typeCheckExpression
This fallback to `typeCheckExpression` is triggered when it's
determined that code completion expression is located inside
of a multi-statement closure and its body is going going to
participate in type-check.
2020-08-28 22:24:24 -07:00
Pavel Yaskevich
74f0ec5b97 [TypeChecker/CodeCompletion] Allow {typeCheck, solve}ForCodeCompletion to operate on target instead of expression
Using `SolutionApplicationTarget` make it easier to propage
contextual information and avoid mistakes of using incorrect
accessors for constraint generation.
2020-08-28 22:24:24 -07:00
Pavel Yaskevich
d6d083ecf8 [TypeChecker] Mode code completion fallback to typeCheckForCodeCompletion
If an expression fails pre-check or constraint generation,
code completion should be performed directly on the
`CodeCompletionExpr` as a fallback. Let's factor that logic
out from `solveForCodeCompletion` and put it directly into
`typeCheckForCodeCompletion` because it's easier to establish
fault conditions there.
2020-08-28 22:24:24 -07:00
Pavel Yaskevich
b71fdb5704 [CSSolver] Augment solveForCodeCompletion to indicate when it fails 2020-08-28 22:24:23 -07:00