Commit Graph

508 Commits

Author SHA1 Message Date
Hamish Knight
237338b504 Merge pull request #40224 from hamishknight/super-tuple-shuffle 2021-11-18 09:50:09 +00:00
Pavel Yaskevich
63f355fde0 Merge pull request #39989 from xedin/more-diag-improvements-for-multi-stmt-closures
[TypeChecker] SE-0326: Enable multi-statement closure inference by default
2021-11-17 10:14:58 -08:00
Hamish Knight
da36a2cb88 [CS] Restore a type variable for compatibility with rdar://85263844
Despite being otherwise disconnected from the
constraint system, it's possible for it to affect
how we type-check tuple matches in certain cases.

This is due to the fact that:
- It can have a lower type variable ID than an
opened generic parameter type, so becomes the
representative when merged with it. And because it
has a different locator, this can influence
binding prioritization.
- Tuple subtyping is broken, as it's currently a
*weaker* relationship than conversion.

Therefore, temporarily restore this bit of logic
for language versions < 6. If possible, we should
try and fix tuple subtying in Swift 6 mode to not
accept label mismatches, so that it's not more
permissive than tuple conversion.

rdar://85263844
2021-11-17 17:06:19 +00:00
Holly Borla
92e0fd4dae [ConstraintSystem] Extend the early type variable binding heuristic to
builtin types.
2021-11-16 20:31:15 -08:00
Pavel Yaskevich
aa3b8867a3 [ConstraintSystem] Attempt conjunction before closure result or generic parameter holes
Closure result type or generic parameter associated with such a location
could bw inferred from a body of a multi-statement closure (when inference
is enabled), so we need to give closure a chance to run before attemtping
a hole for such positions in diagnostic mode.
2021-11-15 16:42:06 -08:00
Pavel Yaskevich
bbdc5b1c9c [CSBindings] Account for API change: isCGFloatType -> isCGFloat 2021-11-08 13:52:53 -08:00
Holly Borla
020c29b347 [CSBindings] Don't attempt to bind type variables early if the conversion
type is CGFloat or Double, and minimize the diagnostic impact of this
heuristic by only binding early for valid code.
2021-11-08 13:51:23 -08:00
Pavel Yaskevich
4799acfb20 [CSBindings] Attempt a type variable early if it's constrained by a struct/enum type
If a type variable has a subtype binding which came from a conversion/subtype/equality
constraint to a struct or enum (expect to `AnyHashable`, `Unsafe{Mutable}RawPointer`),
attempt it early because that type is the only choice which is not going to fail such
constraint.

For example, in cases like `$T argument convertible to Int` type variable could
only be bound to `Int`, `Int!`, or `@lvalue Int` to satisfy that constraint, so
it would make sense to attempt to bind it to `Int` early if it doesn't represent
a result of a member lookup (that's how IUO and/or `@lvalue` could be inferred)`
and doesn't have any direct disjunction associated with it e.g. for coercion or
optional matching.
2021-11-08 13:51:23 -08:00
Pavel Yaskevich
573ae9bcac Merge pull request #40047 from xedin/rdar-83056143
[Diagnostics] A tailored diagnostic for Double<->CGFloat conversion via optional chaining
2021-11-04 16:14:58 -07:00
Pavel Yaskevich
7f94bbf29b [AST] NFC: Drop Type from TypeBase::isCGFloatType
This makes naming consistent with other accessors e.g. `isDouble`
2021-11-03 18:09:14 -07:00
Hamish Knight
fb3796971e [CS] Simplify getAlternativeLiteralTypes
Caching the result here feels a little overkill as
it's only useful for one protocol, and the
`TypeChecker::getDefaultType` computation is
cached by the request evaluator.
2021-11-02 13:55:04 +00: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
Hamish Knight
b8e4c676c6 [CS] Remove function component constraints
FunctionInput relies on being able to represent
parameter lists as tuples, which won't be possible
once parameter flags are stripped from tuple types.
FunctionResult is reasonable, but is currently
unused.
2021-10-12 09:51:45 +01:00
Pavel Yaskevich
2b4691048e [ConstraintSystem] Add a skeleton of Conjunction constraint
It's similar to disjunction constraint but represents an "and"
relationship between its elements instead of "or", so all of the
elements have to produce a solution for conjunction constraint
to be considered solved successfully.
2021-10-08 10:08:00 -07:00
Pavel Yaskevich
eb8eabfba7 [ConstraintSystem] Add a skeleton of ClosureBodyElement constraint 2021-10-08 10:08:00 -07:00
Pavel Yaskevich
a061a966d1 Merge pull request #39251 from xedin/classof-for-fixes
[CSFix] Add support for `classof` for all fixes
2021-09-20 14:33:06 -07:00
Pavel Yaskevich
d21069b3e5 [ConstraintSystem] Propagate holes up to result of optional chaining
If underlying type of an optional chain has been marked as a hole,
e.g. due to a reference to an invalid or missing member, let's
propagate that information to object type of an optional that
represents a result of an optional chain.

Resolves: rdar://80941497
2021-09-10 21:32:51 -07:00
Pavel Yaskevich
06a762b64a [CSFix] Add a specific kind for IgnoreResultBuilderWithReturnStmts 2021-09-10 15:46:27 -07:00
Frederick Kellison-Linn
5f07747cb3 [Sema] Diagnose user-specified placeholders which couldn’t be resolved 2021-08-19 14:53:33 -04:00
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