Commit Graph

28352 Commits

Author SHA1 Message Date
Doug Gregor
c70699c9fe [Strict memory safety] Improve Fix-Its for implied conformances
The Fix-It was adding @unsafe prior to the extension, which is
incorrect. Make sure we apply @unsafe at the right location for the
explicit conformance.

Fixes rdar://151800162
2025-05-30 18:33:47 -07:00
Holly Borla
61a2143fdf [Concurrency] Don't diagnose metatype captures in closures that are
isolated to the same actor as the enclosing context.

(cherry picked from commit f0e77c7814)
2025-05-30 16:09:13 -07:00
Holly Borla
bbc3c42e39 [Concurrency] Remove some dead code from mayExecuteConcurrentlyWith.
This code is no longer used given that region isolation is always enabled
along with strict concurrency checking.

(cherry picked from commit c283ce12d5)
2025-05-30 16:09:00 -07:00
Hamish Knight
f1c37f4e7d Change InlineArray sugar separator x -> of 2025-05-30 22:06:29 +01:00
Doug Gregor
0ed5cff7cc Merge pull request #81744 from DougGregor/more-migratable-features-6.2
[6.2] Make `InferIsolatedConformances` and `StrictMemorySafety` migratable features
2025-05-30 00:52:37 -07:00
Doug Gregor
60024c3c3b Always emit "unsafe does not cover any unsafe constructs" warning
Check for unsafe constructs in all modes, so that we can emit the
"unsafe does not cover any unsafe constructs" warning consistently.
One does not need to write "unsafe" outside of strict memory safety
mode, but if you do... it needs to cover unsafe behavior.

(cherry picked from commit 1b94c3b3d6)
2025-05-29 15:10:43 -07:00
Konrad `ktoso` Malawski
79a43f2cc9 Merge pull request #81798 from ktoso/pick-3b94f009d66667f6f32e50ad85d3990159a91a84
[6.2][Distributed] account Distributed module use from DA declarations
2025-05-29 09:19:12 +09:00
Doug Gregor
0c7c1fb1a7 Make the optional feature StrictMemorySafety migratable
This feature is essentially self-migrating, but fit it into the
migration flow by marking it as migratable, adding
`-strict-memory-safety:migrate`, and introducing a test.

(cherry picked from commit abad2fae0f)
2025-05-28 16:15:15 -07:00
Doug Gregor
a9d526269a Make InferIsolatedConformances a migratable upcoming feature
When migrating, provide warnings that add 'nonisolated' to nonisolated
conformances that don't already have it and would end up being inferred
to be isolated under the upcoming feature.

(cherry picked from commit a32782bcbc)
2025-05-28 16:15:12 -07:00
Steven Wu
28360605e7 Merge pull request #81720 from cachemeifyoucan/eng/PR-release-148752988-151339073-151395300
[6.2][Caching] Swift Caching Dependency Scanning Improvements
2025-05-28 11:44:00 -07:00
Konrad 'ktoso' Malawski
11bc2c2009 [Distributed] account Distributed module use from DA declarations
When issuing warnings about an import not needing to be public, we did
not account for the Distributed module MUST be imported when a
distributed actor is declared. This also actually means that a public
distributed actor effectively is a public use of the DistributedActor
protocol

resolves rdar://152129980
2025-05-28 12:57:37 +09:00
Slava Pestov
c69060356b Merge pull request #81750 from slavapestov/existential-parameterized-composition-6.2
[6.2] Allow existential parameterized compositions: `any P<A> & Q`
2025-05-27 16:36:37 -04:00
Allan Shortlidge
2ab55a8973 Sema: Omit internal from MemberImportVisibility fix-its when appropriate.
Omit an explicit access level from `MemberImportVisibility` fix-its under the
following conditions:

- `InternalImportsByDefault` is enabled.
- The required import needs an `internal` access level or lower.
- The module is not yet imported explicitly in any other file.

