Commit Graph

31 Commits

Author SHA1 Message Date
Robert Widmann
d44d8ec043 Allow Converting Pack Types to Tuples
Insert an implicit conversion from pack types to tuples with equivalent parallel structure. That means

1) The tuple must have the same arity
2) The tuple may not have any argument labels
3) The tuple may not have any variadic or inout components
4) The tuple must have the same element types as the pack
2021-12-16 08:51:38 -08:00
Pavel Yaskevich
46ff410a23 [ConstraintSystem] Warn about discarded expressions found in multi-statement closures 2021-12-03 10:53:50 -08:00
Pavel Yaskevich
bc54bc6bb7 Revert "[TypeChecker] SE-0326: Enable multi-statement closure inference by default" 2021-11-29 17:26:08 -08:00
Hamish Knight
237338b504 Merge pull request #40224 from hamishknight/super-tuple-shuffle 2021-11-18 09:50:09 +00: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
Pavel Yaskevich
3927f56dbd [ConstraintSystem] Warn about discarded expressions found in multi-statement closures 2021-11-15 16:42:04 -08: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
67a721485f [ConstraintSystem] Compute variables referenced by conjunction elements incrementally
Attempting to pre-compute a set of referenced type variables
upfront is incorrect because parameter(s) and/or result type
could be bound before conjunction is attempted. Let's compute
a set of referenced variables before each element gets attempted.
2021-10-08 10:08:03 -07:00
Pavel Yaskevich
55bae6150d [Constraint] Allow closure body elements to carry contextual information 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
9073d00613 [ConstraintSystem] Allow conjunctions marking conjunctions as isolated from the rest of the system 2021-10-08 10:08:01 -07:00
Pavel Yaskevich
ad01027a0d [ConstraintSystem] Allow closure body element constraint to reference type variables
This would be useful when once it's used as part of a conjunction to
be able to solve the closure body element component in isolation.
2021-10-08 10:08:01 -07:00
Pavel Yaskevich
73dffb3125 [ConstraintSystem] Don't require a type variable per closure body element
Since each of the body elements is already going to have a type associated
with it there is no need to create yet another type variable.
2021-10-08 10:08:01 -07:00
Pavel Yaskevich
6aaee599bd [ConstraintSystem] Allow conjunction constraints to reference other variables 2021-10-08 10:08:00 -07: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
9e7a670295 [ConstraintSystem] Implement new Swift -> C pointer conversions
Allow following conversions in argument positions
(applies only to call to imported C/ObjC declarations):

- Unsafe[Mutable]RawPointer -> Unsafe[Mutable]Pointer<[U]Int>
- Unsafe[Mutable]Pointer<Int{8, 16, ...}> <-> Unsafe[Mutable]Pointer<UInt{8, 16, ...}>
2021-09-20 17:22:25 -07:00
Pavel Yaskevich
3a41f7af5f [ConstraintSystem] Add a new conversion - Swift to C pointers
Following pointer conversions are supported in argument positions (when referencing C/ObjC functions):

- Unsafe[Mutable]RawPointer -> Unsafe[Mutable]Pointer<[U]Int>
- Unsafe[Mutable]Pointer<Int{8, 16, ...}> -> Unsafe[Mutable]Pointer<UInt{8, 16, ...}>
2021-09-20 17:22:25 -07: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
957e05cfb1 [Constraint] Allow constraints to be disabled only in "performance" mode 2021-04-27 16:11:47 -07: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
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
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
a559ca8c53 [TypeChecker/SE-0307] NFC: Fix typos and clarify a couple of comments
Thanks Xiaodi Wu!
2021-03-17 14:11:53 -07:00
Pavel Yaskevich
8c6017687a [ConstraintSystem] Limit new implicit conversion to only Double <-> CGFloat 2021-03-17 00:18:10 -07:00
Pavel Yaskevich
2b935bab7c [ConstraintSystem] Add conversion restriction to cover implicit conversion from/to CGFloat 2021-03-17 00:18:08 -07: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
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
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
Holly Borla
12dce859a2 [NFC][ConstraintSystem] Use llvm::count_if for the count methods on
Constraint.
2020-11-05 09:56:00 -08:00
gregomni
2edba9dfbd Instead of chaining binops, favor disjunctions with op overloads whose types match existing binding choices 2020-10-15 09:03:45 -07:00
Pavel Yaskevich
6ba7ecb7c2 [ConstraintSystem] NFC: Move Constraint.h to include/swift/Sema 2020-10-08 10:45:32 -07:00