Commit Graph

2898 Commits

Author SHA1 Message Date
Doug Gregor
e2ee46d724 Merge pull request #81743 from DougGregor/no-unchecked-6.2 2025-05-24 03:58:49 +01:00
Slava Pestov
58a9435485 Sema: Don't complain about implied Sendable conformance of imported type being retroactive
- Fixes rdar://145184871.
2025-05-23 14:34:33 -04:00
Michael Gottesman
b8cf5aeb34 Updates for 6.2.
These were changes that were not updated in the previous commit due to merge conflict
resolution or that the test itself was not in 6.2.
2025-05-23 10:33:58 -07:00
Michael Gottesman
0d519a1acb [sema] Change non-sendable -> non-Sendable in diagnostics.
This matches send non sendable but importantly also makes it clear that we are
talking about something that doesn't conform to the Sendable protocol which is
capitalized.

rdar://151802975
(cherry picked from commit 3ed4059a60)
2025-05-23 10:31:05 -07:00
Pavel Yaskevich
7077ef5ccf Merge pull request #81737 from xedin/rdar-151720646-6.2
[6.2][TypeChecker] Improve diagnostics for access to actor-isolated values…
2025-05-23 10:12:46 -07:00
Pavel Yaskevich
d0d0afb131 Merge pull request #81718 from xedin/rdar-151797372-6.2
[6.2][CSApply] Don't inject global actor into closure type if it's marked …
2025-05-23 09:09:16 -07:00
Doug Gregor
3eb28dcc81 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.