Resolves rdar://149577615.
2025-05-26 22:39:32 -07:00
Slava Pestov
0c44681cad Merge pull request #81694 from slavapestov/fix-rdar145184871-6.2
[6.2] Sema: Don't diagnose implied conformance of imported type to Sendable
2025-05-24 09:00:55 -04:00
Doug Gregor
e2ee46d724 Merge pull request #81743 from DougGregor/no-unchecked-6.2 2025-05-24 03:58:49 +01:00
Slava Pestov
58a9435485 Sema: Don't complain about implied Sendable conformance of imported type being retroactive
- Fixes rdar://145184871.
2025-05-23 14:34:33 -04:00
Slava Pestov
1e35ffff68 Sema: Fix diagnoseRetroactiveConformances() to handle protocol compositions 2025-05-23 14:34:33 -04:00
Slava Pestov
7c4564cbdc Sema: Allow parameterized existential compositions 2025-05-23 14:20:35 -04:00
Pavel Yaskevich
7077ef5ccf Merge pull request #81737 from xedin/rdar-151720646-6.2
[6.2][TypeChecker] Improve diagnostics for access to actor-isolated values…
2025-05-23 10:12:46 -07:00
Pavel Yaskevich
d0d0afb131 Merge pull request #81718 from xedin/rdar-151797372-6.2
[6.2][CSApply] Don't inject global actor into closure type if it's marked …
2025-05-23 09:09:16 -07:00
Doug Gregor
3eb28dcc81 Remove the note that suggests using @unchecked
`@unchecked Sendble` is dangerous, and almost always the wrong thing to
use. Don't have the compiler suggest it.

(cherry picked from commit a922e8e356)
2025-05-23 16:08:59 +01:00
Pavel Yaskevich
dd95c60c70 [TypeChecker] Improve diagnostics for access to actor-isolated values outside of the actor
Replaces generic `expression is 'async' but is not marked with 'await`
diagnostic with a tailed one for cases where there is an access to an
actor-isolated value outside of its actor without `await` keyword.

This makes the diagnostics for async and sync contexts consistent
and actually identifies a problem instead of simply pointing out
the solution.

Resolves: rdar://151720646
(cherry picked from commit 7a6ba8e8c58c58b3438f31fec06102d02bae81a5)
2025-05-22 23:52:02 -07:00
Pavel Yaskevich
c5828ad362 [Concurrency] Fix @_inheritActorContext(always) to use forActorInstanceCapture for parameters
SILGen expects actor instance isolation to always come from captures,
we need to maintain that with implicit isolation capture performed by
`@_inheritActorContext(always)`.

(cherry picked from commit 91047446ad)
2025-05-22 11:32:37 -07:00
Pavel Yaskevich
e12201769d [AST/Sema/SIL] Implement @_inheritActorContext(always)
- Extend `@_inheritActorContext` attribute to support optional `always` modifier.
  The new modifier will make closure context isolated even if the parameter is not
  captured by the closure.
- Implementation `@_inheritActorContext` attribute validation - it could only be
  used on parameter that have `@Sendable` or `sending` and `@isolated(any)` or
  `async` function type (downgraded to a warning until future major Swift mode
  to avoid source compatibility issues).
- Add a new language feature that guards use of `@_inheritActorContext(always)` in swift interface files
- Update `getLoweredLocalCaptures` to add an entry for isolation parameter implicitly captured by `@_inheritActorContext(always)`
- Update serialization code to store `always` modifier

(cherry picked from commit 04d46760bb)
(cherry picked from commit c050e8f75a)
(cherry picked from commit c0aca5384b)
(cherry picked from commit a4f6d710cf)
(cherry picked from commit 6c911f5d42)
(cherry picked from commit 17b8f7ef12)
2025-05-22 11:32:35 -07:00
Steven Wu
4670acf7f9 [Caching] Reduce the number of cas ID passed on frontend commandline
Using IncludeTree::FileList to concat the include tree file systems that
are passed on the command-line. This significantly reduce the
command-line size, and also makes the cache key computation a lot
faster.

rdar://148752988
(cherry picked from commit 201e4faea7)
2025-05-22 11:12:31 -07:00
Pavel Yaskevich
b79e922a50 [CSApply] Don't inject global actor into closure type if it's marked as @concurrent
When the attribute is specified explicitly passing a `@concurrent`
closure to a global actor-isolated parameter or contextual type
should result in a conversion and closure itself should be nonisolated.

