Commit Graph

1877 Commits

Author SHA1 Message Date
Hamish Knight
fee31c69f0 [CS] Move constructor ranking rule into CSRanking
Previously we were introducing a type variable
to mark a constructor's parameter list as
`TVO_PrefersSubtypeBinding`. Unfortunately this
relies on representing the parameter list as a
tuple, which will no longer be properly supported
once param flags are removed from tuple types.

Move the logic into CSRanking such that we pick up
and compare the parameter lists when comparing
overload bindings. For now, this still relies on
comparing the parameter lists as tuples, as there's
some subtle tuple subtyping rules that could
potentially affect source compatibility here, but
at least we can explicitly strip the parameter
flags and localise the hack to CSRanking rather
than exposing it as a constraint.
2021-10-12 09:51:44 +01:00
Hamish Knight
a1abcee108 [CS] Introduce ConstructorMemberType locator elt
Use this new element to represent the overload type
for a constructor call, and have it store a bit
indicating whether the call is for a short-form
`X(...)` or self-delegating `self.init(...)` call.
2021-10-12 09:51:44 +01:00
Luciano Almeida
ca8b660a1c Merge pull request #39648 from LucianoPAlmeida/SR-15281-cast
[SR-15281] [Sema] Couple of contextual mismatch and runtime cast diagnostic fixes
2021-10-10 08:03:24 -03:00
LucianoAlmeida
5424797e79 [Sema] Make constraint restriction to store TypeBase * instead of Type 2021-10-09 14:26:21 -03:00
LucianoAlmeida
4e689bba5d [NFC] Adjusting comments for clarity 2021-10-09 14:26:21 -03:00
LucianoAlmeida
8c424383a6 [Sema] Account for value to optional restriction when recording runtime cast warnings 2021-10-09 14:26:21 -03:00
Pavel Yaskevich
99a9828a03 [ConstraintSystem] Add a new contextual purpose - CTP_CaseStmt 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
7197fac8f5 [ConstraintSystem] Add a new contextual purpose - CTP_ForEachSequence
A contextual purpose for a sequence expression associated with
`for-in` statement, that decays into a `ConformsTo` constraint
to a `Sequence` or `AsyncSequence` protocol.

