Commit Graph

2464 Commits

Author SHA1 Message Date
Sima Nerush
b6d0afba1f Merge pull request #67594 from simanerush/simanerush/pack-iteration-impl
[SE-0408] Enable Pack Iteration
2023-12-07 17:09:48 -08:00
Pavel Yaskevich
d9abf188cc Revert "[CSSimplify] Fix handling of holes by OptionalObject constraint"
This reverts commit 8b5e3848a1.
2023-12-04 11:36:20 -08:00
Holly Borla
48cb3309bd [Constraint System] Fix the shape class and context substitiutions for
opened element generic environments containing same-element requirements.
2023-12-03 21:51:41 -08:00
Sima Nerush
23485990e5 Diagnose that where clause is not supported 2023-12-03 21:51:41 -08:00
Pavel Yaskevich
12f02fd37e Merge pull request #70109 from xedin/fixes-for-member-sendability-inference
[ConstraintSystem] A couple of fixes to Sendable inference on functions
2023-12-01 13:36:15 -08:00
Pavel Yaskevich
d586ffe284 [CSSimplify] InferSendableFromCaptures: Narrow member lookup delaying
Avoid delaying if:

- Base is a metatype because static methods are always Sendable
  (because metatype is Sendable)
- Lookup doesn't have any methods (properties are un-affected by
  the inference changes).
2023-11-29 17:01:41 -08:00
Pavel Yaskevich
d72749560f [CSSolver] Handle situations when key path expression has an existential type
A way to mark key path as Sendable is to extend its type with `& Sendable`.
This is something that makes the type of a key path expression an existential
with superclass bound expressed as a known key path type.
2023-11-28 13:02:17 -08:00
Pavel Yaskevich
bd4ee4681b Merge pull request #70007 from xedin/keypath-application-improvements
[ConstraintSystem] Modernization of key path application handling
2023-11-28 12:44:42 -08:00
Slava Pestov
f89b9817e7 Merge pull request #69950 from slavapestov/clean-up-open-existentials
Cleanups and fixes for opened existentials
2023-11-28 10:45:19 -05:00
Slava Pestov
1b1963e904 Sema: Remove 'inferred result type requires explicit coercion' diagnostic 2023-11-27 14:05:36 -05:00
Alex Hoppen
b603a5e9a0 [Sema] Remove LeaveClosureBodiesUnchecked
This shouldn’t be needed anymore since we migrated code completion to be solver-based.

rdar://91403086
2023-11-23 11:41:29 -08:00
Pavel Yaskevich
cceef44379 [CSSimplify] Detect and diagnose invalid arguments for key path subscript 2023-11-22 21:05:06 -08:00
Pavel Yaskevich
d6f9f1c095 [CSFix] Add a fix to detect incorrect argument to subscript key path index 2023-11-22 20:30:00 -08:00
Pavel Yaskevich
34a0b09889 [ConstraintSystem] NFC: Format code related to InferSendableFromCaptures feature 2023-11-16 10:47:55 -08:00
Pavel Yaskevich
9c5d4654de [CSSimplify] Remove eager bindings for key path type to a contextual function type
This is no longer necessary for diagnostics or anything else because
inference decides the type now.
2023-11-13 10:44:49 -08:00
Pavel Yaskevich
7877c0703c [CSGen] Fix one last incorrect key path locator use
Optional chaining is related to the key path value and not the
key path type itself.
2023-11-09 21:31:28 -08:00
Pavel Yaskevich
7812f5e408 [CSSimplify] NFC: More non-functional changes in KeyPath simplification 2023-11-08 22:29:54 -08:00
Pavel Yaskevich
f84b3d40fe [CSSimplify] Allow fixing root/value mismatches of a key path literal individually
In general the solver attempts to gather all of the generic argument
mismatches into a single fix because there could be an arbitrary
number of generic arguments. This is uncessary for key path literals
matching against a contextual type because they have at most two
generic arguments (Root and Value), so it's better to produce fixes
for root and value type individually.
2023-11-08 19:54:32 -08:00
Pavel Yaskevich
e67dfc182b [CSSimplify] Remove obsolete key path capability inference and matching
The capability inference is now handled by the binding inference
and that makes resolved key path matching to bound type is no longer
necessary.
2023-11-08 19:54:31 -08:00
Pavel Yaskevich
0a2f1b14a7 [CSBindings] Delay key path type inference until literal capability is known
Since key path root is now transitively inferred. Key path type
inference can be delayed until key path is resolved enough to
infer its capability.