Resolves: rdar://151797372
(cherry picked from commit efc6efc4ed)
2025-05-22 10:15:39 -07:00
Doug Gregor
214536eef7 Merge pull request #81677 from DougGregor/unsafe-pattern-match-6.2
[6.2] Handle unsafe pattern match expressions correctly
2025-05-22 02:18:46 +01:00
Anthony Latsis
c1ad869e63 Merge pull request #81655 from AnthonyLatsis/acer-campestri-2-6.2
[6.2] Sema: Fix an issue with `NonisolatedNonsendingByDefault` migration fo…
2025-05-21 20:36:58 +01:00
Doug Gregor
d794c95d44 Improve diagnostic for unsafe call arguments
Use the argument type rather than the (potentially generic) parameter type.
2025-05-21 13:48:18 +01:00
Doug Gregor
5ec166ac9a [Strict memory safety] Lift "unsafe" in pattern match expressions
When an "unsafe" expression is used as the case expression, lift it up
so it also covers the synthesized matching expression (`=~`). This
eliminates some unsuppressible strict memory safety warnings.

Fixes rdar://151731850.
2025-05-21 13:48:18 +01:00
Anthony Latsis
ee4d103500 Sema: Fix an issue with NonisolatedNonsendingByDefault migration for closures
See the inline comments for more details. Depending on the closure's
type signature, sometimes adding the attribute will break code. Fix this
by also adding inferred effects to the signature in these cases.

(cherry picked from commit 2d7e040d4d)
2025-05-21 00:10:00 +01:00
Pavel Yaskevich
ba23f1baa9 [Concurrency] Infer @preconcurrency @MainActor in default main actor mode for language modes < 6
`@MainActor` errors are hard errors, even in minimal concurrency checking in Swift 5 mode.
When users set the default isolation to main actor, we should infer `@preconcurrency @MainActor`
in language modes < 6 to get the right diagnostic staging behavior.

Resolves: rdar://151029517
(cherry picked from commit 6561476059)
2025-05-20 09:06:31 -07:00
Pavel Yaskevich
b923bf401f Merge pull request #81577 from xedin/rdar-130168104-6.2
[6.2][Concurrency] Diagnose loss of global actor isolation in async functi…
2025-05-19 13:53:50 -07:00
Anthony Latsis
810fbcee9c Merge pull request #81573 from AnthonyLatsis/pinus-sibirica-6.2
[6.2] AST, Sema: Cherry-pick 4 `NonisolatedNonsendingByDefault` bug fixes
2025-05-17 07:06:11 +01:00
Hamish Knight
d7286eb231 Merge pull request #81554 from hamishknight/last-straw-6.2
[6.2] [Sema] Continue type-checking `for` body when preamble fails
2025-05-16 23:57:12 +01:00
Pavel Yaskevich
1336dd4cb5 [Concurrency] Diagnose loss of global actor isolation in async function conversions
Perform `Sendable` checking on parameter/result of the function
type when conversion between asynchroneous functions results in
a loss of global actor isolation attribute because access would
result in data crossing an isolation boundary.

This is a warning until Swift language mode 6.

Resolves: rdar://130168104
(cherry picked from commit a058ffc998)
2025-05-16 15:21:03 -07:00
Anthony Latsis
e5a10a37d0 Sema: Fix UB in NonisolatedNonsendingByDefault migration diagnosis
The diagnostic can outlive the locally constructed attribute, which was
passed by pointer, if there is an active `DiagnosticTransaction`.

(cherry picked from commit f4e49d5a0a)
2025-05-16 21:25:08 +01:00
Anthony Latsis
58893716f9 TypeCheckType: Do not emit migration mode diags if nonisolated(nonsending) is explicit
This broke when we split `@execution(...)` into `@concurrent` and
`nonisolated(nonsending)` because the latter became its own `TypeRepr`,
whereas the condition for whether to attempt migration diagnostics
inside `resolveASTFunctionType` is still based on the function type's
attributes alone.

