Commit Graph

28404 Commits

Author SHA1 Message Date
Pavel Yaskevich
2d1f9d3f18 [CSSimplify] Move inout failures handing to LValueConversion block
This is cleanup that allows us to avoid a fallthrough to `ApplyArgToParam`
handling for `inout` failures.
2025-05-30 09:52:57 -07:00
Pavel Yaskevich
ded6158cc3 [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
2025-05-30 09:52:57 -07:00
Pavel Yaskevich
10186d664b [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
2025-05-30 09:52:52 -07:00
Hamish Knight
5d1f219acb Change InlineArray sugar separator x -> of 2025-05-30 13:50:22 +01:00
Pavel Yaskevich
aabfebec03 [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.
2025-05-30 00:39:06 -07:00
Holly Borla
c283ce12d5 [Concurrency] Remove some dead code from mayExecuteConcurrentlyWith.
This code is no longer used given that region isolation is always enabled
along with strict concurrency checking.
2025-05-29 19:17:52 -07:00
Pavel Yaskevich
86390ab91f [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
2025-05-29 13:49:15 -07:00
Alexis Laferrière
7d6447be20 Merge pull request #81519 from xymus/cdecl-diags
Sema: Update more diagnostics for `@cdecl` and representability in the C language
2025-05-29 13:37:29 -07:00
Philipp Gabriel
0d9be9750f [Sema] Type inference from default expression doesn’t compile in free function (#79989)
This is an attempt to solving
https://github.com/swiftlang/swift/issues/72199.
As I've already lined out in the issue, this seems to be a two-fold
problem.

The first one was a rather easy fix, as I've seen similar approaches in
different parts of the codebase. It is pretty much just un-currying the
generic function.

The second problem was, that `DependentMemberType`s were counted towards
the generic-parameter-should-only-be-mentioned-once-limit even though
you cannot infer the generic type from the dependent member type.
2025-05-29 20:21:35 +01:00
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
Pavel Yaskevich
d83ec7b3a5 [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
2025-05-28 14:33:18 -07:00
Pavel Yaskevich
b3e9cf3424 [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
2025-05-28 14:33:18 -07:00
Pavel Yaskevich
ef2fa4a1b6 [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
2025-05-28 14:33:17 -07:00
Mykola Pokhylets
847a7d247b Update comments 2025-05-28 21:25:37 +02: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
Mykola Pokhylets
de3a87c0ab Merge branch 'main' into mpokhylets/weak-let 2025-05-23 17:26:49 +02: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
Mykola Pokhylets
b138c2cc35 Updated logic for diagnosting implicit self capture to handle immutable weak capture (minor source-breaking change) 2025-05-19 16:31:01 +02: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