Commit Graph

28234 Commits

Author SHA1 Message Date
Konrad `ktoso` Malawski
8b4740f0cc Merge pull request #81797 from ktoso/wip-handle-public-import-distributed-awareness
[Distributed] account Distributed module use from DA declarations
2025-05-29 08:04:24 +09:00
Arnold Schwaighofer
7ac551636b Merge pull request #81714 from aschwaighofer/se0460
SE-0460: Introduce @specialized attribute
2025-05-28 12:03:48 -07:00
eeckstein
89bdb311ab Merge pull request #81780 from eeckstein/optimize-enum-comparison
Optimize enum comparisons
2025-05-28 07:01:29 +02:00
Konrad 'ktoso' Malawski
3b94f009d6 [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:54:07 +09:00
Erik Eckstein
c2866b397b Sema: add a @_semantics attribute to synthesized enum comparison functions
So that optimizations can identify and deal with them.
2025-05-27 12:11:03 +02:00
Allan Shortlidge
dbb1d783d9 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:56:47 -07:00
Daniil Kovalev
1e403ecf5c [AutoDiff] Support custom derivatives for @_alwaysEmitIntoClient functions (#78908)
Consider an `@_alwaysEmitIntoClient` function and a custom derivative
defined
for it. Previously, such a combination resulted different errors under
different
circumstances.

Sometimes, there were linker errors due to missing derivative function
symbol -
these occurred when we tried to find the derivative in a module, while
it
should have been emitted into client's code (and it did not happen).

Sometimes, there were SIL verification failures like this:

```
SIL verification failed: internal/private function cannot be serialized or serializable: !F->isAnySerialized() || embedded
```

Linkage and serialization options for the derivative were not handled
properly,
and, instead of PublicNonABI linkage, we had Private one which is
unsupported
for serialization - but we need to serialize `@_alwaysEmitIntoClient`
functions
so the client's code is able to see them.

This patch resolves the issue and adds proper handling of custom
derivatives
of `@_alwaysEmitIntoClient` functions. Note that either both the
function and
its custom derivative or none of them should have
`@_alwaysEmitIntoClient`
attribute, mismatch in this attribute is not supported.

The following cases are handled (assume that in each case client's code
uses
the derivative).

1. Both the function and its derivative are defined in a single file in
   one module.

2. Both the function and its derivative are defined in different files
which
   are compiled to a single module.

3. The function is defined in one module, its derivative is defined in
another
   module.

4. The function and the derivative are defined as members of a protocol
extension in two separate modules - one for the function and one for the
   derivative. A struct conforming the protocol is defined in the third
   module.

5. The function and the derivative are defined as members of a struct
extension in two separate modules - one for the function and one for the
   derivative.

The changes allow to define derivatives for methods of `SIMD`.

Fixes #54445
<!--
If this pull request is targeting a release branch, please fill out the
following form:

https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1

Otherwise, replace this comment with a description of your changes and
rationale. Provide links to external references/discussions if
appropriate.
If this pull request resolves any GitHub issues, link them like so:

  Resolves <link to issue>, resolves <link to another issue>.

For more information about linking a pull request to an issue, see:

https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->

<!--
Before merging this pull request, you must run the Swift continuous
integration tests.
For information about triggering CI builds via @swift-ci, see:

https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci

Thank you for your contribution to Swift!
-->
2025-05-25 09:47:15 -04:00
Slava Pestov
52f54534f3 Merge pull request #76705 from slavapestov/existential-parameterized-composition
Allow existential parameterized compositions: `any P<A> & Q`
2025-05-23 21:26:50 -04:00
Arnold Schwaighofer
13ff5abdb8 Introduce @specialized attribute
Implements SE-0460 -- the non-underscored version of @specialized.

It allows to specify "internal" (not abi affecting) specializations.

rdar://150033316
2025-05-23 13:12:47 -07:00
Slava Pestov
1fa9afc460 Sema: Allow parameterized existential compositions 2025-05-23 14:14:23 -04:00
Pavel Yaskevich
43c3e4a539 Merge pull request #81719 from xedin/rdar-151720646
[TypeChecker] Improve diagnostics for access to actor-isolated values…
2025-05-23 09:58:16 -07:00
Doug Gregor
43f6feaf19 Merge pull request #81738 from DougGregor/no-unchecked
Remove the note that suggests using `@unchecked`
2025-05-23 13:46:22 +01:00
Doug Gregor
a922e8e356 Remove the note that suggests using @unchecked
`@unchecked Sendble` is dangerous, and almost always the wrong thing to
use. Don't have the compiler suggest it.
2025-05-23 09:12:51 +01:00
Pavel Yaskevich
9e562881fe [TypeChecker] Improve diagnostics for access to actor-isolated values outside of the actor
Replaces generic `expression is 'async' but is not marked with 'await`
diagnostic with a tailed one for cases where there is an access to an
actor-isolated value outside of its actor without `await` keyword.

This makes the diagnostics for async and sync contexts consistent
and actually identifies a problem instead of simply pointing out
the solution.

Resolves: rdar://151720646
2025-05-23 00:20:18 -07:00
Pavel Yaskevich
55b29fea4b Merge pull request #81690 from xedin/rdar-151797372
[CSApply] Don't inject global actor into closure type if it's marked …
2025-05-22 09:33:36 -07:00
Doug Gregor
ca0e984c94 Merge pull request #81703 from DougGregor/more-migratable-features
Make `InferIsolatedConformances` and `StrictMemorySafety` migratable features
2025-05-22 16:48:30 +01:00
Slava Pestov
278248e6c6 Merge pull request #81576 from slavapestov/fix-rdar145184871
Sema: Don't diagnose implied conformance of imported type to Sendable
2025-05-22 08:01:40 -04:00
Doug Gregor
abad2fae0f 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.
2025-05-22 11:07:13 +01:00
Doug Gregor
a32782bcbc 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.
2025-05-22 11:07:13 +01:00
Pavel Yaskevich
efc6efc4ed [CSApply] Don't inject global actor into closure type if it's marked as @concurrent
When the attribute is specified explicitly passing a `@concurrent`
closure to a global actor-isolated parameter or contextual type
should result in a conversion and closure itself should be nonisolated.

Resolves: rdar://151797372
2025-05-21 15:22:03 -07:00
Slava Pestov
8b8aafb798 Sema: Don't complain about implied Sendable conformance of imported type being retroactive
- Fixes rdar://145184871.
2025-05-21 18:04:43 -04:00
Slava Pestov
a232a2d1e3 Sema: Fix diagnoseRetroactiveConformances() to handle protocol compositions 2025-05-21 17:25:56 -04:00
Artem Chikin
24f2975db6 Merge pull request #81510 from artemcm/ConstSyntacticVerify
[Compile Time Values] Add syntactic verification of valid expressions in `@const` contexts
2025-05-21 13:22:05 -07:00
Doug Gregor
689491c933 Merge pull request #81675 from DougGregor/unsafe-pattern-match
[Strict memory safety] Lift "unsafe" in pattern match expressions
2025-05-21 18:18:26 +01:00
Doug Gregor
d5476aeda0 Improve diagnostic for unsafe call arguments
Use the argument type rather than the (potentially generic) parameter type.
2025-05-21 13:46:17 +01:00
Doug Gregor
d4dc36d2f3 [Strict memory safety] Lift "unsafe" in pattern match expressions
When an "unsafe" expression is used as the case expression, lift it up
so it also covers the synthesized matching expression (`=~`). This
eliminates some unsuppressible strict memory safety warnings.

Fixes rdar://151731850.
2025-05-21 13:46:17 +01:00
Anthony Latsis
d27a021064 Merge pull request #81633 from AnthonyLatsis/acer-campestri-2
Sema: Fix an issue with `NonisolatedNonsendingByDefault` migration fo…
2025-05-20 21:28:52 +01:00
Artem Chikin
d8176a7e89 [Compile Time Values] Add syntactic verification of valid expressions in '@const' contexts
Syntactically verify that initializer expressions of '@const' variables and argument expressions to '@const' parameters consist strictly of syntactically-verifiable set of basic values and operations
2025-05-20 09:38:36 -07:00
Pavel Yaskevich
37e1fc8794 Merge pull request #81627 from xedin/rdar-151029517
[Concurrency] Infer `@preconcurrency @MainActor` in default main acto…
2025-05-20 09:05:12 -07:00
Anthony Latsis
2d7e040d4d Sema: Fix an issue with NonisolatedNonsendingByDefault migration for closures
See the inline comments for more details. Depending on the closure's
type signature, sometimes adding the attribute will break code. Fix this
by also adding inferred effects to the signature in these cases.
2025-05-20 08:18:33 +01:00
Pavel Yaskevich
6561476059 [Concurrency] Infer @preconcurrency @MainActor in default main actor mode for language modes < 6
`@MainActor` errors are hard errors, even in minimal concurrency checking in Swift 5 mode.
When users set the default isolation to main actor, we should infer `@preconcurrency @MainActor`
in language modes < 6 to get the right diagnostic staging behavior.

Resolves: rdar://151029517
2025-05-19 15:25:06 -07:00
Hamish Knight
edca7c85ad Adopt ABORT throughout the compiler
Convert a bunch of places where we're dumping to stderr and calling
`abort` over to using `ABORT` such that the message gets printed to
the pretty stack trace. This ensures it gets picked up by
CrashReporter.
2025-05-19 20:55:01 +01:00
Anthony Latsis
1823d44de7 Merge pull request #81570 from AnthonyLatsis/acer-campestri
Sema: Fix UB in `NonisolatedNonsendingByDefault` migration diagnosis
2025-05-18 01:34:52 +01:00
Hamish Knight
48f6f24f2b Merge pull request #81540 from hamishknight/last-straw
[Sema] Continue type-checking `for` body when preamble fails
2025-05-16 23:57:00 +01:00
Anthony Latsis
f4e49d5a0a Sema: Fix UB in NonisolatedNonsendingByDefault migration diagnosis
The diagnostic can outlive the locally constructed attribute, which was
passed by pointer, if there is an active `DiagnosticTransaction`.
2025-05-16 21:13:08 +01:00
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
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
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