Commit Graph

508 Commits

Author SHA1 Message Date
Pavel Yaskevich
1817ddcc5e [CSBindings] Always finalize binding set unless explicitly asked not to 2021-02-24 10:38:31 -08:00
Pavel Yaskevich
3177145c95 [CSBindings] Determine literal coverage during binding set finalization 2021-02-24 10:38:30 -08:00
Pavel Yaskevich
5d8699583f [CSBindings] Revert changes to isViable 2021-02-24 10:37:20 -08:00
Pavel Yaskevich
fbc11f410a [ConstraintSystem] Implement incremental binding computation 2021-02-24 10:37:20 -08:00
Pavel Yaskevich
df7af0078f [CSBindings] Separate inference storage from final product usable by the solver
`PotentialBindings` lost most of its responsibilities,
and are no longer comparable. Their main purpose now
is binding and metadata tracking (introduction/retraction).

New `BindingSet` type is something that represents a set
of bindings at the current step of the solver.
2021-02-24 10:37:20 -08:00
Pavel Yaskevich
55cd99bce8 [CSBindings] NFC: Adjust static member lookup feature to recent PotentialBindings changes
- `ConstraintSystem` is now referenced as a member of `PotentialBindings`;
- Literals and defaults are no longer added to the `Bindings` list, so we
  to add a new method `hasViableBindings` to make sure that protocol types
  are added only when there are no other bindings.
2021-02-23 11:33:11 -08:00
Pavel Yaskevich
e8f7a71870 [CSBindings] Update static member lookup to utilize new isDelayed API 2021-02-23 11:33:11 -08:00
Pavel Yaskevich
88654b2025 [CSBindings] Inferring protocol type for member chain base makes binding potentially incomplete 2021-02-23 11:33:11 -08:00
Pavel Yaskevich
dcd746906f [ConstraintSystem] Mark member result type as a potential hole if base was incorrect
If it has been established that member found via static member
lookup on protocol metatype doesn't have correct result type,
chain's result type the should be treated as a hole.
2021-02-23 11:33:10 -08:00
Pavel Yaskevich
5b55ea1312 [CSGen] Use new UnresolvedMemberChainBase constraint 2021-02-23 11:33:10 -08:00
Pavel Yaskevich
497d42d90e [ConstraintSystem] Add a new constraint which connects base with result of the member chain
The first type represents a result of an unresolved member chain,
and the second type is its base type. This constraint acts almost
like `Equal` but also enforces following semantics:

- It's possible to infer a base from a result type by looking through
  this constraint, but it's only solved when both types are bound.

- If base is a protocol metatype, this constraint becomes a conformance
  check instead of an equality.
2021-02-23 11:33:10 -08:00
Pavel Yaskevich
49cc21919b [CSBindings] Don't infer protocol types from the base of an unresolved member chain 2021-02-23 11:32:24 -08:00
Pavel Yaskevich
ee8b87ecf9 [CSBindings] Allow base type of an unresolved member to be inferred from protocol requirements
To be able to infer base type in situations like:

```swift
func foo<T: P>(_: T) {}
foo(.bar)
```

Type variable used for a base type of the chain has to be allowed
to infer types from contextual protocol requirements e.g. `T: P`
in our example.
2021-02-23 11:32:23 -08:00
Nathan Hawes
44e09bc246 Merge branch 'main' into dont-allow-missing-args-if-trailing-and-not-function-type 2021-02-23 12:53:50 +10:00
Holly Borla
11028350a7 Merge pull request #35589 from Jumhyn/placeholder-types
[AST, Sema] Replace HoleType with PlaceholderType
2021-02-22 08:35:37 -08:00
Nathan Hawes
cdcaa110e8 [CodeCompletion][Sema] Refine logic that ignores missing arguments after the code completion position when solving
If the completion loc was in a trailing closure arg, it only makes sense to
ignore later missing args if they have function type, as there's no way for the
user to complete the call for overload being matched otherwise.

Also fix a bug where we were incorrectly penalizing solutions with holes that
were ultimately due to missing arguments after the completion position.

