Commit Graph

236 Commits

Author SHA1 Message Date
Luciano Almeida
8b0b89ee34 Merge pull request #36076 from LucianoPAlmeida/SR-2705-ranking-autoclosure
[SR-2705][Sema] Always favor non-autoclosure parameter function overload
2021-02-24 07:00:42 -03:00
Pavel Yaskevich
c44a92ae0b [ConstraintSystem] Implement new rule for static member lookup in generic contexts
Instead of requiring result type of the member to conform to declaring protocol,
as originally proposed by SE-0299, let's instead require `Self` to be bound to
some concrete type in extension that declares a static member.

This would make sure that:

1. Members are only visible on a particular type;
2. There is no ambiguity regarding what base of the member chain is going to be.
2021-02-23 11:33:11 -08:00
Pavel Yaskevich
b27fd2b4da [TypeChecker] NFC: Add a couple of test-cases of partially applied static members with protocol metatype base 2021-02-23 11:33:11 -08:00
Pavel Yaskevich
df76400fe5 [ConstraintSystem] Add a new reason for invalid member reference
This new reason indicates that result type of a static member
doesn't conform to a specific protocol so it can't be referenced
on a protocol metatype.
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
Luciano Almeida
ef86e9edbe [ConstraintSystem] Adding new score kind SK_FunctionToAutoClosureConversion to increase impact of a function to autoclosure 2021-02-23 07:21:58 -03: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
8539782c9a [Sema] Rename convertInferableTypes to replaceInferableTypesWithTypeVars 2021-02-19 14:35:03 -05:00
Frederick Kellison-Linn
ddd48429bd [Sema] Allocate locator for HandlePlaceholderType 2021-02-17 11:17:35 -05: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
Frederick Kellison-Linn
65521b596f [Sema] Handle placeholder types in during expression type resolution 2021-02-16 22:59:18 -05: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
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