Commit Graph

28404 Commits

Author SHA1 Message Date
Anthony Latsis
4313f8f262 Merge pull request #81538 from AnthonyLatsis/pinus-sibirica
AST, Sema: Fix 2 `NonisolatedNonsendingByDefault` bugs
2025-05-16 09:42:52 +01:00
Pavel Yaskevich
515d203999 Merge pull request #81543 from xedin/inheritActorContextAlways+isolatedAny
[Concurrency] Fix `@_inheritActorContext(always)` to use `forActorIns…
2025-05-16 00:20:38 -07:00
Pavel Yaskevich
cda9866b26 [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
2025-05-15 17:17:02 -07:00
Pavel Yaskevich
91047446ad [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)`.
2025-05-15 14:31:59 -07:00
Hamish Knight
abf0808173 [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-15 21:23:40 +01:00
Anthony Latsis
bee2b6778e 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.
2025-05-15 20:18:28 +01:00
Pavel Yaskevich
917524de94 Merge pull request #81496 from xedin/inheritActorContext-alwayse
[AST/Sema/SIL] Implement `@_inheritActorContext(always)`
2025-05-15 08:17:30 -07:00
Mykola Pokhylets
3e0de8672a Removed the feature and made changes unconditional 2025-05-15 10:52:09 +02:00
Mykola Pokhylets
81da20f63c Enable warnings about never mutated weak var. 2025-05-15 10:26:27 +02:00
Mykola Pokhylets
49b706a811 Added experimental feature to allow weak let and immutable weak captures 2025-05-15 10:26:26 +02:00
Pavel Yaskevich
a8c538937a Merge pull request #81418 from xedin/rdar-130168104
[Concurrency] Diagnose loss of global actor isolation in async functi…
2025-05-15 01:00:43 -07:00
Pavel Yaskevich
17b8f7ef12 [Sema] Validate that @_inheritActorContext is used only on @Sendable/sending and async/@isolated(any) parameters 2025-05-14 20:08:00 -07:00
Pavel Yaskevich
a4f6d710cf [Sema] Start propagating @_inheritActorContext(always) attribute to closures 2025-05-14 20:08:00 -07:00
Pavel Yaskevich
04d46760bb [AST] Extend @_inheritActorContext attribute to support optional always modifier
By default (currently) the closure passed to a parameter with `@_inheritActorContext`
would only inherit isolation from `nonisolated`, global actor isolated or actor
context when "self" is captured by the closure. `always` changes this behavior to
always inherit actor isolation from context regardless of whether it's captured
or not.
2025-05-14 20:07:57 -07:00
Alexis Laferrière
ef84f0e1aa Sema: Update more diagnostics for @cdecl vs @objc 2025-05-14 13:13:03 -07:00
Alexis Laferrière
bb99891648 Sema: Use ForeignLanguage directly in diagnostic definitions 2025-05-14 12:54:33 -07:00
Becca Royal-Gordon
d48ff3545d [NFC] Give withoutArgumentLabels() a context arg
It will soon need to allocate sometimes.
2025-05-14 11:16:02 -07:00
Hamish Knight
110f11493a [IDE] Avoid uses of isBeforeInBuffer in TypeCheckASTNodeAtLocRequest
Use the higher level APIs on SourceManager that handle locations in
parent vs child buffers. This then allows us to fix `walkToDeclPre`
such that we don't set the found DeclContext unless the location is
actually within that decl (here the location may well be in a
separate buffer as we may have a replaced function body).
2025-05-14 11:15:42 +01:00
Steven Wu
7025bf816b Merge pull request #81264 from cachemeifyoucan/eng/PR-148752988
[Caching] Reduce the number of cas ID passed on frontend commandline
2025-05-13 16:15:29 -07:00
Steven Wu
201e4faea7 [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
2025-05-13 09:20:13 -07:00
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