Resolves rdar://problem/72412302
2021-02-20 08:59:47 +10:00
Frederick Kellison-Linn
8539782c9a [Sema] Rename convertInferableTypes to replaceInferableTypesWithTypeVars 2021-02-19 14:35:03 -05:00
Luciano Almeida
76564ea340 [CSBindings] Avoid to infer transitive defaults for DefaultClosureType 2021-02-18 21:39:38 -03:00
Pavel Yaskevich
321cc07ba2 [CSBindings] Reset literal coverage when retracting constraint 2021-02-17 17:26:05 -08:00
Pavel Yaskevich
8e90882ee1 [CSBindings] Allow retracting constraints previously used to compute potential bindings
This allows to avoid having to recompute bindings when solver backtracks.
2021-02-17 17:25:42 -08:00
Pavel Yaskevich
64323a0149 Revert "[SR-12033] [Sema] Do not allow inferring defaultable closure () -> $T for autoclosure arguments result" 2021-02-17 10:28:30 -08:00
Frederick Kellison-Linn
e4ea1678dc Rename HoleType to PlaceholderType
HoleType basically served the same purpose as PlaceholderType. This commit unifies the two.
2021-02-16 22:59:19 -05:00
Frederick Kellison-Linn
fbb78cd006 [Sema] Convert placeholder types to type vars wherever we open generics
Rename `openUnboundGenericTypes` to `convertInferableTypes`. In addition to unbound generics, this method also converts placeholder types to fresh type variables.
2021-02-16 22:59:19 -05:00
Pavel Yaskevich
655aeef7ca [CSBindings] NFC: Associate isCoveredBy(PotentialBinding) with literal requirement 2021-02-16 16:57:50 -08:00
Pavel Yaskevich
b3284c6a9d [CSBindings] Track source constraint of an adjacent variable
This makes it much easier to remove adjacencies when constraint
is retracted from the bindings.
2021-02-11 15:40:19 -08:00
Pavel Yaskevich
bdfd4a8863 Merge pull request #35833 from xedin/couple-minor-incrementality-adjustments
[CSBindings] NFC: Couple minor incrementality adjustments
2021-02-09 18:22:00 -08:00
Pavel Yaskevich
daa4ffffa2 Merge pull request #35503 from LucianoPAlmeida/SR-12033-autoclosure
[SR-12033] [Sema] Do not allow inferring defaultable closure `() -> $T` for autoclosure arguments result
2021-02-09 16:23:51 -08:00
Pavel Yaskevich
c7169edf8f [CSBindings] NFC: Drop result type from since it's no longer useful 2021-02-09 09:09:31 -08:00
Pavel Yaskevich
b004dce44b [CSBindings] Attempt l-value fallback for force unwrap only after r-value type failed
Previously l-value binding would be paired with discovered r-value
one but that is not necessary and can cause issues with ranking
since there is no way to filter this "fallback" binding from the
set.
2021-02-09 09:04:25 -08:00
Pavel Yaskevich
f7432f820b [CSBindings] Attempt Void fallback for closure result only when other choices have failed
Since there is a conversion from `() -> T` to `() -> Void` for closures,
solver has to attempt a `Void` when other bindings (inferred from the body)
have failed.

Let's try it post factum instead of adding `Void` fallback to the
binding set after every discovered supertype binding. Old scheme
wouldn't work in incremental mode anyway because it's possible to
find a subtype binding (which makes it clear that body has to have
a result type) after a supertype and end up attempting `Void` although
it would be incorrect.
2021-02-08 13:35:51 -08:00
Pavel Yaskevich
8726d8889c [CSBindings] Filter out some of the constraints which can't delay hole propagation
If member type is unknown (determined to be a hole) `applicable function`
of any kind or `overload choice` cannot delay attempting it because doing
so would allow solver to make forward progress.
2021-02-08 12:29:49 -08:00
Luciano Almeida
fccb3e00e8 [CSBindings] Prevent solver from infering default binding to auto closures arguments 2021-02-05 20:20:57 -03:00
Pavel Yaskevich
8803281d6b Merge pull request #35701 from xedin/var-cannot-cover-literal
[CSBindings] Literal coverage checking should account for type variab…
2021-02-02 17:19:50 -08:00
Pavel Yaskevich
1965f3ec3c [CSBindings] Literal coverage checking should account for type variable/hole embedded in optional
Currently `isLiteralCoveredBy` only checks for top-level type variable or hole.

