Commit Graph

28234 Commits

Author SHA1 Message Date
Doug Gregor
8fb4b1c134 Merge pull request #81466 from DougGregor/objc-enum-unsafe-bit-cast-warning
[Strict memory safety] Squash warning about unsafety in "@objc enum" synthesized code
2025-05-13 01:56:29 -07:00
Doug Gregor
fcd206fb79 [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:30:16 -07:00
Becca Royal-Gordon
602a1168a1 Merge pull request #81421 from beccadax/just-not-my-type 2025-05-12 16:12:40 -07:00
Doug Gregor
a3279afd08 Merge pull request #81450 from DougGregor/isolated-conformances-in-default-value-expressions
[SE-0470] Include isolated conformance checks for default value expressions
2025-05-12 14:14:56 -07:00
Artem Chikin
8ab726c2be Merge pull request #81361 from artemcm/DepScanFewerClangs
[Dependency Scanning][Refactor] Reduce the number of `ClangImporter` instances used by the scanner
2025-05-12 09:57:38 -07:00
Doug Gregor
2dacde1a6d [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:48:30 -07:00
Pavel Yaskevich
3b3d13c6da Merge pull request #81422 from xedin/fix-csapply-to-avoid-marking-autoclosure-closures-as-nonimplicit
[CSApply] Don't attempt to mark autoclosures as non-implicit
2025-05-12 09:47:45 -07:00
Doug Gregor
c16e93f2cd Merge pull request #81420 from DougGregor/se-0470-synthesized-conformances-main-actor
[SE-0470] Fix synthesized conformances with default main actor isolation
2025-05-09 19:12:58 -07:00
Doug Gregor
ff5b82170c Merge pull request #81419 from DougGregor/lookupexpr-effects-cleanup
[Effects] Simplify handling of LookupExpr in effects checking
2025-05-09 19:00:54 -07:00
Pavel Yaskevich
37e2f374aa [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.
2025-05-09 14:43:48 -07:00
Becca Royal-Gordon
7e7f9d024b Fix @_implements type resolution diagnostics
If a type in an `@_implements` attribute failed to resolve, Sema would assume it was because the type existed but wasn’t a protocol, even if there was another reason for the problem (such as the type not existing). Explicitly resolve the TypeRepr again through a path that will produce diagnostics.
2025-05-09 14:41:10 -07:00
Doug Gregor
9d493db479 [SE-0470] Fix synthesized conformances with default main actor isolation
When defaulting to main-actor isolation, types that have synthesized
conformances (e.g., for Equatable, Hashable, Codable) were getting
nonisolated members by default. That would cause compiler errors
because the conformances themselves defaulted to main-actor isolation
when their types were.

Be careful to only mark these members as 'nonisolated' when it makes
sense, and leave them to get the isolation of their enclosing type
when the conformance might have isolation. This ensures that one can
use synthesis of these protocols along with default main-actor mode.

There is a one-off trick here to force the synthesized CodingKeys to
be nonisolated, because the CodingKey protocol requires Sendable.
We'll separately consider whether to generalize this rule.

More of rdar://150691429.
2025-05-09 14:35:56 -07:00
Pavel Yaskevich
a058ffc998 [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
2025-05-09 13:05:57 -07:00
Alejandro Alonso
02d9779ba3 Merge pull request #81184 from Azoy/no-more-is-array-type
[AST] Rename isArrayType and split the InlineArray portion
2025-05-08 20:52:51 -07:00
Alejandro Alonso
d5970d93b8 Check if we're a bound struct 2025-05-08 14:30:01 -07:00
Ben Barham
6667471b3d Merge pull request #81115 from beccadax/abi-let-you-graduate
Finish implementing `@abi` (SE-0476)
2025-05-08 12:52:00 -07:00
Doug Gregor
61ac302fb7 Factor out effects checking of ApplyExpr to not be specific to ApplyExpr 2025-05-08 09:07:19 -07:00
Doug Gregor
ff830dd12d [Effects] Simplify handling of LookupExpr in effects checking
Our logic for doing the "declaration reference" classification was
unnecessarily convoluted, and did "unsafe" classification twice for
properties and subscripts that have other effects (throws/async) on
their getters. Simplify it.
2025-05-08 09:07:15 -07:00
Artem Chikin
8cd193fc08 [Dependency Scanning] Remove 'ClangImporter' instance from dependency scanning worker
Move relevant logic directly into the worker
2025-05-07 16:43:45 -07:00
Nate Cook
e68069f891 [stdlib] Allow a default for optional interpolations (#80547)
This adds an `appendInterpolation` overload to
`DefaultStringInterpolation` that includes a parameter for providing a
default string when the value to interpolate is `nil`. This allows this
kind of usage:

```swift
let age: Int? = nil
print("Your age is \(age, default: "timeless")")
// Prints "Your age is timeless"
```

The change includes an additional fixit when optional values are
interpolated, with a suggestion to use this `default:` parameter.
2025-05-07 12:47:02 -05:00
Rintaro Ishizaki
62b7a6f380 Merge pull request #81346 from rintaro/macros-definition-typecheck-ifconfig
[Macros] Don't include attr range when checking macro definition
2025-05-07 09:29:34 -07:00
Pavel Yaskevich
f298bdeda5 Merge pull request #81345 from xedin/rdar-150777469
[CSFix] SE-0470: Warn about missing `@Sendable` for unapplied static …
2025-05-07 09:10:48 -07:00
Pavel Yaskevich
a57310b61d [CSFix] SE-0470: Warn about missing @Sendable for unapplied static member references until future Swift version
Static member referenced were marked as `@Sendable` by `InferSendableFromCaptures`
because metatypes used to be always Sendable which is no longer the case, so in
order to maintain the source compatibility we need to downgrade missing `@Sendable`
to a warning for unapplied static member references.

This affects primarily operators at the moment because other static members
form a curry thunk with a call inside and would be diagnosed as a capture.

Resolves: rdar://150777469
2025-05-07 00:17:28 -07:00
Michael Gottesman
c66d6c70c7 Merge pull request #81338 from gottesmm/pr-e2235199764eea9659e08932699c74d60cf387b7
[concurrency] Ensure that we treat closures that are nonisolated(nonsending) via their ActorIsolation as nonisolated(nonsending).
2025-05-06 18:47:58 -07:00
Rintaro Ishizaki
8519e71602 [Macros] Don't include attr range when checking macro definition
For macro definition checking, we use the range of the `macro`
declaration and re-parse it with `SwiftParser`. Previously it uses the
range including the attributes, but that can result invalid code because
the attribute can be in a `#if ... #endif` region.

Since we don't use attributes for checking the definition, just use the
range without the attributes instead.

rdar://150805795
2025-05-06 16:55:42 -07:00
Doug Gregor
aee6a52bcf Merge pull request #81296 from DougGregor/infer-nonisolated-conformances-from-witnesses
[SE-0470] Prohibit inference of isolated conformances with nonisolated witnesses
2025-05-06 16:02:36 -07:00
Michael Gottesman
ced96aa5cd [concurrency] Ensure that we treat closures that are nonisolated(nonsending) via their ActorIsolation as nonisolated(nonsending).
Some notes:

1. In most cases, I think we were getting lucky with this by just inferring the
closure's isolation from its decl context. In the specific case that we were
looking at here, this was not true since we are returning from an @concurrent
async function a nonisolated(nonsending) method that closes over self. This
occurs since even when NonisolatedNonsendingByDefault we want to start importing
objc async functions as nonisolated(nonsending).

2. I also discovered that in the ActorIsolationChecker we were not visiting the
inner autoclosure meaning that we never set the ActorIsolation field on the
closure. After some discussion with @xedin about potentially visiting the
function in the ActorIsolationChecker, we came to the conclusion that this was
likely to result in source stability changes. So we put in a targeted fix just
for autoclosures in this specific case by setting their actor isolation in the
type checker.

3. Beyond adding tests to objc_async_from_swift to make sure that when
NonisolatedNonsendingByDefault is disabled we do the right thing, I noticed that
we did not have any tests that actually tested the behavior around
objc_async_from_swift when NonisolatedNonsendingByDefault is enabled. So I added
the relevant test lines so we can be sure that we get correct behavior in such a
case.

rdar://150209093
2025-05-06 14:15:23 -07:00
Michael Gottesman
b34e2d72fb Merge pull request #81306 from gottesmm/pr-b6ba1a771d90007a5ee6da3e4dc657bfef32b320
[swift-settings] Now that we aren't using it immediately, remove it from tree.
2025-05-06 08:21:23 -07:00
Doug Gregor
d24aa0952d Disable conformance isolation inference for @preconcurrency conformances 2025-05-05 15:15:11 -07:00
Becca Royal-Gordon
0c508a8b78 Ban @abi on multi-var PBDs
Per a comment in the review thread that the comma in a multi-variable pattern binding makes it look like the `@abi` attribute has several arguments.
2025-05-05 13:50:17 -07:00
Michael Gottesman
9d59dbed17 [swift-settings] Now that we aren't using it immediately, remove it from tree.
We can always get it back from the git history.

rdar://150695113
2025-05-05 13:39:03 -07:00
Doug Gregor
1b5c9368a0 Make ConformanceIsolationRequest cache per-ProtocolConformance
This request was looking through to the root conformance, which could
mess with the caching bits. Sink the "is nonisolated conformance" bit
down into ProtocolConformance, and have the request for a non-root
conformance be defined in terms of the request for the root
conformance.
2025-05-05 11:08:55 -07:00
Doug Gregor
2e34549236 [SE-0470] Prohibit inference of isolated conformances with nonisolated witnesses
If all of the witnesses to a conformance are nonisolated, then infer that
conformance as nonisolated rather than global-actor-isolated. This is
only relevant when InferIsolatedConformances is enabled, and prevents
that inference to help maintain source compatibility.
2025-05-05 11:08:52 -07:00
Ludwig Hollmann
39aa950660 Update file header comments for headers in lib. 2025-05-04 22:26:26 +02:00
Pavel Yaskevich
ff790c6d01 Merge pull request #81176 from xedin/pre-enum-extensibility
[AST/Sema] Add `@preEnumExtensibility` attribute to downgrade warning…
2025-05-02 22:04:04 -07:00
Doug Gregor
c249357f16 Merge pull request #81249 from DougGregor/observation-nonisolated-conformances
[Observation] Create nonisolated conformances to Observable
2025-05-02 12:56:27 -07:00
Holly Borla
20e4413193 Merge pull request #80812 from jamieQ/invalid-isolated-any-conversion
[Sema]: ban @isolated(any) conversions to synchronous function types
2025-05-02 12:21:20 -07:00
Pavel Yaskevich
498430afaf [AST/Sema] Add @preEnumExtensibility attribute to downgrade warnings for extensible enums
Just like `@preconcurrency` for concurrency, this attribute is going
to allow exhaustiveness error downgrades for enums that were retroactively
marked as `@extensible`.
2025-05-02 09:07:22 -07:00
Doug Gregor
fed18d58dc [Observation] Create nonisolated conformances to Observable
This is needed to make default-main-actor mode work well with
Observable. Fixes rdar://150419628.
2025-05-01 22:01:41 -07:00
Pavel Yaskevich
11cf263347 Merge pull request #81231 from xedin/rdar-150397825
[Concurrency] Account for explicit `@concurrent` on closures
2025-05-01 09:03:23 -07:00
Pavel Yaskevich
31ff9b4335 Merge pull request #81219 from xedin/nonisolated-nonsending-inference-for-storage
[Concurrency] Allow `nonisolated(nonsending)` inference on properties…
2025-05-01 09:03:06 -07:00
Jamie
629e208970 [Sema]: ban @isolated(any) conversions to synchronous function types
per SE-0431, function conversions from an @isolated(any) function to a synchronous,
non-@isolated(any) function type should not be allowed. this adds a warning during
type checking to enforce this, which will be an error in a future major
language mode.
2025-05-01 07:19:03 -05:00
John Hui
c2f904caa4 Merge pull request #81188 from j-hui/fix-recursive-inheritance
[cxx-interop] Avoid unchecked recursion when importing C++ classes with circular inheritance
2025-05-01 02:00:46 -07:00
Pavel Yaskevich
ef65f26457 [Concurrency] Account for explicit @concurrent on closures
If closure is stated as `@concurrent` is has to be treated as
nonisolated.

Resolves: rdar://150397825
2025-04-30 20:25:32 -07:00
Slava Pestov
f5087c4944 Merge pull request #81202 from slavapestov/lookup-conformance-fn
AST: Change signature of LookupConformanceFn
2025-04-30 22:00:38 -04:00
Pavel Yaskevich
8a9bbd5114 [Concurrency] Allow nonisolated(nonsending) inference on properties with async getters
When `NonisolatedNonsendingByDefault` is enabled it should infer
`nonisolated(nonsending)` for both async functions and storage as
specified by the proposal.
2025-04-30 15:19:56 -07:00
John Hui
1f2107f357 [cxx-interop] Avoid unchecked recursion when importing C++ classes with circular inheritance
It is possible for a C++ class template to inherit from a specialization
of itself. Normally, these are imported to Swift as separate (unrelated)
types, but when symbolic import is enabled, unspecialized templates are
imported in place of their specializations, leading to circularly
inheriting classes to seemingly inherit from themselves.

This patch adds a check to guard against the most common case of
circular inheritance, when a class template directly inherits from
itself. This pattern appears in a recent version of libc++,
necessitating this patch. However, the solution here is imperfect as it
does not handle more complex/contrived circular inheritance patterns.

This patch also adds a test case exercising this pattern. The
-index-store-path flag causes swift-frontend to index the C++ module
with symbolic import enabled, without the fix in this patch, that test
triggers an assertion failure due to the circular reference (and can
infinitely recurse in the StorageVisitor when assertions are disabled).

rdar://148026461
2025-04-30 13:33:33 -07:00
Michael Gottesman
6e33329da5 Merge pull request #81193 from gottesmm/pr-5722431d23d74cb6adc74e1305c2b9e8b8d5159d
[concurrency] Fix an off by one error in generic handling in local capture checking code.
2025-04-30 13:05:11 -07:00
Slava Pestov
6ffa8fd489 AST: Change signature of LookupConformanceFn
Instead of passing in the substituted type, we pass in the
InFlightSubstitution. This allows the substituted type to be
recovered if needed, but we can now skip computing it for
the common case of LookUpConformanceInSubstitutionMap.
2025-04-30 13:42:20 -04:00
Slava Pestov
2746a83109 Merge pull request #81181 from slavapestov/fix-issue-79763
AST: Fix existential erasure of long member types
2025-04-30 13:33:56 -04:00