(cherry picked from commit a922e8e356)
2025-05-23 16:08:59 +01:00
Pavel Yaskevich
dd95c60c70 [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
(cherry picked from commit 7a6ba8e8c58c58b3438f31fec06102d02bae81a5)
2025-05-22 23:52:02 -07:00
Pavel Yaskevich
5997a4dec4 [stdlib] Adopt @_inheritActorContext(always) on Task.immediate
This change aligns implementation with the current SE-0472 proposal.

(cherry picked from commit c3c1b4fca0)
(cherry picked from commit 8c05636e28)
(cherry picked from commit 0598b8c9f4)
2025-05-22 11:32:37 -07:00
Pavel Yaskevich
e12201769d [AST/Sema/SIL] Implement @_inheritActorContext(always)
- Extend `@_inheritActorContext` attribute to support optional `always` modifier.
  The new modifier will make closure context isolated even if the parameter is not
  captured by the closure.
- Implementation `@_inheritActorContext` attribute validation - it could only be
  used on parameter that have `@Sendable` or `sending` and `@isolated(any)` or
  `async` function type (downgraded to a warning until future major Swift mode
  to avoid source compatibility issues).
- Add a new language feature that guards use of `@_inheritActorContext(always)` in swift interface files
- Update `getLoweredLocalCaptures` to add an entry for isolation parameter implicitly captured by `@_inheritActorContext(always)`
- Update serialization code to store `always` modifier

(cherry picked from commit 04d46760bb)
(cherry picked from commit c050e8f75a)
(cherry picked from commit c0aca5384b)
(cherry picked from commit a4f6d710cf)
(cherry picked from commit 6c911f5d42)
(cherry picked from commit 17b8f7ef12)
2025-05-22 11:32:35 -07:00
Pavel Yaskevich
b79e922a50 [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
(cherry picked from commit efc6efc4ed)
2025-05-22 10:15:39 -07:00
Michael Gottesman
63a436ec04 Merge pull request #81615 from gottesmm/release/6.2-rdar151394209
[6.2] Fix a few issues around nonisolated(nonsending) and  protocol witness thunks/vtable thunks
2025-05-22 00:04:01 -07:00
Anthony Latsis
55b4193646 InFlightDiagnostic: Minor improvement to fixItAddAttribute
Do not follow `in` keyword with a space unless the first token inside
the body begins with the next char after `{`.

(cherry picked from commit eedc774fca)
2025-05-21 21:24:37 +01:00
Anthony Latsis
c1ad869e63 Merge pull request #81655 from AnthonyLatsis/acer-campestri-2-6.2
[6.2] Sema: Fix an issue with `NonisolatedNonsendingByDefault` migration fo…
2025-05-21 20:36:58 +01:00
Anthony Latsis
ee4d103500 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.

(cherry picked from commit 2d7e040d4d)
2025-05-21 00:10:00 +01:00
Pavel Yaskevich
ba23f1baa9 [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
(cherry picked from commit 6561476059)
2025-05-20 09:06:31 -07:00
Pavel Yaskevich
b923bf401f Merge pull request #81577 from xedin/rdar-130168104-6.2
[6.2][Concurrency] Diagnose loss of global actor isolation in async functi…
2025-05-19 13:53:50 -07:00
Michael Gottesman
f0023918e3 [silgen] Teach SILGen how to handle nonisolated(nonsending) thunking for vtables
This ensures that when we generate the vtable thunk for a
nonisolated(nonsending) override (or vis-a-versa), we get the ABI correct. I
also added tests for all of the relevant cases for vtables that we check for
protocols.

rdar://151394209
(cherry picked from commit ef23f97071)
2025-05-19 10:33:57 -07:00
Michael Gottesman
27cf33676f [silgen] Place the correct isolation on protocol witness thunks.
We were using the isolation from the witness not from the requirement which we
are supposed to do. The witness thunk thunks the isolation from the requirement
to the witness so from an ABI perspective it should have the interface implied
by the requirement's isolation since that is what callers of the witness method
will expect.

rdar://151394209
(cherry picked from commit 39a013f807)
2025-05-19 10:33:57 -07:00
Pavel Yaskevich
1336dd4cb5 [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
(cherry picked from commit a058ffc998)
2025-05-16 15:21:03 -07:00
Anthony Latsis
e5a10a37d0 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`.

(cherry picked from commit f4e49d5a0a)
2025-05-16 21:25:08 +01:00
Anthony Latsis
58893716f9 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.

(cherry picked from commit bee2b6778e)
2025-05-16 21:24:54 +01:00
Anthony Latsis
9ccb828c37 DiagnosticEngine: Fix attribute insertion location for closures with capture lists
(cherry picked from commit d90c7cb57a)
2025-05-16 21:24:42 +01:00
Slava Pestov
21f3bc1032 Merge pull request #81523 from slavapestov/fix-pack-task-dealloc-6.2
[6.2] IRGen: Fix out-of-order task_dealloc with parameter pack metadata
2025-05-15 20:05:46 -04:00
Pavel Yaskevich
ee3aca2ef3 Merge pull request #81518 from xedin/rdar-148124973-6.2
[6.2][Frontend] Add a way to print features supported by the compiler
2025-05-15 09:46:15 -07:00
Slava Pestov
bf8d836074 IRGen: Fix out-of-order task_dealloc with parameter pack metadata
We deallocate an instruction's packs at points where no further
control flow path uses the value. In the case of an alloc_stack,
this will be right after the dealloc_stack. Thus, if alloc_stack
allocates some packs to build type metadata for a tuple type
that contains a pack, and then proceeds to allocate a value
large enough to hold the tuple, we will free the second allocation
first, before we free the pack, as expected.

However, after stack allocating the value, alloc_stack does
some further work to emit debug info. This could result in
emission of additional metadata packs.

Split up the debug info emission into two parts; the first we do
before we perform the stack allocation, the rest we do after.

- Fixes https://github.com/swiftlang/swift/issues/67702.
- Fixes rdar://problem/141363236.
2025-05-15 12:24:14 -04:00
Pavel Yaskevich
de6ef08d71 [Feature] Switch migration postfix from :adoption to :migrate
(cherry picked from commit 1ba077d922)
2025-05-14 20:28:46 -07:00
Mykola Pokhylets
700800ca26 Fixed no copying IsIsolated flag when cloning subscript params 2025-05-14 10:11:42 +02:00
Pavel Yaskevich
2bf00077e4 [stdlib] SE-0472: Rename Task and*TaskGroup APIs to match the proposal
`Task.startSynchronously` -> `Task.immediate`
`*TaskGroup.startTaskSynchronously{UnlessCancelled}` -> `*TaskGroup.addImmediateTask{UnlessCancelled}`

(cherry picked from commit 001eab867d)
2025-05-13 20:11:28 -07:00
Konrad `ktoso` Malawski
413373480e Disable startSynchronously while we rework semantics
Reworking semantics of this API so disabling the flaky test, it'll have different sematntics and then the test will be adjusted

(cherry picked from commit a3762d4e19)
2025-05-13 20:11:12 -07:00
Konrad 'ktoso' Malawski
910bc1a1a3 [Concurrency] Improve in order synchronous enqueue of startSynchronously
Previously there was still a sneaky hop which caused ordering issues.
This introduced a specific test startSynchronously_order which checks
that the task enqueues indeed are "immediate" and cleans up how we
handle this.

This also prepares for the being discussed in SE review direction of
this API that it SHOULD be ALLOWED to actually hop and NOT be
synchronous at all IF the isolation is specified on the closure and is
DIFFERENT than the callers dynamic isolation.

This effectively implements "synchronously run right now if dynamically
on the exact isolation as requested by the closure; otherwise enqueue
the task as usual".

resolves rdar://149284186
cc @drexin

(cherry picked from commit a24a28c217)
2025-05-13 20:10:35 -07:00
Alastair Houghton
02c160cdac Merge pull request #81335 from al45tair/eng/PR-148899609-6.2
[Concurrency] Don't pass negative times to the Dispatch code.
2025-05-13 11:29:35 +01:00
Pavel Yaskevich
336be3c632 Merge pull request #81453 from xedin/fix-csapply-to-avoid-marking-autoclosure-closures-as-nonimplicit-6.2
[6.2][CSApply] Don't attempt to mark autoclosures as non-implicit
2025-05-13 00:47:42 -07:00
Pavel Yaskevich
b8542ba649 Merge pull request #81456 from xedin/rename-notes-file-for-noinisolated-nonsending-feature-6.2
[6.2][Diagnostics] Rename the note file to match the `NonisolatedNonsendingByDefault` feature group declaration
2025-05-13 00:47:21 -07:00
Pavel Yaskevich
6c54fe142a [Diagnostics] Replace last references to AsyncCallerExecution with NonisolatedNonsendingByDefault
(cherry picked from commit 0bcbde4940)
2025-05-12 13:37:58 -07:00
Pavel Yaskevich
b967cf4f53 [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.

(cherry picked from commit 37e2f374aa)
2025-05-12 10:40:37 -07:00
Doug Gregor
760d0a35df [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:51:29 -07:00
Doug Gregor
009f868922 Merge pull request #81344 from DougGregor/infer-nonisolated-conformances-from-witnesses-6.2 2025-05-10 08:27:04 -07:00
Doug Gregor
2ea1421aba [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:40:21 -07:00
Pavel Yaskevich
d517a26f25 [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
(cherry picked from commit a57310b61d)
2025-05-07 09:13:08 -07:00
Doug Gregor
a3a17d0405 Disable conformance isolation inference for @preconcurrency conformances 2025-05-06 16:07:29 -07:00
Doug Gregor
2ec6fbec4d [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-06 16:07:22 -07:00
Michael Gottesman
e04e15f125 [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
(cherry picked from commit 9d59dbed17)

Conflicts:
	include/swift/AST/DiagnosticsSema.def
	include/swift/Basic/Features.def
	test/abi/macOS/arm64/concurrency.swift
	test/abi/macOS/x86_64/concurrency.swift
2025-05-06 14:12:23 -07:00
Meghana Gupta
5d3a95af3a Merge pull request #81321 from meg-gupta/disabletest
Disable failing test - reflect_task.swift
2025-05-06 11:42:39 -07:00
Alastair Houghton
c9113ed123 [Concurrency][Tests] Add a test of waiting until a time before the epoch.
Add a test to check that attempting to `Task.sleep(until:)` passing a
time before the start of the Dispatch clocks works and doesn't wait
forever.

rdar://148899609
2025-05-06 17:00:43 +01:00
Meghana Gupta
a9d807d39d Disable failing test - reflect_task.swift 2025-05-06 00:04:57 -07:00
Holly Borla
b684e716fe Merge pull request #81275 from jamieQ/invalid-isolated-any-conversion-6.2
[6.2][Sema]: ban @isolated(any) conversions to synchronous function types
2025-05-05 18:00:20 -07:00
Alastair Houghton
55cda7dd85 Merge pull request #80795 from al45tair/eng/PR-149058236-6.2
[Concurrency] Remove -executor-factory option and replace with magic type.
2025-05-04 18:29:30 +01:00
Jamie
89b98a2cb5 [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.

(cherry picked from commit 629e208970)
2025-05-03 12:51:39 -05:00
Pavel Yaskevich
fb04803459 Merge pull request #81237 from xedin/rdar-150397825-6.2
[6.2][Concurrency] Account for explicit `@concurrent` on closures
2025-05-01 22:14:24 -07:00