Commit Graph

28382 Commits

Author SHA1 Message Date
Pavel Yaskevich
b65da0bee0 [Concurrency] Start using default isolation set in a file scope
Infer default actor isolation from `using` declaration in the
file scope and use it to override one that is set by `-default-isolation`
flag.

(cherry picked from commit 595c3b3a62)
2025-06-04 13:22:34 -07:00
Pavel Yaskevich
7d18588f93 [Concurrency] Add a request to retrieve default isolation of a file
The default isolation is computed based on `using` declaration
found in the file, if any.

(cherry picked from commit 36b77116bd)
2025-06-04 13:21:56 -07:00
Pavel Yaskevich
d057429e9a [AST] Add new declaration - using
Initially this declaration is going to be used to determine
per-file default actor isolation i.e. `using @MainActor` and
`using nonisolated` but it could be extended to support other
file-global settings in the future.

(cherry picked from commit aabfebec03)
2025-06-04 13:16:55 -07:00
Doug Gregor
ed29e1fdcd Merge pull request #81934 from DougGregor/break-isolated-conformance-reference-cycle-6.2
Split conformance isolation request to eliminate a reference cycle
2025-06-04 10:26:52 -07:00
Doug Gregor
1a3ce94c3d Only emit the non-sendable metatype capture diagnostic under region-based isolation
We effectively suppress sendable diagnostics when region-based
isolation is disabled, and RBI is enabled whenever strict concurrency
checking is enabled. So, suppress this diagnostic when RBI is enabled.

Fixes rdar://152583759.
2025-06-04 09:48:47 -07:00
Pavel Yaskevich
6e9d97e273 Merge pull request #81945 from xedin/various-diagnostic-fixes-6.2
[6.2][Diagnostics] A collection of diagnostic fixes/improvements
2025-06-03 19:57:44 -07:00
Allan Shortlidge
5ee57368ae Merge pull request #81932 from tshortli/visionos-availability-remap-regression-6.2
[6.2] AST/Sema: Fix remapping of iOS availability in diagnostics for visionOS
2025-06-03 13:30:35 -07:00
Pavel Yaskevich
bbc6ed827d [CSSimplify] Produce tailored fixes for a few generic argument mismatches
- Mismatch in tuple element position should reference whole tuple
  with a note for mismatch position;
- Situations where optional object type is not a class but matched
  against `AnyObject` have a tailored fix.

(cherry picked from commit 7305275dbd)
2025-06-03 09:33:13 -07:00
Pavel Yaskevich
f67687b8d6 [CSSimplify] Fix matchDeepEqualityTypes to allow fixing of optionals
Attempting to propagate generic argument failures up is not always
reliable, `matchDeepEqualityTypes` should avoid using `TMF_ApplyingFix`
while dealing with optionals and instead let `repairFailures` decide
whether to use generic arguments mismatch fix to a more general one.

(cherry picked from commit 27c28d4d64)
2025-06-03 09:33:13 -07:00
Pavel Yaskevich
143931ac08 [CSSimplify] Increase impact of a generic argument mismatch if mismatch is contextual
If generic arguments mismatch ends up being recorded on the result
of the chain or `try` expression it means that there is a contextual
conversion mismatch.

For optional conversions the solver currently generates a disjunction
with two choices - bind and optional-to-optional conversion which is
anchored on the contextual expression. If we can get a fix recorded
there that would result in a better diagnostic. It's only possible
for optional-to-optional choice because it doesn't bind the
variable immediately, so we need to downgrade direct fixes to prevent
`bind` choice from considered better.

(cherry picked from commit 65e83a8bb1)
2025-06-03 09:33:13 -07:00
Pavel Yaskevich
9ae7a75f78 [CSDiagnostics] Attempt fix-its for contextual generic argument mismatches
(cherry picked from commit 71a8d8d8a4)
2025-06-03 09:33:13 -07:00
Pavel Yaskevich
fc56f3551f [CSSimplify] Remove ad-hoc optional mismatch handling for arguments
Since we have `repairViaOptionalUnwrap`, let's use that to fix
argument/parameter mismatches instead of doing ad-hoc matching.

(cherry picked from commit b12d844fcc)
2025-06-03 09:33:13 -07:00
Pavel Yaskevich
044696772b [CSSimplify] Move inout failures handing to LValueConversion block
This is cleanup that allows us to avoid a fallthrough to `ApplyArgToParam`
handling for `inout` failures.

(cherry picked from commit 2d1f9d3f18)
2025-06-03 09:33:13 -07:00
Pavel Yaskevich
a6827c605d [CSSimplify] Detect when generic argument mismatch applies to argument and produce a tailed fix
The problem detection logic currently expects `generic argument #<N>`
location to always be associated with two generic types, but that
is not always the case, this locator element is sometimes used for
i.e. optional object types and pointer `Pointee` type when types
appear in argument positions. This needs to be handled specifically.

Resolves: rdar://82971941
(cherry picked from commit ded6158cc3)
2025-06-03 09:33:13 -07:00
Pavel Yaskevich
0f1cce3d4f [Diagnostics] Assign missing member eagerly when there is no context
Without contextual information it won't be possible to bind a missing
member to a concrete type later, so let's bind them eagerly and propagate
placeholders outward.

