Commit Graph

630 Commits

Author SHA1 Message Date
Alex Martini
5d6c179df1 Add missing 'else' to guard statements.
Fixes <rdar://84895831>.
2021-12-07 12:09:14 -08:00
najacque
57ad1f1c7d Merge pull request #40115 from amartini51/concurrency_docs_to_main
Cherry-pick concurrency docs
2021-12-07 11:59:56 -08:00
Berik Visschers
7fb3624ee7 Fix typo UnsafeContination -> UnsafeContinuation 2021-12-04 01:35:10 +01:00
Kuba (Brecka) Mracek
7e33575c6b Re-import LLVMSupport from llvm-project and enforce header includes only being used from the Swift fork when building stdlib (#40173)
* Enforce using headers from Swift's LLVMSupport fork and not llvm-project when building stdlib

* [LLVMSupport] Re-import LLVMSupport .cpp and .h files from 9ff3a9759b7c2f146e7f46e4aebc60453c577c5a from apple/llvm-project

Done via the following commands, while having llvm-project checked out at 9ff3a9759b7c2f146e7f46e4aebc60453c577c5a, a
commit on the stable/20210726 branch of apple/llvm-project, <9ff3a9759b>:

for i in swift/stdlib/public/LLVMSupport/*.cpp ; do cp llvm-project/llvm/lib/Support/$(basename $i) $i ; done
for i in swift/stdlib/include/llvm/ADT/*.h; do cp llvm-project/llvm/include/llvm/ADT/$(basename $i) $i ; done
for i in swift/stdlib/include/llvm/Support/*.h; do cp llvm-project/llvm/include/llvm/Support/$(basename $i) $i ; done
cp llvm-project/llvm/include/llvm/ADT/ScopeExit.h swift/stdlib/include/llvm/ADT/ScopeExit.h
cp llvm-project/llvm/include/llvm/ADT/Twine.h swift/stdlib/include/llvm/ADT/Twine.h
cp llvm-project/llvm/include/llvm/Support/raw_ostream.h swift/stdlib/include/llvm/Support/raw_ostream.h

* [LLVMSupport] Re-namespace the LLVMSupport fork after re-forking by re-applying b72788c27a

More precisely:

1) git cherry-pick b72788c27a
2) manually resolve the conflict in AlignOf.h by keeping the HEAD's version of the chunk and discarding the cherry-pick's change
3) git add AlignOf.h
4) git status | grep "deleted by us" | awk '{print($4)}' | xargs git rm
5) git cherry-pick --continue

Original namespacing commit message:

> This adds the `__swift::__runtime` inline namespace to the LLVMSupport
> interfaces.  This avoids an ODR violation when LLVM and Swift are in the
> same address space.  It also will aid in the process of pruning the
> LLVMSupport library by ensuring that accidental leakage of the llvm
> namespace does not allow us to remove symbols which we rely on.

* [LLVMSupport] Re-apply "pruning" on re-forked LLVMSupport from bb102707ed

This re-applies the "pruning" commit from bb102707ed, which did the following:
- Remove many whole files,
- Remove "epoch tracking" and "reverse iteration" support from ADT containers
- Remove "ABI break checking" support from STLExtras
- Remove float parsing functions from StringExtras.h
- Remove APInt/APSInt dependencies from StringRef.h + StringRef.cpp (edit distance, int parsing)
- Remove some variants of error handling and dependency of dbgs() from ErrorHandling.h and ErrorHandling.cpp

We don't need to do the whole-file-removal step, because that's already done, but the rest is re-applied by doing:

1) git cherry-pick bb102707ed
2) manually resolving conflict in ADT/DenseMap.h by keeping HEAD's version of the chunk and removing epoch tracking from it
3) manually resolving conflict in ADT/STLExtras.h by keeping HEAD's version of the chunk and removing ABI check checking from it
4) manually resolving conflict in ADT/StringExtras.h by deleting the whole chunk (removing APInt/APSInt dependent functions)
5) manually resolving conflict in ErrorHandling.cpp by force-applying the cherry-pick's version (removing write() calls and OOM callback)
6) manually resolving the three conflicts in CMakeLists.txt files by keeping HEAD's version completely
7) git add stdlib/include/llvm/{ADT/StringSwitch.h,ADT/Twine.h,Support/raw_ostream.h}

Original commit description:

> Reduce LLVMSupport to the subset required for the runtime.  This reduces
> the TCB and the overheads of the runtime.  The inline namespace's
> preservation ensures that ODR violations do not occur.

* [LLVMSupport] Re-apply all post-import modifications on LLVMSupport that the Swift's fork has

Since the previous commits re-imported "vanilla" versions of LLVMSupport, we need to re-apply all modifications that the Swift's fork has made since the last import. More precisely:

1) git diff 7b70120440cd39d67a595a7d0ea4e828ecc6ee44..origin/main -- stdlib/include/llvm stdlib/public/LLVMSupport | git apply -3 --exclude "stdlib/include/llvm/Support/DataTypes.h" --exclude "stdlib/include/llvm/Config/llvm-config.h.cmake"
2) manually resolve conflict in STLExtras.h by applying the "__swift::__runtime" prefix to HEAD's version
3) manually resolve conflicts in StringSwitch.h by keeping HEAD's version (removing the Unicode BOM marker at the beginning of the file, keeping LLVM's version of the string functions)
4) manually resolve conflict in SwapByteOrder.h by adding the `defined(__wasi__)` part into the #if

* [LLVMSupport] Drop remaining dependencies on APSInt.h, Error.h, DataTypes.h and STLForwardCompat.h

Most cases can drop the #includes without any changes, in some cases there are
straighforward replacements (climits, cstdint). For STLForwardCompat.h, we need
to bring in parts of STLForwardCompat.h from llvm-project.

* [LLVMSupport] Remove raw_ostream.h and drop dependencies to it from the runtime

* [LLVMSupport] Simplify error reporting in SmallVector and avoid using std::string when producing fatal errors messages

Co-authored-by: Saleem Abdulrasool <compnerd@compnerd.org>
2021-12-02 17:21:51 -08:00
swift-ci
83e3ae8111 Merge pull request #40265 from mikeash/task-id-64-bit 2021-12-01 10:37:36 -08:00
Saleem Abdulrasool
de1c3e6580 Concurrency: report errors on failures on Windows
The usage of libdispatch in Concurrency is dynamic - it does not
explicitly link against libdispatch and thus cannot directly invoke
`dispatch_main`.  While linking against dispatch would be ideal, this
should improve the current path.
2021-11-30 08:19:53 -08:00
Saleem Abdulrasool
910fbee14e gardening: make c++98-compat-extra-semi an error
This cleans up 90 instances of this warning and reduces the build spew
when building on Linux.  This helps identify actual issues when
building which can get lost in the stream of warning messages.  It also
helps restore the ability to build the compiler with gcc.
2021-11-27 11:40:17 -08:00
Mike Ash
bac6965946 [Concurrency] Make task IDs 64-bit.
The 32-bit identifier in Job is locked down at this point, so we expand the ID by storing the top 32 bits separately inside AsyncTask::PrivateStorage.

rdar://85167409
2021-11-19 15:24:35 -05:00
Saleem Abdulrasool
306662fd29 Concurrency: fix UB in DefaultActor initialization
This fixes a latent UB instance in the `DefaultActor` implementation
that has haunted the Windows target.  The shared constructor for the
type caused an errant typo that happened to compile which introduced
UB but happened to work for the non-Windows cases.  This happened to
work for the other targets as `swift::atomic` had a `std::atomic` at
on most configurations, and the C delegate for the Actor initializer
happened to overlap and initialize the memory properly.  The Windows
case used an inline pointer width value but would be attempted to be
initialized as a `std::atomic`.  Relying on the overlap is unsafe to
assume, and we should use the type's own constructor which delegates
appropriately.
2021-11-19 10:34:41 -08:00
swift-ci
37ea254cc1 Merge pull request #40220 from DougGregor/predates-concurrency 2021-11-19 01:14:42 -08:00
swift-ci
a41f1b0b58 Merge pull request #40252 from kavon/main-taskgroup-bug 2021-11-18 19:59:12 -08:00
Kavon Farvardin
69e80a1201 use compare_exchange_strong to protect agianst spurious failures
A `compare_exchange_weak` can spuriously return false, regardless of
whether a concurrent access happened. This was causing a null-pointer
dereference in TaskGroupImpl::poll in a narrow circumstance.

The dereference failure only appears when using the `arm64`
slice of the runtime library, since Clang will use `ldxr/stxr` for
synchronization on such targets. The weak form does not retry on a
spurious failure, but the strong version will.

resolves rdar://84192672
2021-11-18 16:37:04 -08:00
Doug Gregor
089cc4f101 Remove last use of @_unsafeSendable in the concurrency library 2021-11-18 11:20:53 -08:00
Mike Ash
cf3c131e7c [Reflection] Add API for inspecting async task allocation slabs.
We remove the existing `swift_reflection_iterateAsyncTaskAllocations` API that attempts to provide all necessary information about a tasks's allocations starting from the task. Instead, we split it into two pieces: `swift_reflection_asyncTaskSlabPointer` to get the first slab for a task, and `+swift_reflection_asyncTaskSlabAllocations` to get the allocations in a slab, and a pointer to the next slab.

We also add a dummy metadata pointer to the beginning of each slab. This allows tools to identify slab allocations on the heap without needing to locate every single async task object. They can then use `swift_reflection_asyncTaskSlabAllocations` on such allocations to find out about the contents.

rdar://82549631
2021-11-18 14:15:25 -05:00
Evan Wilde
05fa143a88 Merge pull request #40221 from etcwilde/ewilde/include-missing-api-in-swinterface
Include missing `_getMainExecutor` and `_asyncMainDrainQueue` in concurrency swiftinterface
2021-11-18 09:48:15 -08:00
John McCall
84623ceac4 Teach default actors to execute jobs in priority order.
rdar://76473589
2021-11-18 00:32:58 -05:00
Evan Wilde
1c852f9179 Adding @usableFromInline to needed API
getMainExecutor and asyncMainDrainQueue function declarations are needed
to compile programs with the asyn-main function. The functions are
declared internal, so they don't show up in the swift interface files.
2021-11-16 21:36:58 -08:00
John McCall
26ea1fe6e9 Miscellaneous improvements to the cooperative executor:
- Switch to using ListMerger for priority insertion.
- Move ready delayed jobs to the back to the queue instead of
  running them immediately, before anything currently in the queue.
- Respect priorities in delayed jobs.
- Use the proper std::chrono facilities for managing deadlines
  instead of doing all the math on nanoseconds since the epoch.
- Take advantage of the second word of queue-private storage to
  avoid allocating a separate job when a deadline fits there.
2021-11-16 03:21:49 -05:00
John McCall
c45f2c4334 [NFC] Introduce a typedef for job delay in nanoseconds. 2021-11-16 01:50:52 -05:00
swift-ci
4fbf7a5d55 Merge pull request #40192 from DougGregor/unchecked-continuation-conditional-sendable 2021-11-15 19:15:13 -08:00
Doug Gregor
5a99ae485e Make (Unsafe|Checked)Continuation's Sendable conformance conditional.
Make the continuation type's conformances to the `Sendable` protocol
conditional on the sendability of the result yielded when the
resumption is performed. This ensures that one cannot silently escape
a continuation's result out of a task or actor, closing a safety hole
in Sendable checking.

Fixes rdar://85419546.
2021-11-15 16:41:07 -08:00
John McCall
0bd0f772d8 NFC: move the global executor implementations into their own files 2021-11-15 18:29:08 -05:00
swift-ci
2a0c8a186a Merge pull request #40157 from DougGregor/unchecked-sendable-stdlib 2021-11-12 09:54:47 -08:00
Doug Gregor
353daabf8d Replace UnsafeSendable with @unchecked Sendable in the standard library. 2021-11-12 07:56:10 -08:00
Guillaume Lessard
8cc076000a Merge pull request #40116 from glessard/concurrency-assertions
[stdlib] replace uses of assert in the Concurrency module
2021-11-11 09:50:20 -07:00
Philippe Hausler
71cc7666f9 Correct lifetime based cancellation of AsyncStream and AsyncThrowingStream (#40087) 2021-11-11 08:30:28 -08:00
Guillaume Lessard
eb6348447b [stdlib] replace uses of assert in the Concurrency module
- we define a local equialent to `_internalInvariant` that will compile to nothing in release builds
- `assert` was still detectable in release builds, presumably costing execution time
2021-11-09 19:02:30 -07:00
Alex Martini
dee26fbc99 Restore stray whitespace. 2021-11-09 17:23:38 -08:00
Alex Martini
28f15008ee Cherry pick Swift 5.5 doc changes in TaskSleep.swift 2021-11-09 17:23:38 -08:00
Alex Martini
3977d8ede8 Cherry pick Swift 5.5 doc changes in TaskGroup.swift 2021-11-09 17:23:38 -08:00
Alex Martini
0f75fc7f51 Cherry pick Swift 5.5 doc changes in Task.swift 2021-11-09 17:23:38 -08:00
Alex Martini
699421c79b Cherry pick Swift 5.5 doc changes in PartialAsyncTask.swift 2021-11-09 17:23:38 -08:00
Alex Martini
e7d229af7f Cherry pick Swift 5.5 doc changes in GlobalActor.swift 2021-11-09 17:23:38 -08:00
Alex Martini
7913b82839 Cherry pick Swift 5.5 doc changes in Executor.swift 2021-11-09 17:23:38 -08:00
Alex Martini
c7aec3d6b7 Cherry pick Swift 5.5 doc changes in CheckedContinuation.swift 2021-11-09 17:23:38 -08:00
Alex Martini
4aa1485c49 Cherry pick Swift 5.5 doc changes in AsyncThrowingStream.swift 2021-11-09 17:23:38 -08:00
Alex Martini
8162400215 Cherry pick Swift 5.5 doc changes in AsyncThrowingPrefixWhileSequence.swift 2021-11-09 17:18:24 -08:00
Alex Martini
cd97ed714a Cherry pick Swift 5.5 doc changes in AsyncStream.swift 2021-11-09 17:18:24 -08:00
Alex Martini
64ab9dda79 Cherry pick Swift 5.5 doc changes in AsyncSequence.swift 2021-11-09 15:34:12 -08:00
Alex Martini
75dd98de42 Cherry pick Swift 5.5 doc changes in AsyncIteratorProtocol.swift 2021-11-09 15:31:29 -08:00
swift-ci
95129274bb Merge pull request #39817 from AtariDreams/unsafesendable 2021-11-05 17:44:37 -07:00
Karoy Lorentey
2732765096 [CMake] Introduce availability macros for all known stdlib releases
Introduce "SwiftStdlib x.y"-style availability macros for all known releases of the stdlib, adding them to the swift flags of all Swift libraries and tests.
2021-10-28 18:31:54 -07:00
Karoy Lorentey
47956908b7 [Concurrency] SwiftStdlib 5.5 ⟹ SwiftStdlib 5.1 (usages)
The concurrency runtime now deploys back to macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, which corresponds to the 5.1 release of the stdlib.

Adjust macro usages accordingly.
2021-10-28 14:36:36 -07:00
Karoy Lorentey
fb090fde5e [Concurrency] SwiftStdlib 5.5 ⟹ SwiftStdlib 5.1 (definitions)
The concurrency runtime now deploys back to macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, which corresponds to the 5.1 release of the stdlib.

Adjust the definition of the SwiftStdlib availability macro accordingly.
2021-10-28 14:36:21 -07:00
Doug Gregor
9e41e37e76 Merge pull request #39935 from DougGregor/watchos-noasyncframepointer-backdeploy
Disable the definition and use of swift_async_extendedFramePointerFlags on watchOS
2021-10-27 16:26:13 -07:00
Doug Gregor
26b7cbc4ae Define swift_async_extendedFramePointerFlags for the watchOS simulator 2021-10-27 12:04:20 -07:00
Doug Gregor
4aca32c0a4 Disable the definition and use of swift_async_extendedFramePointerFlags on watchOS
The asm definition of `swift_async_extendedFramePointerFlags` prevents
the use of bitcode with the back-deployment libraries, so remove the
definition and use of this symbol from watchOS binaries entirely.
Instead, always force the async frame bit to be set. This trades off
backtraces on older OS's for debuggability of newer ones. If it causes
problems, it can be disabled via the option
`-swift-async-frame-pointer=never`.

Fixes rdar://84687579.
2021-10-26 22:26:37 -07:00
Mike Ash
c60b68608c [Concurrency] Re-fix ABI regression in task groups due to Sendable requirements.
There was an attempted fix in bed3c4b313 but it had extra underscores at the start of the @_silgen_name identifiers.

rdar://83617067
2021-10-26 11:40:52 -04:00
Doug Gregor
48eab6d732 Merge pull request #39872 from DougGregor/mainactor-run-hop-back 2021-10-22 17:21:04 -07:00
Doug Gregor
420e21a287 Fix the other implementation, too. 2021-10-22 08:39:22 -07:00