Commit Graph

1442 Commits

Author SHA1 Message Date
Hamish Knight
ee0e408a8c [Sema] Remove separate closure type-checking logic
`participatesInInference` is now always true for
a non-empty body, remove it along with the separate
type-checking logic such that empty bodies are
type-checked together with the context.
2024-09-08 16:17:11 +01:00
Alejandro Alonso
0df42e9841 Lower UDRE to TypeValue if it references a value generic 2024-09-04 15:13:29 -07:00
Alejandro Alonso
75c2cbf593 Implement value generics
Some requirement machine work

Rename requirement to Value

Rename more things to Value

Fix integer checking for requirement

some docs and parser changes

Minor fixes
2024-09-04 15:13:25 -07:00
Pavel Yaskevich
f9e08bc6ec Merge pull request #76174 from xedin/remodel-constraint-generation-for-assignment
[ConstraintSystem] Introduce `LValueObject` constraint to replace direct l-value assignments
2024-09-04 09:27:59 -07:00
Pavel Yaskevich
bd313deae5 Merge pull request #76136 from xedin/rdar-131321053
[ConstraintSystem] InferSendableFromCaptures: Mark unapplied operator references as `@Sendable`
2024-09-02 08:29:56 -07:00
Pavel Yaskevich
be0bf46657 [CSGen] Set correct ref kinds on synthesized makeIterator and next for for-in loops 2024-08-30 15:26:54 -07:00
Pavel Yaskevich
2e53bc26cd [CSSimplify] Implement LValueObject constraint simplification 2024-08-29 10:10:14 -07:00
Hamish Knight
3c16ecf568 [Sema] Remove preCheckExpression
There are only a couple of clients left using this,
migrate them onto `preCheckTarget`.
2024-08-28 15:09:40 +01:00
Slava Pestov
b601c294ac AST: Replace remaining uses of Type::transform() with transformRec() 2024-08-12 16:05:43 -04:00
Slava Pestov
375363a473 AST: Move global conformance lookup entry points to ConformanceLookup.h 2024-08-08 23:35:58 -04:00
Greg Titus
d87e049cde Improve diagnoses of generic specializations
Always add constraints, find fixes during simplify.
New separate fix for allow generic function specialization.
Improve parse heuristic for isGenericTypeDisambiguatingToken.
Degrade concrete type specialization fix to warning for macros.
2024-07-30 18:51:34 -07:00
Pavel Yaskevich
0343bb18af Revert "[Sema] Add specialization constraints for func and variable types, then diagnose w/fixes." 2024-07-25 15:43:15 -07:00
Greg Titus
47acc09e11 Merge pull request #74909 from gregomni/generic-arg
[Sema] Add specialization constraints for func and variable types, then diagnose w/fixes.
2024-07-24 19:38:11 -07:00
Greg Titus
6e917b567a Improve diagnoses of generic specializations
Always add constraints, find fixes during simplify.
New separate fix for allow generic function specialization.
Improve parse heuristic for isGenericTypeDisambiguatingToken.
2024-07-24 14:25:11 -07:00
Hamish Knight
4beaaf32ad [CS] Improve placeholder diagnostics slightly
Make sure `CouldNotInferPlaceholderType` can
produce a diagnostic for a `PlaceholderType`
locator element, and avoid emitting an extra
diagnostic for a placeholder type in an invalid
position.
2024-07-07 23:42:33 +01:00
Slava Pestov
86d567f95a AST: ModuleDecl::lookupConformance() is a static method 2024-07-06 12:05:47 -04:00
Slava Pestov
3fcda140bb AST: ModuleDecl::checkConformance() is a static method 2024-07-06 12:05:46 -04:00
Slava Pestov
fae01d9776 AST: Remove ModuleDecl parameter from more places 2024-07-06 12:05:46 -04:00
Ben Barham
d72f5b12c4 Update StringRef::equals references to operator==
`equals` has been deprecated upstream, use `operator==` instead.
2024-06-27 19:14:06 -07:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Holly Borla
cdfe3364be Merge pull request #74509 from hborla/fix-infer-sendable-from-global-actor
[Concurrency] Fix `@Sendable` inference for global-actor-isolated function types.
2024-06-18 07:08:10 -07:00
Holly Borla
1406b28de0 [Concurrency] Consider the upcoming feature flags in the originating module when
applying `@Sendable` inference for global-actor-isolated function types.