This solves multiple problems:

- Inference fully controls what key path type is bound to;
- KeyPath constraint simplification doesn't have to double-check
  the capability and attempt to re-bind key path type;
- Custom logic to resolve key path type is no longer necessary;
- Diagnostics are improved because capability and root/value type
  mismatch are diagnosed when key path is matched against the
  contextual type.
2023-11-08 19:54:31 -08:00
Angela Laar
eb277d9ee7 Merge pull request #67498 from angela-laar/implicit-sendable-for-methods
[Sema] Implicitly add @Sendable attribute to partial methods
2023-11-07 16:46:16 -08:00
Angela Laar
c09ec72e85 [Constraint System] Always add Sendable to unapplied function applications 2023-11-07 13:37:24 -08:00
Pavel Yaskevich
8b5e3848a1 [CSSimplify] Fix handling of holes by OptionalObject constraint
When "optional type" is a hole the simplification logic has to
simplify "object type" and mark all of its unresolved components
are potential holes, otherwise hole propagation won't work since
sometimes there is no other contextual information for such types
but "optional type".

Resolves: rdar://117871338
2023-11-03 10:13:09 -07:00
Pavel Yaskevich
b129d92937 Merge pull request #69549 from xedin/rdar-117227549
[ConstraintSystem] Rework overload ranking based on Sendable conformances
2023-11-02 09:42:49 -07:00
Pavel Yaskevich
736381286a [CSSimplify] NFC: Extract invalid function type detection from tryMatchRootAndValueFromType 2023-11-01 09:15:14 -07:00
Pavel Yaskevich
d74c4723dc [ConstraintSystem] De-duplicate key path constraint simplification
Move some of the checks from the constraint simplification into
`inferKeyPathLiteralCapability` and start using it for both
inference and constraint simplification.
2023-11-01 09:15:14 -07:00
Pavel Yaskevich
9bf9d549c4 [ConstraintSystem] Key path capability inference should indicate whether key path is invalid
This flag makes it easier to determine what binding to produce
from the default. In cases where some of the member references
are invalid it's better to produce a placeholder for a key
path type instead of letting the solver to attempt to fix more
contextual problems for a broken key path.
2023-11-01 09:15:14 -07:00
Pavel Yaskevich
8b4985054a [CSDiagnostics] Differentiate between key path type and value issues
Make sure that contextual mismatch uses a correct locator when
the issue is with key path value type instead of the key path
type.
2023-11-01 09:15:14 -07:00
Pavel Yaskevich
bfeade4e39 [CSSimplify] Cleanup some obsolete code from key path simplification
Since key path type is always bound by inference before the
constraint could be simplified, there is no need to search
for a contextual type or try to bind key path type if there
are errors in the path.
2023-11-01 09:15:14 -07:00
Pavel Yaskevich
161e126a91 [CSDiagnostics] Diagnose a key path literal without components early
Detect that diagnose key path literals that do not have any components.
2023-11-01 09:15:14 -07:00
Pavel Yaskevich
19e9cb0a91 [CSSimplify] Delay simplification of key path constraint until key path type is bound
Let the inference drive key path literal resolution, this fixes
a problem where key path is bound too eagerly.
2023-11-01 09:15:14 -07:00
Pavel Yaskevich
d0fae407f3 [CSSimplify] Increase score if conformance constraint finds missing conformances
Although the solver is allowed to use types with missing synthesizable
conformances we need to note their presence in the score in order
to rank overloads without such types higher.
2023-10-31 13:47:23 -07:00
Kavon Farvardin
29acda5136 Merge pull request #69406 from kavon/noncopyable-generics-pt2
[NoncopyableGenerics] handle `~Copyable` in `where`, `some`, and compositions.
2023-10-28 22:36:22 -07:00
Doug Gregor
ff45fec1d8 [Typed throws] Handle key-path literal used with a function that has typed throws
When providing a key-path literal for a parameter of function type
where that function type has a generic parameter for its thrown error
type, infer `Never` for the generic argument because key paths don't
throw.

