Commit Graph

2514 Commits

Author SHA1 Message Date
Slava Pestov
6027bf46a6 AST: Simplify collectExistentialConformances() 2024-02-10 09:36:37 -05:00
Kavon Farvardin
74a3839cf3 Merge pull request #71515 from kavon/ncgenerics-test-fixes-kavon-v7
Ncgenerics test fixes kavon v7
2024-02-09 19:39:18 -08:00
Slava Pestov
06b1aee360 Evaluator: Cache circular evaluation to avoid redundant diagnostics
Previously, if a request R evaluated itself N times, we would emit N
"circular reference" diagnostics. These add no value, so instead let's
cache the user-provided default value on the first circular evaluation.

This changes things slightly so that instead of returning an
llvm::Expected<Request::OutputType>, various evaluator methods take
a callback which can produce the default value.

The existing evaluateOrDefault() interface is unchanged, and a new
evaluateOrFatal() entry point replaces
llvm::cantFail(ctx.evaluator(...)).

Direct callers of the evaluator's operator() were updated to pass in
the callback. The benefit of the callback over evaluateOrDefault() is
that if the default value is expensive to constuct, like a dummy
generic signature, we will only construct it in the case where a
cycle actually happened, otherwise we just delete the callback.

(cherry picked from commit b8fcf1c709efa6cd28e1217bd0efe876f7c0d2b7)
2024-02-09 16:02:24 -08:00
Kavon Farvardin
7bf570d579 NCGenerics: conformance to Any does not always hold
`Any` now implies the requirements `Copyable & Escapable`. Check it like
 any ordinary existential.
2024-02-09 15:46:43 -08:00
Doug Gregor
a4f0709c2f Rename AsyncIteratorProtocol.next(_:) to next(isolation:)
Match the name of the method as specified in SE-0421
2024-02-09 14:18:37 -08:00
Kavon Farvardin
d768c75134 NCGenerics: narrow use of custom diagnostics
In some cases we get a `ConstraintKind::SelfObjectOfProtocol` here.
That's typically for an existential cast. In such a case, we actually
get a better standard diagnostic than what MustBeCopyable can produce
currently. So this change narrows things to what MustBeCopyable is
better at diagnosing.
2024-02-09 12:35:15 -08:00
Hamish Knight
2c77947000 Merge pull request #71006 from hamishknight/implicit-last-expression
Introduce implicit last expression results
2024-02-08 10:15:01 +00:00
Kavon Farvardin
aaf2f7e565 Merge pull request #71438 from kavon/ncgenerics-test-fixes-kavon-v4
Ncgenerics test fixes kavon v4
2024-02-07 19:28:11 -08:00
Kavon Farvardin
056493b079 NCGenerics: fix !hasTypeVariable() assert 2024-02-07 11:05:08 -08:00
Hamish Knight
1003b2f30b [CS] Remove CTP_ImpliedReturnStmt
Unify with `CTP_ReturnStmt`, and have the
SyntacticElementTarget carry the ReturnStmt for
regular type-checking, which we can use to record
implied returns.
2024-02-07 18:14:23 +00:00
Hamish Knight
61a4148925 [CS] Generalize implied result handling
Track the implied result exprs in the constraint
system, and allow arbitrary propagation of
implied results down if/switch expression
branches. This is required for allowing implied
results in non-single-expression closures.
2024-02-07 18:14:22 +00:00
John McCall
2f8a33cf0a Experimental type-checking support for @isolated(any) function types. 2024-02-06 22:54:27 -05:00
Slava Pestov
d46bd335de Merge pull request #71371 from slavapestov/ncgenerics-fixes-3
Non-copyable generics fixes, part 3
2024-02-06 08:35:07 -05:00
Slava Pestov
a68c806290 Sema: Skip a legacy check when built with SWIFT_ENABLE_EXPERIMENTAL_NONCOPYABLE_GENERICS 2024-02-05 11:25:57 -05:00
Freddy Kellison-Linn
aedf854e33 Follow ups for keypath function conversion PR 2024-02-03 13:41:22 -05:00
Frederick Kellison-Linn
0735629c8d Merge pull request #39612 from Jumhyn/keypath-function-conversion
[ConstraintSystem] Allow function-function conversions for keypath literals
2024-02-03 10:26:13 -08:00
Hamish Knight
27c08b130a Merge pull request #71123 from hamishknight/sema-expr-return
Move the single-expr return transform from Parse to Sema
2024-01-31 10:13:24 +00:00
Doug Gregor
29cfe61472 Merge pull request #71253 from DougGregor/hash-table-iteration-considered-harmful
Fix nondeterminism in explicitly-specified generic macro arguments
2024-01-30 15:21:40 -08:00
Doug Gregor
7712903f6b Fix nondeterminism in explicitly-specified generic macro arguments
A hash table got flattened into an array without any ordering guarantees,
and then we assumed it was in order. Fixes rdar://121397992.
2024-01-30 12:40:23 -08:00
Hamish Knight
9b64990d24 [AST] Remove the "single expression body" bit
Remove this bit from function decls and closures.
Instead, for closures, infer it from the presence
of a single return or single expression AST node
in the body, which ought to be equivalent, and
automatically takes result builders into
consideration. We can also completely drop this
query from AbstractFunctionDecl, replacing it
instead with a bit on ReturnStmt.
2024-01-30 14:08:54 +00:00
Doug Gregor
0cc529768a Merge pull request #70635 from DougGregor/async-sequence-typed-throws
Adopt typed throws in AsyncIteratorProtocol and AsyncSequence
2024-01-29 11:51:25 -08:00
Pavel Yaskevich
3ed09325bc Merge pull request #71196 from xedin/rdar-121692664
[CSSimplify] Matching function types with variadic parameters should …
2024-01-29 10:02:18 -08:00
Pavel Yaskevich
eb05750f28 [CSSimplify] Matching function types with variadic parameters should account for contravariance
Resolves: rdar://121692664
2024-01-26 16:27:08 -08:00
John McCall
b0fb03d8c7 Create a uniform representation for function type isolation.
Not quite NFC because apparently the representation bleeds into what's
accepted in some situations where we're supposed to be warning about
conflicts and then making an arbitrary choice.  But what we're doing
is nonsense, so we definitely need to break behavior here.

This is setting up for isolated(any) and isolated(caller).  I tried
to keep that out of the patch as much as possible, though.
2024-01-25 22:11:01 -05:00
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