Commit Graph

2540 Commits

Author SHA1 Message Date
Doug Gregor
6ebb0ff560 Replace AsyncIteratorProtocol.nextElement() with isolated next(_:)
Use an optional isolated parameter to this new `next(_:)` overload to
keep it on the same actor as the caller, and pass `#isolation` when
desugaring the async for..in loop. This keeps async iteration loops on
the same actor, allowing non-Sendable values to be used with many
async sequences.
2024-01-25 16:04:48 -08:00
Doug Gregor
dc85ae3fc6 Choose between AsyncIteratorProtocol's next() and nextElement() based on availability
This allows us to not break backward deployment
2024-01-25 16:04:47 -08:00
Doug Gregor
bb7a563e6c Switch async for-each loop over to _nextElement and drop @rethrows.
This couples together several changes to move entirely from
`@rethrows` over to typed throws:

* Use the `Failure` type to determine whether an async for-each loop
will throw, rather than depending on rethrows checking

* Introduce a special carve-out for `rethrows` functions that have a
generic requirement on an `AsyncSequence` or `AsyncIteratorProtocol`,
which uses that requirement's `Failure` type as potentially being part
of the thrown error type. This allows existing generic functions like
the following to continue to work:

    func f<S: AsyncSequence>(_: S) rethrows

* Switch SIL generation for the async for-each loop from the prior
`next()` over to the typed-throws version `_nextElement`.

* Remove `@rethrows` from `AsyncSequence` and `AsyncIteratorProtocol`
entirely. We are now fully dependent on typed throws.
2024-01-25 16:04:43 -08:00
Kavon Farvardin
3e03c674c7 [NCGenerics] remove arg from isNoncopyable(DC)
It should be the responsibility of callers to map the type to a
contextual type, as needed. When it's not possible or repetitive to do
so, there is a special-purpose function `isInterfaceTypeNoncopyable` for
 Sema.
2024-01-23 22:42:38 -08:00
Frederick Kellison-Linn
0d79f4523a Allow function-function conversions for keypath literals
Remove keypath subtype asserts; always use cached root type

Add tests for keypaths converted to funcs with inout param

Add unit test for overload selection
2024-01-23 08:51:44 -05:00
Pavel Yaskevich
be39c05df2 Merge pull request #71026 from xedin/rdar-111120803
[CSSimplify] Increase impact of requirement failures in special result builder methods
2024-01-22 13:10:59 -08:00
Pavel Yaskevich
b3152d8bc0 [CSSimplify] Increase impact of requirement failures in special result builder methods
Handle requirement failures in result builder `build*` methods explicitly
and give them a high impact rating because issues if such positions
imply that the transform didn't work and it shouldn't shadow errors
in user code.

Resolves: rdar://111120803
Resolves: rdar://120342129
2024-01-19 15:11:41 -08:00
Slava Pestov
fc9f8252cc Sema: Replace a couple of TypeChecker::getProtocol() calls with getKnownProtocolKind() checks 2024-01-17 19:59:58 -05:00
Slava Pestov
d7ce5172a0 Sema: Replace a couple of TypeChecker::getProtocol() calls with ASTContext::getProtocol() 2024-01-17 19:59:58 -05:00
Anthony Latsis
96ee57b00b Merge pull request #70623 from AnthonyLatsis/init-sema
Move unqualified `init` diagnosis from Parse to Sema
2024-01-18 03:53:33 +03:00
Kavon Farvardin
bb78171767 [NFC] forEachMissingConformance doesn't use module 2024-01-10 19:39:07 -08:00
Pavel Yaskevich
4c604b479b Merge pull request #70777 from xedin/diagnostic-improvements-for-closures
[ConstraintSystem] Closure type-checking improvements
2024-01-10 11:13:49 -08:00
Slava Pestov
597fb216cb Merge pull request #70457 from slavapestov/parameter-pack-open-type
Fix openType() handling of parameter packs
2024-01-10 13:41:08 -05:00
Slava Pestov
5d58a634ad Sema: Clean up openType() and openUnboundGenericType()
Fixes:
- rdar://112785081
- https://github.com/apple/swift/issues/67906
- https://github.com/apple/swift/issues/68160
2024-01-09 15:23:42 -05:00
Slava Pestov
855c082141 Sema: Tweak shape mismatch fixes 2024-01-09 14:43:16 -05:00
Pavel Yaskevich
61d5ae969d [CSSimplify] Avoid resolving closures passed to a parameter that doesn't accept them
Doing so improves performance if closure is passed as an argument
to a (heavily) overloaded declaration, avoid unrelated errors,
propagate holes, and record a more impactful fix.
2024-01-08 14:43:55 -08:00
Saleem Abdulrasool
d36ef3fed1 Merge pull request #63915 from AtariDreams/std-math
Ensure the correct function is called by prepending std:: to the std math functions
2024-01-04 20:30:51 -08:00
Pavel Yaskevich
6afc30761e [CSBindings] Prevent determineBestBindings from selecting unresolved key path type 2024-01-01 12:47:13 -08:00
Anthony Latsis
bd2f48d9d2 [NFC] AST: Introduce and use Identifier::isConstructor 2023-12-25 21:09:17 +03:00
Sima Nerush
2fd5843a79 Merge pull request #70355 from simanerush/pack-iteration-fixes
[SE-0408] Pack iteration review feedback!
2023-12-16 09:50:31 -08:00
Sima Nerush
0482bd3652 [Sema] Refactor code and improve documentation pertaining to SE-0408. 2023-12-15 20:39:40 -08:00
Doug Gregor
8ad137fb51 [Typed throws] Infer thrown error type for do..catch blocks within closures.
Start classifying all potential throw sites within a constraint
system and associate them with the nearest enclosing catch node. Then,
determine the thrown error type for a given catch node by taking the
union of the thrown errors at each potential throw site. Use this to
compute the error type thrown from the body of a `do..catch` block
within a closure.

This behavior is limited to the upcoming feature `FullTypedThrows`.
2023-12-13 14:59:23 -08:00
Doug Gregor
b080b5f3d8 [Typed throws] An ErrorUnion type to the type system
The errorUnion type operation specifies how thrown error types are
combined when multiple errors are thrown in the same context. When
thrown error types can have type variables in them, we sometimes cannot
resolve the errorUnion until the type variables have substitutions. In
such cases, we need to persist the result of errorUnion in the
constraint solver.

Introduce the ErrorUnionType to do exactly that, and update the core
errorUnion operation to produce an ErrorUnionType when needed. At
present, this code is inert, because any errorUnion operation today
involves only concrete types. However, inference of thrown errors in
closures will introduce type variables, and depend on this.
2023-12-08 22:30:37 -08:00
Kavon Farvardin
338d426b3d Merge pull request #70278 from kavon/refactor-InverseType
[NCGenerics] fold InverseType into PCT
2023-12-08 02:44:45 -08:00
Kavon Farvardin
63b3e7624d [NCGenerics] fold InverseType into PCT
We already need to track the inverses separate from the members in a
ProtocolCompositionType, since inverses aren't real types. Thus, the
only purpose being served by InverseType is to be eliminated by
RequirementLowering when it appears in a conformance requirement.

Instead, we introduce separate type InverseRequirement just to keep
track of which inverses we encounter to facilitate cancelling-out
defaults and ensuring that the inverses are respected after running
the RequirementMachine.
2023-12-07 22:14:23 -08:00
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