Resolves: rdar://152021264
Resolves: https://github.com/swiftlang/swift/issues/81770
(cherry picked from commit 10186d664b)
2025-06-03 09:33:13 -07:00
Pavel Yaskevich
148e2d1fa0 [Diagnostics] Diagnose existential mismatch in a literal collection element position
If key or value of a literal collection expression doesn't conform
to protocol(s) expected by the contextual existential type, let's
diagnose that via a tailed collection mismatch fix instead of a
generic conformance one.

Resolves: rdar://103045274
(cherry picked from commit d83ec7b3a5)
2025-06-03 09:33:13 -07:00
Pavel Yaskevich
814b83b9fa [Diagnostics] Use argument mismatch fix for @autoclosure result positions
`@autoclosure` is associated with a parameter, we use argument mismatch fix
to diagnose missing explicit calls as well as any mismatches in that position.

Resolves: rdar://110527062
(cherry picked from commit b3e9cf3424)
2025-06-03 09:33:13 -07:00
Pavel Yaskevich
8a51175acb [Diagnostics] Don't attempt to force unwrap invalid optional chaining in the argument position
If the argument has an extra `?` or `!`, let's not attempt to force
optional (because it's use is already invalid) and re-introduce
the constraint with unwrapped type instead. This would help to diagnose
the invalid chaining as well as any argument to parameter mismatches.

Resolves: rdar://126080504
(cherry picked from commit ef2fa4a1b6)
2025-06-03 09:33:13 -07:00
Hamish Knight
47959ac7dc [CS] Check hasType in isPlaceholderVar
Patterns assert that a type is set in `getType`, check `hasType`
before querying.

rdar://146383201
2025-06-03 11:30:01 +01:00
Doug Gregor
a3dd168435 Split conformance isolation request to eliminate a reference cycle
Inference of conformance isolation needs to check whether all of the
witnesses are nonisolated. However, witness checking looks at
conformance isolation. To break this reference cycle, split the
conformance isolation request into two requests: a "raw" request that
looks at explicitly-specified isolation, and the existing one that
also performs inference. The existing one builds on the "raw" one, as
does a separate path for the conformance checker.

Fixes rdar://152461344.
2025-06-02 23:43:29 -07:00
Allan Shortlidge
5b79f61414 AST/Sema: Fix remapping of iOS availability in diagnostics for visionOS.
When compiling for visionOS, iOS availability attributes are remapped into the
visionOS availability domain automatically. While the version remapping was
being performed correctly, there was a regression that caused the platform name
to be printed incorrectly in many diagnostics. Whenever an iOS version is
remapped to a visionOS version, availability diagnostics will now present
those versions as visionOS versions instead of iOS versions.

Resolves rdar://146293165.
2025-06-02 22:56:47 -07:00
Doug Gregor
9b62aed6c3 Merge pull request #81911 from DougGregor/unsafe-string-interpolation-6.2
[6.2] [Strict memory safety] Adjust "unsafe" location for string interpolation
2025-06-02 21:45:24 -07:00
Doug Gregor
bd72b8fb04 [Strict memory safety] Adjust "unsafe" location for string interpolations
String interpolations can end up being unsafe in the call to
appendInterpolation when it's provided with unsafe types. Move the
location of the proposed "unsafe" out to the string interpolation
itself in these cases, which properly suppresses the warning.

Fixes rdar://151799777.
2025-06-02 12:46:17 -07:00
Allan Shortlidge
c99b19e450 AST/Sema: Make MemberImportVisibility a migratable feature.
The migration to `MemberImportVisibility` can be performed mechanically by
adding missing import declarations, so offer automatic migration for the
feature.

Resolves rdar://151931597.
2025-06-02 07:27:41 -07:00
Allan Shortlidge
f6124cbe13 AST: Simplify the interface of DiagnosticEngine::getBestAddImportFixItLoc().
For clarity, it should just take a `SourceFile`.
2025-06-02 07:27:33 -07:00
Allan Shortlidge
49b594100f AST/Sema: Remove code adding @_spi to suggested import fix-its.
The was never invoked because inaccessibility due to SPI protection level is
always diagnosed before missing imports are diagnosed. The functionality could
therefore not be tested and should be removed.
2025-06-02 07:27:22 -07:00
Hamish Knight
38744ebd2f Merge pull request #81877 from hamishknight/x-of-hearts-6.2
[6.2] Change InlineArray sugar separator `x` -> `of`
2025-05-31 23:50:05 +01:00
Holly Borla
c6cafd30ce Merge pull request #81881 from hborla/6.2-isolated-capture-fixes
[6.2][Concurrency] Fix a false-positive metatype capture diagnostic.
2025-05-31 12:44:36 -07:00
Doug Gregor
837ed71a01 Merge pull request #81883 from DougGregor/unsafe-implied-conformance-6.2
[Strict memory safety] Improve Fix-Its for implied conformances
2025-05-31 03:38:14 -07:00
Doug Gregor
d08187a2d7 [Strict memory safety] Show issues with unsafe constructs in the for..in loop
We weren't showing the unsafe uses when we determine that a for..in
loop is unsafe. Do so, which generally means complaining about `next()`
being unsafe. Fixes rdar://151237127
2025-05-30 18:45:11 -07:00
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