Otherwise, for libraries that do not enable `GlobalActorIsolatedTypesUsability`,
clients that do will encounter mangling mismatches for any library APIs that
have global-actor-isolated function types that are not explicitly `@Sendable`.
2024-06-17 18:01:45 -07:00
Michael Gottesman
81100ad660 [sending] Fix type inference for sending results of closures.
The previous commit fixed things like:

```swift
let x: () -> sending String = { "" }
```

This commit fixes this test case:

```swift
let x = { () -> sending String in "" }
```
2024-06-12 16:59:24 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Doug Gregor
6559ed6b6b Merge pull request #73912 from DougGregor/async-for-each-next-isolation-availability
Fix source location info to address availability error with `next(isolation:)`.
2024-05-25 10:13:08 -07:00
Doug Gregor
3564d14a84 Fix source location info to address availability error with next(isolation:)
Due to a missing source location in the implicitly-generated `await` in the
async for loop, we misdiagnosed availability within an `if #available`.

Fixes rdar://128560745.
2024-05-24 22:29:42 -07:00
Pavel Yaskevich
888ab81c1e [ConstraintSystem] Connect closure to outer pack expansions it appears in
Type variable reference collector needs to be augmented to collect
type variables associated with pack expansions that a closure references
elements of, otherwise it would get disconnected from the context.
2024-05-22 14:42:39 -07:00
Slava Pestov
da31c59bcb Sema: Track active pack expansions across closure boundaries 2024-04-30 21:38:45 -04:00
Anthony Latsis
1b0d383853 [NFC] Sema: Move diagnosis of super in illegal context from CSGen to PreCheckExpr 2024-04-18 23:07:14 +03:00
Anthony Latsis
9017bf77b1 Sema: Improve error messages for super in illegal context 2024-04-18 23:07:14 +03:00
Holly Borla
78384d596d [Concurrency] Add ExtractFunctionIsolationExpr to represent the isolation
of a dynamically isolated function value in the AST.
2024-03-13 19:55:15 -07:00
cui fliter
127077b3aa chore: fix some comments
Signed-off-by: cui fliter <imcusg@gmail.com>
2024-03-05 17:23:22 +08:00
Hamish Knight
8b42107a4e [CS] Rename SyntacticElementTarget::forEachStmt -> forEachPreamble
This more closely matches what we're actually
type-checking, since we do not currently include
the body.
2024-03-04 11:56:24 +00:00
Ben Barham
f292ec9784 Use the new template deduction guides rather than makeArrayRef
LLVM has removed `make*ArrayRef`, migrate all references to their
constructor equivalent.
2024-02-23 20:04:51 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Holly Borla
ddf2fc44f4 [Concurrency] Allow #isolation to have a more specific contextual type. 2024-02-16 16:27:54 -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
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
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
d981cf3b77 Sema: De-requestify TypeBase::isNoncopyable() and TypeBase::isEscapable()
And consolidate the logic in ConformanceLookup.cpp.
2024-02-05 11:25:57 -05:00
Hamish Knight
16cfca4186 [ASTWalker] NFC: Rename SkipChildren -> SkipNode
This better describes what the action currently
does, and allows us to re-introduce `SkipChildren`
with the correct behavior.
2024-02-05 15:27:25 +00:00
Hamish Knight
94c4d117a1 Remove some redundant post walks 2024-02-05 15:27:25 +00:00
Hamish Knight
d9fd4c75b1 [CS] Remove isInputExpression parameter
This wasn't consistently used, and consequently
could result in some expressions getting their
parents invalidated. Instead, replace it with a
query to make sure we don't try and add an
expression we've already computed the parent info
for.
2024-01-31 20:26:20 +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
Sima Nerush
066f253d2e Merge pull request #70196 from simanerush/nested-pack-iteration
[SE-0408] Enable nested iteration
2024-01-27 10:18:12 -08:00
Sima Nerush
0b167b55b1 [ConstraintSystem] Cache pack element generic environments associated withfor-in loops over parameter packs to apply in getPackElementEnvironment. 2024-01-27 00:12:33 -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