That check has to be sunk down so it could be used after optionality is stripped
away (when possible), otherwise bindings like `$T0?` are (incorrectly) determined
to cover literal requirements (because conformance check always succeeds when
attempted on a type variable).
2021-02-01 17:52:29 -08:00
Pavel Yaskevich
50a76c895f [CSBindings] New binding formed by join operation should refer to constraint that triggered join
Using existing binding with updated type would result in incorrect
behavior in incremental mode since when "originating" (new) constraint
gets retracted it would leave a stale binding behind.
2021-02-01 16:55:05 -08:00
Pavel Yaskevich
b03dc63634 [AST] Adjust TypeBase::getTypeVariables to accept a set
Currently the pattern is to collect the type variables and then unique
them. Instead of asking clients to do uniquing, let's just accept a set
as an argument.
2021-01-26 18:13:34 -08:00
Pavel Yaskevich
ac8897cc44 Merge pull request #35529 from xedin/never-fail-inference
[CSBindings] Inference cannot fail
2021-01-21 12:39:00 -08:00
Pavel Yaskevich
df43268929 [CSBindings] Inference cannot fail
Any constraints which would previously cause binding inference to
fail should instead delay associated type variable and preserve
all of the collected information.

This is vital for incremental binding computation that cannot
re-introduce constraints after "failure" because it's too expensive.
2021-01-20 16:58:05 -08:00
swift-ci
6c41322f0d Merge pull request #35504 from LucianoPAlmeida/update-comment 2021-01-20 05:44:52 -08:00
Luciano Almeida
0f6a4c06c7 [NFC] Update comment that mentioned old mark as FullyBound way to delay bindings 2021-01-19 22:40:12 -03:00
Pavel Yaskevich
48afd65ec2 [CSBindings] NFC: Convert checkTypeOfBinding into a static function 2021-01-15 15:04:28 -08:00
Pavel Yaskevich
cb4e597921 [ConstraintSystem] NFC: Convert getPotentialBindingForRelationalConstraint into a method on PotentialBindings 2021-01-15 15:04:13 -08:00
Pavel Yaskevich
72888ca29b [ConstraintSystem] NFC: Extract PotentialBindings and auxiliary struct from ConstraintSystem
This opens up a posibility of using `PotentialBindings`
in `ConstraintGraphNode` and other places in `ConstraintGraph`.
2021-01-15 15:03:54 -08:00
Pavel Yaskevich
b4f28b4883 [ConstraintSystem] NFC: Move implementation of PotentialBindings::dump(...) into cpp 2021-01-15 15:03:39 -08:00
Pavel Yaskevich
afec25271e [ConstraintSystem] Extract PotentialBinding and its auxiliary classes into a separate header
Create a new namespace - `swift::constraints::inference` and associate
`PotentialBinding` with it. This way it would be possible for constraint
graph to operate on `PotentialBinding(s)` in the future.
2021-01-15 15:03:24 -08:00
Pavel Yaskevich
7617b7418e [CSBindings] Re-introduce joined bindings instead of updating in place
Make `PotentialBinding` immutable and re-introduce products of
type join instead.
2021-01-12 11:09:14 -08:00
Pavel Yaskevich
03b6b41774 [CSBindings] NFC: Don't pass constraint system as an argument to infer* methods
`PotentialBindings` already reference the constraint system they
belong to, so there is no need to pass it as an argument to inference
methods.
2021-01-12 00:53:46 -08:00
Pavel Yaskevich
aa887fd66a [ConstraintSystem] Turn binding storage into a SetVector
Currently potential bindings are stored in a vector (`SmallVector`)
and every call has to pass additional set of unique types to
inference methods to unqiue the bindings. Instead let's merge
these two together and use `SetVector` for binding storage,
which would also be great for incremental mode that can't
pass additional sets around.
2021-01-12 00:52:55 -08:00
Pavel Yaskevich
8356ab430b [ConstraintSystem] NFC: Avoid use of designated initializers to make Windows happy 2021-01-05 13:25:57 -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