Commit Graph

489 Commits

Author SHA1 Message Date
willtunnels
319b3e64aa Add support for opaque result types in structural positions (#38392)
* [TypeResolver][TypeChecker] Add support for structural opaque result types

* [TypeResolver][TypeChecker] Clean up changes that add structural opaque result types
2021-08-03 23:45:02 -04:00
Pavel Yaskevich
942ff69310 [CSBindings] Record produced types incrementally
Allow type variable binding producer to record types as they
are being produced. Otherwise it could be possible to re-discover
already explored types during `computeNext()` which leads to
duplicate bindings e.g. inferring fallback `Void` for a closure
result type when `Void` was already inferred as a direct/transitive
binding.
2021-06-17 13:47:48 -07:00
Pavel Yaskevich
81ff342f4e [CSBindings] Overload variable shouldn't be delayed by its application
When inference is determining bindings of a type variable that represents
an overload set (e.g. member or operator reference), let's not consider
it as delayed due to presence of `ApplicableFunction` constraint since
argument/result type inference depends on overload set but not vice versa.

Resolves: rdar://78917861
2021-06-08 13:36:19 -07:00
Pavel Yaskevich
7558832f94 Merge pull request #37734 from xedin/rdar-78425221
[CSBindings] Don't record variable adjacency for `member chain base` constraint
2021-06-02 09:38:46 -07:00
Pavel Yaskevich
b881142486 [CSBindings] Don't record variable adjacency for member chain base constraint
This constraint is used to enforce ordering of inference and provide
a starting point for inference of base based on associated generic
constraints. It's an `Equals` constraint with additional semantics
that only apply to unresolved members, which means that there are
no (other) adjacent variables in this case.

Resolves: rdar://78425221
2021-06-01 20:10:10 -07:00
Pavel Yaskevich
1673a9f172 [ConstraintSystem] NFC: Print out adjacent type variables to a debug log
If type variable has any type variables adjacent to it, let's print
them out to make it easier to figure out what inference did.
2021-06-01 17:54:30 -07:00
Pavel Yaskevich
0c75593a04 [CSBindings] Fix inference of partial key path from conversion constraints
It's not permitted to use `PartialKeyPath` type to resolve a key path
expression, because that type is intended to be a type-erased version of
a fully resolved `KeyPath` type.

In situations where contextual type is a partial key path (e.g. parameter
type is a partial key path), let's replace it with a `KeyPath` type that
is a subtype of `PartialKeyPath` and allow value inference to happen.

Resolves: SR-5667
Resolves: rdar://32365183
2021-05-28 17:54:05 -07:00
Luciano Almeida
ba7524d1d8 [Sema] Do not record hole root fix for keypath with invalid component 2021-05-19 21:35:42 -03: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
Pavel Yaskevich
3c0388d945 [CSBindings] Don't infer subtypes/supertype bindings for a closure type
A type representing a closure expression is always bound to its
"inferred" type based on the body, so contextual bindings just
serve as a trigger to "resolve" a closure. Let's not attempt any
subtype/supertype inference for a type variable representing a
closure since if "direct" bindings have failed, it wouldn't be bound
to such types regardless.

Resolves: rdar://problem/77022842
2021-05-06 13:35:45 -07:00
Azoy
9ed732f0ab Introduce isDecl and getDeclType
fix enum logic issue

fix tests

guard against null types
2021-04-20 02:22:16 -04: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
8e401d2413 Merge pull request #36657 from xedin/rdar-75978086
[CSBindings] A couple of adjustments to transitive protocol inference
2021-03-31 12:31:13 -07:00
Pavel Yaskevich
f00c578761 Merge pull request #34401 from xedin/implicit-cgfloat-conversion
[DNM][TypeChecker] Implement Double <-> CGFloat implicit conversion
2021-03-31 10:20:28 -07:00
Pavel Yaskevich
d310f37ffc [CSBindings] Infer transitive protocols only for unresolved member base
Nothing besides static member refs on protocols feature is currently
using transitive protocols, so instead of trying to infer them on every
step let's do that only for base type of a dot-syntax reference when
there are no other bindings for it.
2021-03-30 13:39:24 -07:00
Pavel Yaskevich
56c96c6b50 [CSBindings] Use all equivalence chain members while interring transitive protocols
Currently inference logic only checked direct equivalence class members
associated with a "work-in-progress" type variable, but each member can
have local equivalences as well that need to be accounted for.

Resolves: rdar://75978086
2021-03-30 13:39:12 -07:00
Holly Borla
ee2a8fce16 [ConstraintSystem] Delay binding the type variable representing a wrapped
value type until the PropertyWrapper constraint has been solved.
2021-03-24 12:39:42 -07:00
Holly Borla
7cd8add885 [ConstraintSystem] Add a property wrapper constraint to delay checking
if an inferred wrapper type is a property wrapper until that type is
resolved.
2021-03-24 11:24:21 -07:00
Pavel Yaskevich
0321425044 [CSBindings] Adopt Double <-> CGFloat handling to addPotentialBindings API change 2021-03-17 00:18:19 -07:00
Pavel Yaskevich
ba2bf82d5c [CSBindings] Adjust Double<->CGFloat handling since Bindings are now a SetVector 2021-03-17 00:18:18 -07:00
Pavel Yaskevich
fbeca3d31e [CSBindings] Prefer Double over CGFloat bindings
Always prefer binding to `Double` over `CGFloat` if possible
since there is an implicit conversion between them and attempting
both could lead to ambiguities.
2021-03-17 00:18:15 -07:00
Pavel Yaskevich
dde9fa35e8 [ConstraintSystem] Re-activate constraints if, due to incorrect reference, member type has been bound before base type
If member has been bound before the base and the base was
incorrect at that (e.g. fallback to default `Any` type),
then we need to re-activate all of the constraints
associated with this member reference otherwise some of
the constraints could be left unchecked in inactive state.

This is especially important for key path expressions because
`key path` constraint can't be retired until all components
are simplified.

Resolves: SR-13364
Resolves: rdar://66706980
Resolves: rdar://74711236
2021-03-12 15:31:06 -08:00
Pavel Yaskevich
b487b6956b [ConstraintSystem] Delay inference until let's clear that type variable attempt is successful
Currently bindings where inferred on every `bindTypeVariable` call,
but that's wasteful because not all binds are always correct. To
avoid unnecessary inference traffic let's wait until re-activated
constraints are simplified and notify binding inference about new
fixed type only if all of them are successful.
2021-03-01 10:52:29 -08:00
Pavel Yaskevich
f12efe9166 [CSBindings] Use matchTypes directly while attempting a type variable
This makes sure that solver knows the result of a bind, instead of
having to checking `failedConstraint` and allows passing flags.
2021-03-01 10:52:29 -08:00
Pavel Yaskevich
ff4294297a Merge pull request #36156 from xedin/rdar-74723323
[CSBindings] Copy-initialize transitive protocols for equivalence class
2021-02-26 09:03:11 -08:00
Pavel Yaskevich
67d8cb8acf [CSBindings] Copy-initialize transitive protocols for equivalence class
Since equivalence class shares protocols, let's copy-initialize
transitive requirement sets because move would result in slots
with null pointers if equivalence class is bigger than just one member.

Resolves: rdar://74723323
2021-02-25 00:40:02 -08:00
Pavel Yaskevich
8b8e002bc4 [CSBindings] Allow hack that drops noEscape bit from function types to work during constraint generation phase
Previously bindings were inferred only during solving but now they
are inferred as soon as something changes in the constraint graph,
so the hack that dropped `noEscape` bit from function type when
inferred for generic parameter should be allowed during constraint
generation as well.
2021-02-24 15:28:54 -08:00
Pavel Yaskevich
e5c686a3ad [CSBinding] Adjust SE-0299 binding inference to BindingSet 2021-02-24 12:58:31 -08:00
Pavel Yaskevich
b891a4540a [CSBindings] Change the direction of literal coverage determination 2021-02-24 10:38:31 -08:00
Pavel Yaskevich
dd1b8b3224 [CSBindings] Fix merge conflicts with main 2021-02-24 10:38:31 -08:00
Pavel Yaskevich
10df9d23ff [CSBindings] An attempt to make isViable filter out duplicate bindings 2021-02-24 10:38:31 -08:00
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