Commit Graph

28619 Commits

Author SHA1 Message Date
Pavel Yaskevich
aaf153d7a1 [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
2025-06-06 08:48:29 -07:00
Pavel Yaskevich
622475bf15 [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.
2025-06-05 22:30:46 -07:00
Alexis Laferrière
5df615d3e0 Sema: Reject enums marked with both @cdecl and @objc 2025-06-05 13:46:36 -07:00
Pavel Yaskevich
3495c61840 [Diagnostics] Use contains instead of has when non-Sendable type appears inside of a member type 2025-06-05 11:14:55 -07:00
Pavel Yaskevich
6d45229367 [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
2025-06-05 11:13:38 -07:00
Pavel Yaskevich
7cca7225a1 [Concurrency] NFC: Rename ImpliedByStandardProtocol to ImpliedByPreconcurrencyProtocol
The new name better reflects the intention for this Sendable check kind.
2025-06-05 11:13:37 -07:00
Pavel Yaskevich
e24196e365 [Concurrency] Clean-up duplicate code in checkSendableInstanceStorage 2025-06-05 11:13:37 -07:00
Anthony Latsis
f2e1420a90 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.
2025-06-05 18:01:20 +01:00
Anthony Latsis
7c431c9a9a [NFC] Make a function static 2025-06-05 17:59:34 +01:00
John McCall
b3493bfa23 Prevent PrintOptions from being implicitly copied.
NFC *except* that I noticed a bug by inspection where we suppress
`@escaping` when print enum element types. Since this affects
recursive positions, we end up suppressing `@escaping` in places
we shouldn't. This is unlikely to affect much real code, but should
still obviously be fixed.

The new design is a little sketchy in that we're using `const` to
prevent direct use (and allow initialization of `const &` parameters)
but still relying on modification of the actual object.  Essentially,
we are treating the `const`-ness of the reference as a promise to leave
the original value in the object after computation rather than a
guarantee of not modifying the object. This is okay --- a temporary
bound to a `const` reference is still a non-`const` object formally
and can be modified without invoking UB --- but makes me a little
uncomfortable.
2025-06-05 12:52:01 -04:00
Mykola (Nickolas) Pokhylets
87e536ebec Merge pull request #80440 from nickolas-pohilets/mpokhylets/weak-let 2025-06-05 09:59:33 +02:00
Doug Gregor
c1f7771e84 Merge pull request #81998 from DougGregor/raw-conformance-isolation-cleanup
Make (Raw)ConformanceIsolation requests work on the normal protocol conformance
2025-06-04 20:40:24 -07:00
Doug Gregor
352f39207b Merge pull request #81983 from DougGregor/non-sendable-metatype-suppress
Only emit the non-sendable metatype capture diagnostic under region-based isolation
2025-06-04 17:46:07 -07:00
Doug Gregor
68914528db Make (Raw)ConformanceIsolation requests work on the normal protocol conformance
Reduce the burden on the evaluator's caching mechanism by handling the
unwrapping of a conformance down to its normal protocol conformance
outside of these requests. Thanks, Slava!
2025-06-04 14:26:18 -07:00
Doug Gregor
332151aa69 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:46:02 -07:00
Slava Pestov
c61a4fe333 Merge pull request #81949 from slavapestov/missing-part-of-se-0346
Sema: Implement missing part of SE-0346
2025-06-04 09:24:19 -04:00
Doug Gregor
9957f5240f Merge pull request #81933 from DougGregor/break-isolated-conformance-reference-cycle 2025-06-03 14:54:16 -07:00
Slava Pestov
185a91d955 Sema: Handle nested compositions and parameterized protocols in diagnoseRetroactiveConformances() 2025-06-03 17:28:19 -04:00
Slava Pestov
cd5ecbee16 Sema: Implement missing part of SE-0346
The proposal states that this should work, but this was never
implemented:

    protocol P<A> {
      associatedtype A
    }

    struct S: P<Int> {}

- Fixes https://github.com/swiftlang/swift/issues/62906.
- Fixes rdar://91842338.
2025-06-03 17:28:19 -04:00
Pavel Yaskevich
b189b8a320 Merge pull request #81936 from xedin/improve-optional-wrappedValue-mismatch-diagnostics
[CSSimplify] Fix `matchDeepEqualityTypes` to allow fixing of optionals
2025-06-03 09:19:50 -07:00
Allan Shortlidge
adedf15270 Merge pull request #81922 from tshortli/visionos-availability-remap-regression
AST/Sema: Fix remapping of iOS availability in diagnostics for visionOS
2025-06-03 04:58:31 -07:00
Hamish Knight
d00a3b5764 Merge pull request #81901 from hamishknight/hastype
[CS] Check `hasType` in `isPlaceholderVar`
2025-06-03 11:01:54 +01:00
Pavel Yaskevich
7305275dbd [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.
2025-06-03 00:49:06 -07:00
Pavel Yaskevich
27c28d4d64 [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.
2025-06-03 00:48:59 -07:00
Pavel Yaskevich
65e83a8bb1 [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.
2025-06-02 23:49:52 -07:00
Doug Gregor
7472a0ca38 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:37:58 -07:00
Allan Shortlidge
f4b4dc9889 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 17:55:38 -07:00
Pavel Yaskevich
71a8d8d8a4 [CSDiagnostics] Attempt fix-its for contextual generic argument mismatches 2025-06-02 17:39:56 -07:00
Doug Gregor
bfa991d5b3 Merge pull request #81910 from DougGregor/unsafe-string-interpolation
[Strict memory safety] Adjust "unsafe" location for string interpolations
2025-06-02 17:16:10 -07:00
Michael Gottesman
ec48e41d42 Merge pull request #81851 from gottesmm/pr-400c59de66fe5c91648aedb348d84cb7bd8d09f4
[flow-isolation] Allow for initialization of fields of a Global Actor isolated class in its nonisolated inits
2025-06-02 13:21:21 -07:00
Alexis Laferrière
acdc9514c2 AST: Begin accepting @cdecl on enums (but not @_cdecl) 2025-06-02 13:19:36 -07:00
Alexis Laferrière
96a28336c4 Sema: Add missing range on notes about representability 2025-06-02 13:19:36 -07:00
Doug Gregor
6ba48f2738 [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:36:36 -07:00
Pavel Yaskevich
e1e9f04398 Merge pull request #81863 from xedin/using-for-default-isolation-in-file-context
[AST/Sema] SE-0478:  Implement `using` declaration under an experimental flag
2025-06-02 09:56:29 -07:00
Michael Gottesman
501bad55a8 [flow-isolation] Allow for initialization of fields of a Global Actor isolated class in its nonisolated inits
This just involved loosening some checks in the type checker so we stopped
erroring in the type checker and instead deferred to SIL level checks.

rdar://131136194
2025-06-02 08:37:05 -07:00
Hamish Knight
9cad10ddcd [CS] Check hasType in isPlaceholderVar
Patterns assert that a type is set in `getType`, check `hasType`
before querying.

rdar://146383201
2025-06-02 14:33:10 +01:00
Allan Shortlidge
d5ef256b40 Merge pull request #81751 from tshortli/migratable-member-import-visibility 2025-06-01 08:49:01 -07:00
Hamish Knight
82e6d7bbee Merge pull request #81887 from hamishknight/warning-downgrade
[Sema] Downgrade multi-param default inference diag for methods
2025-06-01 02:58:59 +01:00
Pavel Yaskevich
83ac0f5042 [TypeChecker] Disable use of using in macro extensions 2025-05-31 10:49:50 -07:00
Pavel Yaskevich
21ec5924f7 [AST] NFC: Capitalize UsingSpecifier::nonisolated for consistency 2025-05-31 10:49:50 -07:00
Pavel Yaskevich
595c3b3a62 [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.
2025-05-31 10:49:50 -07:00
Pavel Yaskevich
36b77116bd [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.
2025-05-31 10:49:50 -07:00
Hamish Knight
2790ccce89 [Sema] Downgrade multi-param default inference diag for methods
We recently started enforcing this rule for methods, downgrade to a
warning until the next language mode to avoid source compatibility
breakage.
2025-05-31 17:33:58 +01:00
Slava Pestov
f6f0d75263 Merge pull request #81843 from slavapestov/hamish-fuzzer-fixes
Hamish fuzzer fixes
2025-05-31 12:28:56 -04:00
Hamish Knight
dde37c0f01 Merge pull request #81868 from hamishknight/x-of-hearts
Change InlineArray sugar separator `x` -> `of`
2025-05-31 10:05:26 +01:00
Doug Gregor
5c3faaaf92 Merge pull request #81884 from DougGregor/unsafe-for-loop-uses
[Strict memory safety] Show issues with unsafe constructs in the for..in loop
2025-05-30 23:28:53 -07:00
Doug Gregor
1d903b2e6e Merge pull request #81882 from DougGregor/unsafe-implied-conformance
[Strict memory safety] Improve Fix-Its for implied conformances
2025-05-30 22:18:35 -07:00
Doug Gregor
efacceeacd [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:44:11 -07:00
Pavel Yaskevich
dad81fb4bc Merge pull request #81779 from xedin/diagnostic-fixes
[Diagnostics] A collection of diagnostic fixes/improvements
2025-05-30 18:37:16 -07:00
Doug Gregor
9af5884555 [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 17:41:10 -07:00