(cherry picked from commit bee2b6778e)
2025-05-16 21:24:54 +01:00
Pavel Yaskevich
f41e6598d7 [CSGen] Prevent @concurrent on closures from skipping throws inference
Introduction of `@concurrent` attribute caused an unintended
side-effect in `ClosureEffectsRequest` since the attribute
could only be used on `async` types setting `async` too early
prevented body analysis for `throws` from running.

Resolves: rdar://151421590
(cherry picked from commit cda9866b26)
2025-05-16 21:24:23 +01:00
Hamish Knight
e5fb276485 [Sema] Continue type-checking for body when preamble fails
Skipping type-checking the body when the preamble fails to type-check
seems to be more of a historical artifact than intentional behavior.
Certain elements of the body may still get type-checked through
request evaluation, and as such may introduce autoclosures that won't
be properly contextualized. 

Make sure we continue type-checking the body even if the preamble
fails. We already invalidate any variables bound in the element
pattern, so downstream type-checking should be able to handle it
just fine. This ensures autoclosures get contextualized, and that
we're still able to provide semantic diagnostics for other issues in
the body.

rdar://136500008
2025-05-16 14:04:18 +01:00
Pavel Yaskevich
61c8e70c66 [Feature] Rename Feature APIs from adoption to migration
(cherry picked from commit 085078dd8a)
2025-05-14 20:28:46 -07:00
Michael Gottesman
e92e9dff0c Make Feature a struct enum so we can put methods on it.
Just noticed this as I was looking at making other changes.

(cherry picked from commit 3ff9463957)
2025-05-14 16:07:04 -07:00
Doug Gregor
a98ea99f2f Merge pull request #81467 from DougGregor/objc-enum-unsafe-bit-cast-warning-6.2
[6.2] [Strict memory safety] Squash warning about unsafety in "@objc enum" synthesized code
2025-05-13 07:16:06 -07:00
Pavel Yaskevich
336be3c632 Merge pull request #81453 from xedin/fix-csapply-to-avoid-marking-autoclosure-closures-as-nonimplicit-6.2
[6.2][CSApply] Don't attempt to mark autoclosures as non-implicit
2025-05-13 00:47:42 -07:00
Artem Chikin
5740ae7bf9 Merge pull request #81452 from artemcm/DepScanFewerClangs-62
[6.2 🍒][Dependency Scanning][Refactor] Reduce the number of ClangImporter instances used by the scanner
2025-05-12 22:09:01 -07:00
Doug Gregor
7b6fe8ffc5 [Strict memory safety] Squash warning about unsafety in "@objc enum" synthesized code
There's a synthesized call to unsafeBitCast(_:to:), which is obvious
unsafe, and is being diagnosed as such. The compiler generates this
call, so have the compiler also generate the `unsafe` around it to
suppress these warnings.

Fixes rdar://151199011.
2025-05-12 21:32:57 -07:00
Pavel Yaskevich
b967cf4f53 [CSApply] Don't attempt to mark autoclosures as non-implicit
While building an initializer call the declaration reference
should have the same implicitness as the call when it doesn't
require thunking, otherwise don't attempt to mark autoclosures
as non-implicit because it could break assumptions elsewhere.

(cherry picked from commit 37e2f374aa)
2025-05-12 10:40:37 -07:00
Artem Chikin
fc23c6b460 [Dependency Scanning] Remove 'ClangImporter' instance from dependency scanning worker
Move relevant logic directly into the worker
2025-05-12 10:01:45 -07:00
Doug Gregor
760d0a35df [SE-0470] Include isolated conformance checks for default value expressions
Per SE-0411, we compute the isolation of a default value expression
based on what isolation it requires. Include isolated conformance
checks in this computation, rather than always emitting diagnostics,
so that the combination of isolated default values + isolated
conformances works as expected.

Fixes rdar://150691429.
2025-05-12 09:51:29 -07:00
Doug Gregor
009f868922 Merge pull request #81344 from DougGregor/infer-nonisolated-conformances-from-witnesses-6.2 2025-05-10 08:27:04 -07:00