Commit Graph

672 Commits

Author SHA1 Message Date
Nathan Hawes
7e65384f80 Merge pull request #35535 from nathawes/dont-filter-out-non-best-solutions-for-completion
[CodeCompletion][Sema] Don't filter out any viable solutions when solving for code completion
2021-02-04 14:41:30 +10: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
Nathan Hawes
3fe0b8f91f [CodeCompletion][Sema] Don't filter out any viable solutions when solving for code completion
Resolves rdar://problem/73282163
2021-02-03 12:36:21 +10:00
Varun Gandhi
86b123a35c [Sema] Diagnose type error on Clang type mismatch.
Fixes rdar://71904525.
2021-01-25 18:51:13 -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
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
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
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
db4f790c5d [ConstraintSystem] Make it possible to use PotentialBinding in set/map 2021-01-11 12:53:26 -08:00
Pavel Yaskevich
2a6f279b45 [ConstraintSystem] NFC: Remove obsolete used/checked conformances cache 2021-01-08 12:55:49 -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
50212a0ea4 [ConstraintSystem] If the solver has already found a solution with a
disjunction choice that does not introduce conversions, check to see
if known argument types satisfy generic operator conformance requirements
early, and skip the overload choice if any requirements fail.

This helps the solver avoid exploring way too much search space when
the right solution involves a generic operator, but the argument types
are known up front, such as `collection + collection + collection`.
2021-01-06 13:36:38 -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
b79b875a3d [ConstraintSystem] Make it possible to reference PotentialBinding(s) in unit tests 2021-01-05 11:51:33 -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
Pavel Yaskevich
731810e184 [CSBindings] Check literal coverage as new bindings/requirements are discovered
One more step towards incrementality of binding inference. Instead of
trying to determine literal protocol coverage during finalization
of the bindings, let's do that as soon as new bindings and/or literal
protocol requirements are discovered.
2021-01-04 09:20:14 -08:00
Pavel Yaskevich
41623abe49 [CSBindings] Compute literal information on demand 2021-01-04 09:20:14 -08:00
Pavel Yaskevich
650c54b822 [CSBindings] Split literals from other protocol requirements
Literal protocol requirements are handled differently from other
protocols, they require additional contextual information (such
as coverage, direct/transitive distinction), and participate in
binding inference (could be turned into default bindings).
2021-01-04 09:20:14 -08:00
Pavel Yaskevich
e301b19b83 [ConstraintSystem] Avoid using a separate set to compute viable defaults 2020-12-15 13:30:52 -08:00
Pavel Yaskevich
9649b76042 [CSBindings] Don't generate bindings for defaults
Let's keep defaults separate from direct and transitive bindings,
that would make it easier to handle them in incremental model.

Instead of generating bindings for defaults and adding to the main
set, let's allow producer to choose what to do with them once type
variable has been picked for attempting.
2020-12-15 13:17:41 -08:00
Pavel Yaskevich
8e4207e0d8 [ConstraintSystem] NFC: Simplify type var producer/step by referencing constraint system from bindings 2020-12-11 00:30:39 -08: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
50cc0f040f [ConstraintSystem] NFC: Extract requiresOptionalAdjustment so it could be used for default bindings 2020-12-09 13:34:30 -08:00
Pavel Yaskevich
ef673c74f1 [ConstraintSystem] Handle binding nullability in producer instead of collector
Wrapping bindings into optional type based on presence of
an `ExpressibleByNilLiteral` conformance requirement should
be done after type variable has been selected for attempting.
Otherwise such upfront work would be wasteful since it doesn't
affect binding ranking in any way.
2020-12-09 13:34:01 -08:00
Pavel Yaskevich
4e321320cf [CSStep] Don't retain multiple copies of the same bindings just for printing 2020-12-09 13:34:01 -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
Pavel Yaskevich
88efaacd79 Merge pull request #34988 from xedin/on-demand-fully-bound
[CSBindings] Instead of using a flag track constraints which delay type variable
2020-12-08 10:03:18 -08:00
Pavel Yaskevich
c1d178a9e0 [ConstraintSystem] NFC: Rename isFullyBound -> isDelayed and clarify associated comment 2020-12-08 00:54:09 -08:00
Pavel Yaskevich
54406b49de [ConstraintSystem] Track constraints that caused bindings to be "fully bound"
- Keep track of all constraints which caused a particular type variable to
  be de-prioritized.

- Convert a property to a method which would determine whether
  given set of potential bindings is "fully bound" and has to
  be delayed until certain constraints are simplified.
2020-12-04 21:50:04 -08:00
Frederick Kellison-Linn
a53b1e4f3f [Sema] Always look through optionals for unresolved member lookup 2020-12-04 12:11:10 -05:00
Pavel Yaskevich
96415b237e [CSBinding] Attempt to join any existing and viable bindings with new binding
Instead of attempting to join only the last recorded supertype
binding, let's attempt to join any previously recorded supertype
binding with an incoming one to make sure that set contains only
the most viable types.
2020-11-19 18:06:35 -08:00
Nathan Hawes
1eb05b7760 Merge pull request #34733 from nathawes/migrate-unresolved-completion
[CodeCompletion][Sema][Parse] Migrate unresolved member completion to the solver-based completion implementation
2020-11-19 01:26:43 -08:00
Nathan Hawes
86ddd52204 [Sema] Extract out expression-contains-completion-loc check into a method on ConstraintSystem (NFC) 2020-11-19 09:32:38 +11:00
Pavel Yaskevich
094ca8077d Merge pull request #34737 from xedin/potential-bindings-refactor
[ConstraintSystem] Infer some of the bindings attributes on demand
2020-11-16 13:28:21 -08:00
Pavel Yaskevich
afa11989c9 [ConstraintSystem] Determine whether bindings are potentially incomplete on demand 2020-11-13 13:45:58 -08:00
Pavel Yaskevich
6a7cc79f83 [ConstraintSystem] Determine whether type variable is a hole on demand 2020-11-11 15:31:24 -08:00
Pavel Yaskevich
4ed9794547 [ConstraintSystem] Compute whether bindings are bound only by existentials on demand 2020-11-11 14:19:49 -08:00
Pavel Yaskevich
7f228b0e31 [ConstraintSystem] Compute # of defaultable bindings on demand 2020-11-11 12:35:53 -08:00
Slava Pestov
0ff82ca051 Sema: Check conformance availability when ranking solutions
This completes the work on <rdar://problem/35158274>, and also
adds a test case for <rdar://problem/50627401>.
2020-11-10 17:52:51 -05: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
Doug Gregor
33cfbbdd72 [Concurrency] Don't diagnose missing "self." in async let autoclosures. 2020-11-04 23:18:51 -08:00
Holly Borla
b9e08b23fb [ConstraintSystem] Allow the solver to find other solutions after
successfully finding a solution by favoring operators already bound
elsewhere.

Favoring existing operator bindings often lets the solver find a solution
fast, but it's not necessarily the best solution.
2020-10-29 14:33:29 -07:00