Commit Graph

865 Commits

Author SHA1 Message Date
Anthony Latsis
e48f4830dd TypeResolution: Replace more 'forContextual' uses with 'resolveContextualType' 2021-11-19 16:44:03 +03:00
Pavel Yaskevich
0c70f5650f Merge pull request #39592 from Jumhyn/contextual-placeholder-followup
Remove default argument from getContextualType
2021-11-08 10:00:36 -08:00
Pavel Yaskevich
f765390c62 [ConstraintSystem] Convert Fixes to a set vector to avoid duplicates 2021-10-22 10:09:09 -07:00
Pavel Yaskevich
d74e8c9407 [ConstraintSystem] Convert ConversionRestrictions to a map vector to avoid duplicates 2021-10-22 10:09:08 -07:00
Pavel Yaskevich
880374eaf3 [ConstraintSystem] Convert DisjunctionChoices to a map vector & assert on duplicates 2021-10-22 10:09:08 -07:00
Pavel Yaskevich
19c253bec2 [ConstraintSystem] Convert argumentMatchingChoices to a map vector to avoid duplicates 2021-10-22 10:09:08 -07:00
Pavel Yaskevich
e95e43d019 [ConstraintSystem] Convert ImplicitValueConversions to a map vector to avoid duplicates 2021-10-22 10:09:08 -07:00
Pavel Yaskevich
568c27f551 [ConstraintSystem] Convert Opened{Existential}Types to a map vector to avoid duplicates
Same reasons as with `DefaultConstraints` but also improves
code ergonomics around opened types.
2021-10-22 10:09:08 -07:00
Pavel Yaskevich
cfcc85268a [ConstraintSystem] Convert DefaultConstraints to a set vector to avoid duplicates
It's always been the case that partial solutions introduce
some storage duplication when applied back to the constraint
system to form a more complete solution with outer context,
 but the constraint systems used to be small before
introduction of result builders (and now multi-statement
inference), which make the duplication more visible.
2021-10-22 10:09:08 -07:00
Doug Gregor
b72f9394d9 Remove unnecessary clear(). 2021-10-21 12:11:33 -07:00
Doug Gregor
0c9f9f7a43 Use a SmallSetVector to eliminate duplicates 2021-10-20 23:15:21 -07:00
Doug Gregor
45824befd2 Infer 'isolated' closure parameters from context.
When a closure is provided with a contextual type that has isolated
parameters, infer that the corresponding closure parameter is "isolated".

Fixes rdar://83732479.
2021-10-20 21:51:42 -07:00
Luciano Almeida
ca8b660a1c Merge pull request #39648 from LucianoPAlmeida/SR-15281-cast
[SR-15281] [Sema] Couple of contextual mismatch and runtime cast diagnostic fixes
2021-10-10 08:03:24 -03:00
LucianoAlmeida
5424797e79 [Sema] Make constraint restriction to store TypeBase * instead of Type 2021-10-09 14:26:21 -03:00
Pavel Yaskevich
67a721485f [ConstraintSystem] Compute variables referenced by conjunction elements incrementally
Attempting to pre-compute a set of referenced type variables
upfront is incorrect because parameter(s) and/or result type
could be bound before conjunction is attempted. Let's compute
a set of referenced variables before each element gets attempted.
2021-10-08 10:08:03 -07:00
Pavel Yaskevich
95119f1049 [CSSolver] Don't select disabled conjunctions 2021-10-08 10:08:01 -07:00
Pavel Yaskevich
f3440077b6 [CSSimplify] Implement conjunction element simplification 2021-10-08 10:08:01 -07:00
Pavel Yaskevich
27275f6214 [CSStep] Add an implementation of ConjunctionStep
It behavies similar to `DisjunctionStep` but attempts all of
its elements unless there is an inference failure.
2021-10-08 10:08:00 -07:00
Pavel Yaskevich
2377f0507c [ConstraintSystem] Add a conjunction element producer
In preporation to add `ConjunctionStep`, let's first
introduce a `ConjunctionElement` and `ConjunctionElementProducer`.
2021-10-08 10:08:00 -07:00
Frederick Kellison-Linn
b433724735 Remove default argument from getContextualType 2021-10-05 17:04:54 -04:00
Hamish Knight
cf4fc9f3c9 Merge pull request #39541 from hamishknight/dynamic-programming 2021-10-05 21:11:01 +01:00
Frederick Kellison-Linn
f6b6f0cd2b Lift replaceInferableTypes call into getContextualType 2021-10-04 23:36:33 -04:00
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
Holly Borla
06a7950d0d [ConstraintSystem] Treat arithmetic SIMD operators like other generic
operators when partitioning an overload set.
2021-07-22 19:15:45 -07: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