Note that CTP_ForEachSequence is almost identical to CTP_ForEachStmt
but the meaning of latter is overloaded, so to avoid breaking solution
targets I have decided to add a new purpose for now.
2021-10-08 10:08:02 -07:00
Pavel Yaskevich
55bae6150d [Constraint] Allow closure body elements to carry contextual information 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
91eecdb6d0 [CSClosure] Initial support for multi-statement closures
Implement constraint generation for brace statements and
refactor closure contraint generation to accept multi-statement
closures.
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
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
1c0a306c75 Merge pull request #37956 from xedin/implicit-swift-to-c-ptr-conversions
[TypeChecker] Implement limited set of conversions between Swift and C pointers
2021-10-06 14:35:22 -07:00
Pavel Yaskevich
ed45116be8 Merge pull request #39458 from xedin/result-builder-labeled-tuple-pattern
[ResultBuilders] A couple pattern matching fixes to make it consistent with `TypeCheckPattern`
2021-10-04 09:29:48 -07:00
Holly Borla
9bf9de8ca6 Merge pull request #39188 from amritpan/projected-value-labels
[CSSimplify] Fix a bug where the omitted projected value label was missing as an acceptable parameter label for property wrappers
2021-09-28 16:57:28 -07:00
Pavel Yaskevich
7a854ee1cc [CSSimplify] Make solver behavior consistent with TypeCheckPattern for paren patterns
A single paren pattern becomes a labeled tuple pattern
e.g. `case .test(let value):` should be able to match
`case test(result: Int)`. Note that it also means that:
`cast test(result: (String, Int))` would be matched against
e.g. `case .test((let x, let y))` but that fails during
pattern coercion (behavior consistent with what happens in
`TypeCheckPattern`).
2021-09-25 11:42:21 -07:00
Pavel Yaskevich
a9fdb7ad66 [CSSimplify] Detect and diagnose Swift -> C pointer conversion failures
Detect and diagnose situations when Swift -> C pointer conversion
is unsupported due to method not being imported from C header.
2021-09-20 17:22:26 -07:00
Pavel Yaskevich
25762c25ee [CSSimplify] Make sure that Swift -> C pointer conversion always waits for optionals
Wait for a value-to-optional promotion or optional-to-optional conversion
to happen before attempting Swift -> C pointer conversion.
2021-09-20 17:22:26 -07:00
Pavel Yaskevich
f53bcea60c [CSFix] Add a tailored fix for invalid Swift -> C pointer conversions
This is a skeleton of a fix that would be used to diagnose situations
when Swift -> C pointer conversion was attempted on a Swift function.
2021-09-20 17:22:26 -07:00
Pavel Yaskevich
5cb8604b60 [ConstraintSystem] De-prioritize solutions with Swift -> C pointer conversions
Just like other implicit conversions - always prefer solutions with
the lowest possible number of them.
2021-09-20 17:22:26 -07:00
Pavel Yaskevich
f368e5a7b6 [ConstraintSystem] NFC: Extract Swift -> C pointer conversion simplification into a separate method 2021-09-20 17:22:26 -07:00
Pavel Yaskevich
d95e92c92c [CSSimplify] Allow implicit Swift -> C pointer conversion within optional types
Support Swift -> C pointer conversions even if argument required
a value to optional promotion or is optional.
2021-09-20 17:22:25 -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
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
Amritpan Kaur
e57ff0224d [NFC] Replace similar if block in claimNextArgs with matchParameterLabel(). 2021-09-17 16:28:35 -07:00
Amritpan Kaur
2667d3df25 [CSSimplify] Add omitted projection name label as valid argument label and consolidate all checks for argument and parameter label matches into new Param member function. 2021-09-17 16:25:26 -07:00
LucianoAlmeida
d53a862251 [Sema][SR-15179] Do not record default argument mismatch fix if there is one remove arg fix already for locator 2021-09-13 13:51:18 -03:00
LucianoAlmeida
ac92f4e44a [Sema] Ignore individual FunctionArgument inout mismatch fix if there is already a fix recorded for function type locator 2021-09-13 11:20:44 -03:00
Pavel Yaskevich
150203c4e4 [Diagnostics] Use IgnoreContextualType for contextual failures related to closure body/result types 2021-09-10 17:17:31 -07:00
Pavel Yaskevich
e512473c64 [Diagnostics] Use IgnoreContextualType fix for mismatches between ternary branch and contextual type 2021-09-10 16:14:28 -07:00
Pavel Yaskevich
06a762b64a [CSFix] Add a specific kind for IgnoreResultBuilderWithReturnStmts 2021-09-10 15:46:27 -07:00
Pavel Yaskevich
0a425480d0 [CSFix] NFC: Rename fix/diagnostic for checked casts that always succeed 2021-09-10 13:55:15 -07:00
Pavel Yaskevich
0f2ee14cad [CSFix] Add a specific kind for CollectionElementContextualMismatch 2021-09-10 13:07:22 -07:00
Pavel Yaskevich
152cf0b66c [CSFix] Add a specific kind for IgnoreKeyPathContextualMismatch 2021-09-10 13:01:26 -07:00
Pavel Yaskevich
48cdb58a91 [CSFix] Add a specific kind for AllowInOutConversion 2021-09-10 12:55:26 -07:00
Pavel Yaskevich
4f5b33b4dd [CSFix] Add a specific kind for IgnoreAssignmentDestinationType 2021-09-10 12:48:14 -07:00
Pavel Yaskevich
2e5ab93f0f [CSFix] Add a specific kind for IgnoreContextualType 2021-09-10 12:42:34 -07:00
Pavel Yaskevich
04b35e4c26 [CSFix] Add a specific kind for AllowAutoClosurePointerConversion 2021-09-10 12:37:08 -07:00
Pavel Yaskevich
934e875e7f [CSFix] Add a specific kind for DropAsyncAttribute 2021-09-10 12:30:02 -07:00
Pavel Yaskevich
d1d2846baa [CSFix] Add a specific kind for DropThrowsAttribute 2021-09-10 12:21:26 -07:00
Pavel Yaskevich
057563e783 [CSFix] Add a specific kind for AddSendableAttribute 2021-09-10 12:15:10 -07:00
Hamish Knight
77e6c083f3 [AutoDiff] [CS] Formalize function tupling behavior for @differentiable
Reject tupling into a `@differentiable` function,
and allow the stripping of `@noDerivative` given
we're also losing `@differentiable`.
2021-09-09 21:46:32 +01:00
Hamish Knight
cab39bf26c [CS] Formalize param flag handling for imploding params
By default avoid imploding params that have parameter
flags, but carve out exceptions for ownership flags,
which can be thunked, and `@_nonEphemeral` which can
be freely dropped without issue.
2021-09-09 21:46:31 +01:00
Hamish Knight
af14bba276 [AST] Simplify AnyFunctionType::composeTuple
Remove the canonicalVararg parameter and
CanParamArrayRef wrapper. Almost none of the
callers want canonicalVararg, and the one that
does calls `getCanonicalType` on the result
anyway.
2021-09-09 21:46:31 +01:00
Pavel Yaskevich
3bbde55052 [ConstraintSystem] Detect and diagnose incorrectly typed weak declarations
All `weak` declarations are supposed to have an optional type.
Detect situations when is not an optional, wrap it as a fix,
and diagnose the problem.
2021-09-08 09:39:54 -07:00
Pavel Yaskevich
3fac0fefc9 [CSFix] Add a skeleton of weak pattern with non-optional type fix 2021-09-07 17:36:56 -07:00
Holly Borla
df76275116 Merge pull request #39169 from hborla/bogus-missing-function-call-error
[ConstraintSystem] Fix a bogus missing function call error message.
2021-09-07 11:24:50 -07:00
LucianoAlmeida
63330f9a6e [Sema] Do not emit warning about conditional cast bridge when from type is optional 2021-09-07 01:43:58 -03:00