Commit Graph

28352 Commits

Author SHA1 Message Date
Anthony Latsis
5b71a7dd7a Merge pull request #82156 from AnthonyLatsis/camellia-sinensis-6.2
[6.2] Sema: Never record argument label mismatches for unlabeled trailing closures
2025-06-11 04:49:31 +01:00
Pavel Yaskevich
27cd5eef15 Merge pull request #82114 from xedin/rdar-150689994-6.2
[6.2][Diagnostics] Correctly diagnose situations when immutable value is passed to `inout` parameter
2025-06-10 09:11:10 -07:00
Pavel Yaskevich
dfd21ba699 Merge pull request #82130 from xedin/rdar-151943924-6.2
[6.2][TypeCheckEffects] Fix `AbstractFunction::getType` to look through al…
2025-06-10 08:44:12 -07:00
Hamish Knight
bd4c3adb92 [CS] Make CSRanking change slightly less risky for 6.2
Check for `isSolverAllocated` rather than
`hasTypeVariableOrPlaceholder`, and downgrade an `ASSERT` to
`CONDITIONAL_ASSERT`.
2025-06-10 16:18:24 +01:00
Hamish Knight
cc66fc886f [CS] Avoid solver-allocated inputs with typesSatisfyConstraint
Escaping solver-allocated types into a nested allocation arena is
problematic since we can e.g lazily compute the `ContextSubMap` for a
`NominalOrBoundGenericNominalType`, which is then destroyed when we
exit the nested arena. Ensure we don't pass any types with type
variables or placeholders to `typesSatisfyConstraint`.

rdar://152763265
2025-06-10 16:08:00 +01:00
Anthony Latsis
da1922f0bf Sema: Never record argument label mismatches for unlabeled trailing closures
Fixes a crash on invalid. The previous logic was causing a label
mismatch constraint fix to be recorded for an unlabeled trailing closure
argument matching a variadic paramater after a late recovery argument
claim in `matchCallArgumentsImpl`, because the recovery claiming skips
arguments matching defaulted parameters, but not variadic ones. We may
want to reconsider that last part, but currently it regresses the
quality of some diagnostics, and this is a targeted fix.

The previous behavior is fine because the diagnosis routine associate
with the constraint fix (`diagnoseArgumentLabelError`) skips unlabeled
trailing closures when tallying labeling issues — *unless* there are no
other issues and the tally is zero, which we assert it is not.

Fixes rdar://152313388.

(cherry picked from commit f2e1420a90)
2025-06-10 15:28:41 +01:00
Pavel Yaskevich
f8a3c3b1ff [TypeCheckEffects] Fix AbstractFunction::getType to look through all levels of optional
A member and a parameter could be wrapped in an arbitrary number
of `Optional`, we need to look through all of them to get to the
underlying function type.

Resolves: rdar://151943924
(cherry picked from commit 86390ab91f)
2025-06-09 17:18:11 -07:00
Pavel Yaskevich
a9e5a8a07a [Diagnostics] Correctly diagnose situations when immutable value is passed to inout parameter
Currently the note is going to point to the "callee" but that is
incorrect when the failure is related to an argument of a call.

Detect this situation in `RValueTreatedAsLValueFailure::diagnoseAsNote`
and produce a correct note.

Resolves: rdar://150689994
(cherry picked from commit 6bbc101a98)
2025-06-09 09:39:12 -07:00
Pavel Yaskevich
3ca6228246 [ConstraintSystem] Look through ArgumentAttribute element when computing a callee
This element is used purely for diagnostic purposes and locator
should behavior as if it's completely transparent.

(cherry picked from commit 622475bf15)
2025-06-09 09:39:12 -07:00
Pavel Yaskevich
47925188ba [Concurrency] Fix SendableMetatype conformance failures to behave like Sendable ones
No warnings with minimal checking, warnings with `strict-concurrency=complete` and
if declaration is `@preconcurrency` until next major swift version.

Resolves: rdar://151911135
Resolves: https://github.com/swiftlang/swift/issues/81739
(cherry picked from commit e326cd00930ff042ba1595e7793af9aaf0208b97)
2025-06-06 08:51:05 -07:00
Pavel Yaskevich
2a3e2d0800 Merge pull request #82037 from xedin/rdar-146027395-6.2
[6.2][Concurrency] Downgrade errors to warnings when Sendable requirement is inferred from a preconcurrency protocol
2025-06-06 08:49:20 -07:00
Allan Shortlidge
f82c0b71a2 Sema: Fix an unused variable warning. 2025-06-05 15:44:27 -07:00
Pavel Yaskevich
fe2c8ef00a [Diagnostics] Use contains instead of has when non-Sendable type appears inside of a member type
(cherry picked from commit 3495c61840)
2025-06-05 14:48:20 -07:00
Pavel Yaskevich
ace1e527d1 [Concurrency] Downgrade errors to warnings when Sendable requirement is inferred from a preconcurrency protocol
If a type gets `Sendable` conformace requirement through another
`@preconcurrency` protocol the error should be downgraded even
with strict concurrency checking to allow clients time to address
the new requirement.

Resolves: rdar://146027395
(cherry picked from commit 6d45229367)
2025-06-05 14:48:01 -07:00
Pavel Yaskevich
a947450a4d [Concurrency] NFC: Rename ImpliedByStandardProtocol to ImpliedByPreconcurrencyProtocol
The new name better reflects the intention for this Sendable check kind.

(cherry picked from commit 7cca7225a1)
2025-06-05 14:48:01 -07:00
Pavel Yaskevich
82f04e5b78 [Concurrency] Clean-up duplicate code in checkSendableInstanceStorage
(cherry picked from commit e24196e365)
2025-06-05 14:48:01 -07:00
Pavel Yaskevich
608a37ad04 Merge pull request #81997 from xedin/using-for-default-isolation-in-file-context-6.2
[6.2][AST/Sema] SE-0478: Implement using declaration under an experimental flag
2025-06-05 00:44:21 -07:00
Doug Gregor
3604f8918c Merge pull request #81985 from DougGregor/non-sendable-metatype-capture-diag-fixes-6.2
[6.2] Minor fixes for the non-sendable meta type capture diagnostics
2025-06-04 17:59:17 -07:00
Pavel Yaskevich
f72efd8327 [TypeChecker] Disable use of using in macro extensions
(cherry picked from commit 83ac0f5042)
2025-06-04 13:23:17 -07:00
Pavel Yaskevich
e5501d485a [AST] NFC: Capitalize UsingSpecifier::nonisolated for consistency
(cherry picked from commit 21ec5924f7)
2025-06-04 13:22:34 -07:00
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