Commit Graph

1607 Commits

Author SHA1 Message Date
Konrad `ktoso` Malawski
f300164acc [Concurrency] Improve crash message on continuation misuse (#75613) 2024-08-02 00:46:45 -07:00
Alex Martini
63323e04a9 Match parameter names in docs to the declaration 2024-08-01 11:01:02 -07:00
Alex Martini
70536cd56a Match parameter name in docs to declaration 2024-08-01 10:28:26 -07:00
Alex Martini
736be735e6 DOCS: Add missing periods (#75407)
* Add missing period at end of sentence

* Add missing period

Co-authored-by: LamTrinh.Dev <me@lamtrinh.dev>

---------

Co-authored-by: LamTrinh.Dev <me@lamtrinh.dev>
2024-07-23 22:12:10 -07:00
Mike Ash
75fa43ebd8 [Concurrency] Clear current task TSD before enqueuing task in swift_task_switch. (#74736)
The executor may execute and free the task while the enqueue code is still finishing up. If that code tries to get an async backtrace (for example, if it calls malloc/free with malloc stack logging enabled) then it will find a dangling pointer in the current task TSD, and dereferencing it may crash.

rdar://130125017
2024-07-24 12:29:01 +09:00
Kavon Farvardin
2557ba96c8 Noncopyable: deprecate '@_moveOnly' attribute
This hidden attribute is a leftover from before the '~Copyable' syntax.

rdar://130526083
2024-07-23 11:05:33 -07:00
Mike Ash
c1772eba50 [Concurrency] Fix unsafe continuation validation when a continued task has been destroyed.
SWIFT_DEBUG_VALIDATE_UNCHECKED_CONTINUATIONS works by tracking the context pointers of active continuations, and verifying that a resumed context is in the set of active continuations. However, the resume calls are passed the task pointer, not the context pointer. The context pointer is recovered from the task. If the task has been destroyed, the context pointer is invalid. This can result in a weird error message or it can crash if the context pointer is used before checking it against the active continuations.

Instead, track tasks that are suspended pending an unchecked continuation. If the task is destroyed, we'll still be passed the dangling pointer and check that pointer against the tracking info. We must be sure to check that before trying to use anything inside it.

rdar://131858544
2024-07-16 15:08:26 -04:00
Doug Gregor
a3bf1fc4c2 Merge pull request #75248 from DougGregor/unsafe-inherit-executor-the-rest
Extend _unsafeInheritExecutor_ to remaining @_unsafeInheritExecutor APIs
2024-07-15 18:46:38 -07:00
Doug Gregor
a47483c0ec Fix ABI issue with TaskLocal.withValue and update ABI test 2024-07-15 14:37:45 -07:00
Doug Gregor
f6ba1bbeaa Adopt _unsafeInheritExecutor_ workaround on the internal withValueImpl 2024-07-15 14:12:40 -07:00
Doug Gregor
d6b6bafe60 Extend _unsafeInheritExecutor_ to remaining @_unsafeInheritExecutor APIs
Extend the _unsafeInheritExecutor_ workaround to all remaining APIs in the
Concurrency library that have adopted `#isolation` default arguments to
(safely) stay in the caller's isolation domain...

... except one. Clock.measure() is currently running into problems with
the type checker workaround and needs a little more thought.

Fixes rdar://131760111.
2024-07-15 14:12:36 -07:00
Kenta Kubo
7b7110061f [stdlib][docs] Fix the SeeAlso documentation for withDiscardingTaskGroup (#72767)
The SeeAlso documentation for `withDiscardingTaskGroup` is missing trailing backticks.
2024-07-15 13:51:21 +09:00
Mykola Pokhylets
816d62c972 Merge remote-tracking branch 'upstream/main' into mpokhylets/isolated-deinit
# Conflicts:
#	include/swift/Basic/Features.def
#	lib/SILGen/SILGenDestructor.cpp
#	test/Concurrency/flow_isolation.swift
#	test/abi/macOS/arm64/concurrency.swift
#	test/abi/macOS/x86_64/concurrency.swift
2024-07-11 13:11:59 +02:00
Mykola Pokhylets
e9173ff2f4 Make sure legacy executor checking mode is always used in swift_task_deinitOnExecutor() 2024-07-11 13:09:08 +02:00
Mykola Pokhylets
8dbddec82e Don't read current task executor to avoid extra access of the task-local storage. 2024-07-11 13:09:08 +02:00
Mykola Pokhylets
1b69068105 Keep current task executor when taking fast path in isolated deinit 2024-07-11 13:09:08 +02:00
Mykola Pokhylets
ab4d338f6a Added flags to be able to control task-locals behaviour in the future 2024-07-11 13:09:08 +02:00
Mykola Pokhylets
35f0334eb6 Rename performOnExecutor into deinitOnExecutor.
It cannot be used for executing general-purpose work, because such function would need to have a different signature to pass isolated actor instance.

And being explicit about using this method only for deinit allows to use object pointer for comparison with executor identity.
2024-07-11 13:09:07 +02:00
Mykola Pokhylets
a043ebf97a Don't switch threads when running isolated deinit of the default actor. 2024-07-11 13:09:07 +02:00
Mykola Pokhylets
cdba7b321f Removed explicit deinit from MainActor - not needed. 2024-07-11 13:09:07 +02:00
Mykola Pokhylets
f04f1de75e Fixed some typos 2024-07-11 13:09:07 +02:00
Mykola Pokhylets
72cad34662 Don't hop to @MainActor if already running on the main thread. 2024-07-11 13:09:06 +02:00
Mykola Pokhylets
62dbc6c966 Fixed some tests. Using extract_executor SIL instruction instead of custom code. 2024-07-11 13:09:06 +02:00
Mykola Pokhylets
b13da727b5 Removed declaration of the AdHocJob from the ABI headers 2024-07-11 13:09:06 +02:00
Mykola Pokhylets
411cdb7f73 Added unit-tests for (not)copying task-local values. Fixed release after deallocation. 2024-07-11 13:09:06 +02:00
Mykola Pokhylets
d4e449b62d SILGen for isolated deinit 2024-07-11 13:09:05 +02:00
Mykola Pokhylets
b7e23c2e2e Runtime support for isolated deinit 2024-07-11 13:09:04 +02:00
Doug Gregor
2a8b3fcf95 Merge pull request #75093 from DougGregor/unsafe-inherit-executor-vs-pound-isolation
Ensure that a `@_unsafeInheritExecutor` function does not depend on `#isolation`
2024-07-10 11:05:37 -07:00
Doug Gregor
8964436f36 Add _unsafeInheritExecutor_ version of TaskLocal.withValue 2024-07-09 15:38:38 -07:00
Allan Shortlidge
45f3e94b46 AST: Promote AssociatedTypeImplements feature to baseline. 2024-07-09 14:28:30 -07:00
Allan Shortlidge
b85da32707 AST: Promote OptionalIsolatedParameters feature to baseline. 2024-07-09 14:28:29 -07:00
Ian Anderson
dad0a21b01 Merge pull request #74920 from ian-twilightcoder/builtin_float_module-abi-name
[overlay] Support the older @rpath Darwin library for _Builtin_float's $ld$previous$ symbols
2024-07-09 12:04:37 -07:00
Ian Anderson
9e9d66efc9 [overlay] Support the older @rpath Darwin library for _Builtin_float's $ld$previous$ symbols
The _Builtin_float symbols were moved twice, most recently from the OS Darwin library, but previously they were in the embedded @rpath Darwin library. @_originallyDefinedIn doesn't support multiple install names, but it can be replaced with -module-abi-name, and then multiple $ld$previous$ symbols can be used.
Update the Platform and Concurrency magic symbols to use $ld$previous$ everywhere.

rdar://130107191
2024-07-09 09:13:30 -07:00
Doug Gregor
a2038f92f8 Address code review feedback and fix rebase typo in a test 2024-07-09 08:13:24 -07:00
Konrad `ktoso` Malawski
a3e0b173ea [Concurrency] TaskExecutors may be non-swift objects; dont swift_release them (#75059) 2024-07-09 02:55:11 -07:00
Doug Gregor
a2b2324e7f Use @_unsafeInheritExecutor forms of with*Continuation from @_unsafeInheritExecutor functions
The move from `@_unsafeInheritExecutor` to `#isolation` for the
with*Continuation breaks code that is using `@_unsafeInheritExecutor` and
calling these APIs. This originally caused silent breakage (which manifest
as runtime crashes), and is now detected by the compiler as an error.

However, despite `@_unsafeInheritExecutor` being an unsafe,
not-intended-to-be-user-facing feature, it is indeed being used, along
with these APIs. Introduce _unsafeInheritExecutor_-prefixed versions of
the `with*Continuation` and `withTaskCancellationHandler` APIs into
the _Concurrency library that use `@_unsafeInheritExecutor`. Then,
teach the type checker to swap in these
_unsafeInheritExecutor_-prefixed versions in lieu of the originals
when they are called from an `@_unsafeInheritExecutor` function. This
allows existing code using `@_unsafeInheritExecutor` with these APIs
to continue working as it has before, albeit with a warning that
`@_unsafeInheritExecutor` has been removed.

Fixes rdar://131151376.
2024-07-08 23:35:37 -07:00
Allan Shortlidge
20d97556ae stdlib: Remove #if $TypedThrows guards.
https://github.com/swiftlang/swift/pull/72612 can be reverted because it is no
longer necessary for the interface of the stdlib to be compatible with
compilers without `$TypedThrows` support.
2024-07-08 16:52:52 -07:00
Alastair Houghton
b6e7a5107a Merge pull request #75024 from Sajjon/cyon_typo_batch__stdlib
Typos: `stdlib`
2024-07-08 10:57:54 +01:00
Konrad `ktoso` Malawski
a8f68aab4b Merge pull request #75008 from kateinoigakukun/yt/fix-mutex-guard-wasm-thread
Concurrency: Guard TG state with a mutex even with cooperative executor
2024-07-08 17:56:31 +09:00
Konrad `ktoso` Malawski
df43b63f44 [Concurrency] Attempt to unbreak embedded build (#75006) 2024-07-08 11:21:12 +09:00
Konrad `ktoso` Malawski
3c75f2fac8 Add comment explaining #if guard 2024-07-08 10:49:38 +09:00
Konrad `ktoso` Malawski
5ad2291ac0 [Concurrency] Fix build in actors as locks configuration (#75004) 2024-07-07 10:37:33 +09:00
Alexander Cyon
c21b1e68fd [stdlib] Fix typos 2024-07-06 13:09:57 +02:00
Yuta Saito
49a20d110a Concurrency: Guard TG state with a mutex even with cooperative executor
`SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY` just means that the global
executor is cooperative, but it doesn't mean that the target platform is
always single-threaded. For example, on wasm32-unknown-wasip1-threads,
the global executor is cooperative, but users can still set up their own
TaskExecutor with multiple threads.

This patch guards the `TaskGroup` state with a mutex even with a
cooperative executor by respecting threading package instead. This
change effectively affects only wasm32-unknown-wasip1-threads.
2024-07-06 08:14:07 +00:00
Allan Shortlidge
fb6ab05746 Concurrency: Restore -enable-experimental-feature IsolatedAny.
Supported older compilers don't enable this feature by default, so it can't be
omitted from the `_Concurrency` module's flags (regression from
https://github.com/swiftlang/swift/pull/74543).

Additionally, remove `@_allowFeatureSuppression(IsolatedAny)` from all
declarations. We no longer need to support compilers that don't have the
`IsolatedAny` feature, so the suppression is superfluous and the alternative
branches didn't actually build anyways. _Additionally_, the suppressible
feature logic could not handle suppressing `IsolatedAny` simultaneously with
`SendingArgsAndResults`, resulting in a broken interface because `sending` was
used outside `#if $SendingArgsAndResults` guards.
2024-07-03 10:36:47 -07:00
Konrad `ktoso` Malawski
70ed18044d Allow using older API if $BuiltinCreateAsyncTaskOwnedTaskExecutor is not available 2024-07-03 10:36:47 -07:00
Konrad `ktoso` Malawski
9ee719dbcd Prevent potential for condfail with owned task executor parameter
While the new parameter is added in a compatible way where code which
does not refer to it will get a defaulted nil value; since we refer to a
new parameter name in source, we need to guard it with a language
feature -- as old compilers will not have this new name available.

This should prevent a potential condfail issue.
2024-07-03 10:36:47 -07:00
Allan Shortlidge
b47b5ccba0 Concurrency: Remove superfluous $BuiltinBuildMainExecutor guards. 2024-07-02 22:59:28 -07:00
Allan Shortlidge
b9c12aa314 Concurrency: Remove superfluous $BuiltinExecutor guards. 2024-07-02 22:59:28 -07:00
Allan Shortlidge
346bbcaa05 Concurrency: Remove superfluous $BuiltinCreateAsyncTaskInGroup guards. 2024-07-02 22:26:55 -07:00