Thanks to @xedin for realizing that this would be an issue.
2023-10-27 12:52:05 -07:00
Angela Laar
619a517a61 [CSSimplify] Check all conditional requirements for a type variable 2023-10-25 12:30:50 -07:00
Angela Laar
34ca702031 [Frontend] Feature flag for InferredSendableMethods 2023-10-25 12:30:24 -07:00
Angela Laar
9e408af419 [Sema] Global funcs should always be Sendable
Global funcs should be Sendable by default because they don't
capture anything.
2023-10-25 12:29:37 -07:00
Angela Laar
6879961c52 [Sema] Delay lookup for conditional conformances
Remove diagnostics and sendable checks from ActorIsolationChecker
2023-10-25 12:29:35 -07:00
Kavon Farvardin
66712ce6e0 [Sema] introduce InverseType
This type will become the corresponding type that is resolved for an
`InverseTypeRepr`. This kind of type is not expected to appear past type
 checking (currently, not even past requirement lowering!).
2023-10-23 10:37:22 -07:00
Kavon Farvardin
f76360c5b1 [Sema] "Noncopyable" means no Copyable conformance 2023-10-18 13:52:14 -07:00
Doug Gregor
a14f280104 Merge pull request #69087 from DougGregor/typed-throws-conformances 2023-10-10 21:16:44 -07:00
Pavel Yaskevich
12630f4c5c Merge pull request #69031 from xedin/rdar-116376651
[ConstraintSystem] A few improvements to key path handling and diagnostics
2023-10-09 23:27:45 -07:00
Doug Gregor
7d7c726efe [Typed throws] Teach associated type inference to infer from thrown errors
When comparing a requirement that uses typed throws and uses an
associated type for the thrown error type against a potential witness,
infer the associated type from the thrown error of the
witness---whether explicitly specified, untyped throws (`any Error`),
or non-throwing (`Never`).
2023-10-09 21:21:21 -07:00
Doug Gregor
ccf8619453 [Typed throws] Refactor thrown error subtyping check for reuse.
Lift the subtyping check for thrown error types out of the constraint
solver, so we can re-use it elsewhere.

There is a minor diagnostic change, from one that is actively
misleading (it shows a legitimate conversion that's wrong) to one that
is correct, which comes from us not treating "dropping throws" as a
legitimate way to handle equality of function types.
2023-10-09 21:21:21 -07:00
Doug Gregor
9340705294 Address code review comments 2023-10-07 07:29:02 -07:00
Pavel Yaskevich
b17ec0e385 [CSSimplify] Broaden delay of the key path assignment
If key path is connected to a disjunction directly or indirectly
(i.e. via ApplicableFunction constraint) do not attempt to bind
it until disjunction is taken, otherwise there is a risk to miss
a valid keypath-to-function conversion.
2023-10-06 17:47:10 -07:00
Pavel Yaskevich
cc0e621497 [CSFix] NFC: Remove obsolete IgnoreKeyPathContextualMismatch fix 2023-10-06 17:07:41 -07:00
Pavel Yaskevich
6fd6c16bf7 [CSSimplify] Key path should use a default type is contextual type is a placeholder
If there is something wrong with the context, let's assign a default
KeyPath type to the key path literal to avoid propagating placeholder
into the key path inference.
2023-10-06 16:59:53 -07:00
Pavel Yaskevich
4830c5be9a [CSSimplify] Unwrap of key path root can only yield one type
For methods there are two possibilities - force unwrap and
conditional, that's why we need a disjunction with two choices.

This is not the case for key path root type it could only
be force unwrapped.
2023-10-06 16:14:01 -07:00
Pavel Yaskevich
5a6c562b8c [CSSimplify] Adjust locators associated with keypath root/value matching constraints
`tryMatchRootAndValueFromType` anchored both root and value match
constraints directly on the key path expression. That is incorrect
because we have special locators for that.
2023-10-06 10:35:42 -07:00