Commit Graph

16370 Commits

Author SHA1 Message Date
Alastair Houghton
eb4c81d60e [Threading] Don't use TLS keys as template arguments.
There's no guarantee that e.g. pthread_key_t is an integral type.  It could
be some kind of struct, or some other thing that isn't valid as a template
argument.

rdar://90776105
2022-06-07 07:39:53 +01:00
Alastair Houghton
c7c1c1be80 [Threading] Fix some problems with the C11 threading code.
These changes are needed to get things building with a C11 threads shim
header on macOS.

rdar://90776105
2022-06-07 07:39:53 +01:00
Alastair Houghton
0e9318cec5 [Threading] Put everything through git clang-format.
Just formatting changes.

rdar://90776105
2022-06-07 07:39:53 +01:00
Alastair Houghton
f3a412dd53 [Threading] Remove thread_get_main().
Removing thread_get_main() means we don't need a static initializer on
Darwin, which means we can delete Darwin.cpp as well.  We can also delete
Nothreads.cpp while we're about it, because there's nothing in that file.

rdar://90776105
2022-06-07 07:39:53 +01:00
Alastair Houghton
ef2e40a937 [Concurrency][Windows] Remove unnecessary includes.
TaskLocal.cpp doesn't need <handleapi.h> or <processthreadsapi.h>, both of
which want <windows.h>, which isn't included any more.

rdar://90776105
2022-06-07 07:39:52 +01:00
Alastair Houghton
e305a7dcf6 [Concurrency][Windows] Add a couple of includes for Windows.
Actor.cpp does need <io.h> still, and Task.cpp should have been including
<windows.h>

rdar://90776105
2022-06-07 07:39:52 +01:00
Alastair Houghton
14a4bd45b6 [Concurrency][Threading] Remove use of platform thread functions.
The concurrency library can use the new threading library functions,
which avoids the problem of including <windows.h>.

rdar://90776105
2022-06-07 07:39:52 +01:00
Alastair Houghton
66f6eb6bc6 [Runtime][Windows] A couple of files need to include <windows.h>
We shouldn't include <windows.h> implicitly from .cpp files, but should
do it directly so that we know it's there.

Also, if we're including <windows.h>, do it at the top of the file.

rdar://90776105
2022-06-07 07:39:52 +01:00
Alastair Houghton
05cccf939b [Runtime][Windows] Need to link with Synchronization.lib.
We're using some functions from Synchronization.lib now, after the
threading changes.

rdar://90776105
2022-06-07 07:39:52 +01:00
Alastair Houghton
8615983174 [Build] Fix static linking.
When we static link against libswiftCore, we need it to contain the
actual object modules from the threading library (when it's dynamically
linked, the shared object will already contain those modules because it's
been linked against libswiftThreading), which means that the threading
library in the stdlib needs to be an OBJECT_LIBRARY rather than a STATIC
library (otherwise people will have to statically link against the
threading library as well, and that'll need to be installed, and we don't
want that).

rdar://90776105
2022-06-07 07:39:52 +01:00
Alastair Houghton
6d1b6dbd1c [Threading] Fix the Linux build.
A few fixes specifically for the Linux build.

rdar://90776105
2022-06-07 07:39:52 +01:00
Alastair Houghton
e934cbcf23 [Threading] Fix case sensitivity bug.
The file is called Nothreads.cpp, not NoThreads.cpp.

rdar://90776105
2022-06-07 07:39:51 +01:00
Alastair Houghton
f5bdb858e0 [Threading] Create new threading library and use it.
Moved all the threading code to one place.  Added explicit support for
Darwin, Linux, Pthreads, C11 threads and Win32 threads, including new
implementations of Once for Linux, Pthreads, C11 and Win32.

rdar://90776105
2022-06-07 07:39:51 +01:00
Alastair Houghton
66b9d21000 [Runtime] Remove all use of read/write locks.
Read/write locks are not as good as you'd think; a simple mutex is better in
almost all cases.

rdar://90776105
2022-06-07 07:39:51 +01:00
Alastair Houghton
0cf687aa2b [Build][Runtime] Replace SWIFT_STDLIB_SINGLE_THREADED_RUNTIME.
SWIFT_STDLIB_SINGLE_THREADED_RUNTIME is too much of a blunt instrument here.
It covers both the Concurrency runtime and the rest of the runtime, but we'd
like to be able to have e.g. a single-threaded Concurrency runtime while
the rest of the runtime is still thread safe (for instance).

So: rename it to SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY and make it just
control the Concurrency runtime, then add a SWIFT_STDLIB_THREADING_PACKAGE
setting at the CMake/build-script level, which defines
SWIFT_STDLIB_THREADING_xxx where xxx depends on the chosen threading package.

This is especially useful on systems where there may be a choice of threading
package that you could use.

rdar://90776105
2022-06-07 07:39:51 +01:00
Doug Gregor
0fe2d7b003 Merge pull request #59282 from DougGregor/back-deploy-concurrency-rebuild
Inline the Swift 5.6 concurrency library as a separate back-deploy library
2022-06-06 15:13:31 -07:00
Doug Gregor
588a1eb519 Ensure that we enabled override hooks in the concurrency back-deployment lib
Fixes rdar://94184066.
2022-06-06 10:48:00 -07:00
Doug Gregor
ffb37ed057 Inline the Swift 5.6 concurrency library as a separate back-deploy library 2022-06-06 10:38:25 -07:00
Jager-yoo
ce6005d870 [Concurrency] fix grammatically incorrect phrase 2022-06-04 14:50:09 +09:00
Robert Widmann
9c72d09dfe Merge pull request #59142 from Jager-yoo/fix-typo-supersede
[Gardening] fix typo "supercede" -> "supersede"
2022-06-03 09:03:59 -06:00
Alex Hoppen
4aa2bbbf06 Revert "Merge pull request #42447 from al45tair/eng/PR-90776105"
This reverts commit 8bcb71140f, reversing
changes made to c4dd271d36.
2022-06-02 18:03:23 +02:00
Alex Hoppen
935e0dda4a Revert "Merge pull request #59223 from al45tair/pr/fix-bdp-threading"
This reverts commit 94c9ce6473, reversing
changes made to 4967cd58a1.
2022-06-02 18:03:08 +02:00
Alex Hoppen
6c0636bfa3 Revert "Merge pull request #59227 from al45tair/pr/fix-bd-concurrency-2"
This reverts commit 729f912e43, reversing
changes made to b7fd963b79.
2022-06-02 18:02:48 +02:00
Alastair Houghton
35acc21739 [Concurrency] Fix back deploying concurrency threading (take 2).
Looks like I got the fix slightly wrong.  Sorry.  This should work.
2022-06-02 16:47:02 +01:00
Alastair Houghton
d3d7f4a4f8 [Concurrency] Fix back deploy concurrency threading.
If building the stdlib/runtime is disabled, building BackDeployConcurrency
still needs the Threading object library.
2022-06-02 14:23:41 +01:00
swift-ci
9a0978a5a2 Merge pull request #59200 from glessard/se-unaligned-loads-docs
[docs] fix a parameter description for storeBytes
2022-06-01 13:19:06 -07:00
Alastair Houghton
8bcb71140f Merge pull request #42447 from al45tair/eng/PR-90776105
[Build][Runtime] Add a new threading library.
2022-06-01 12:57:23 -07:00
Alejandro Alonso
c59f47389f Add Script and Script Extension tests (#59194) 2022-06-01 09:55:09 -07:00
Guillaume Lessard
0895934303 [docs] fix a parameter description for storeBytes 2022-06-01 09:04:43 -06:00
Alastair Houghton
e1bc4f126b [Build][Concurrency] Fix Concurrency build to work for Linux.
`SWIFT_BUILD_STATIC_STDLIB` is not mutually exclusive with
`SWIFT_BUILD_DYNAMIC_STDLIB`, and Linux sets both, so we can't use
`SWIFT_BUILD_STATIC_STDLIB` to conditionalise things.

The linker error about duplicate definitions for the threading error
handler was happening because we were forced to include the object
containing that symbol; moving it to another object should fix that.

And it turns out there's a way to get CMake to include the threading
object library only when building a shared object, so use that too.

rdar://90776105
2022-06-01 13:25:48 +01:00
Daniel Duan
c368d73b5b [stdlib] Delete unused gyb variable (#59197)
This variable is no longer referenced anywhere.
2022-06-01 03:15:15 -07:00
swift-ci
f1ed622810 Merge pull request #59187 from glessard/se-unaligned-loads-docs
[docs] clarify docs for load, loadUnaligned and storeBytes
2022-05-31 17:16:26 -07:00
Guillaume Lessard
11138424a7 [docs] clarify docs for load, loadUnaligned and storeBytes
- outdated and incorrect information removed
2022-05-31 15:55:09 -06:00
Alastair Houghton
68dfde2405 [Build] Fix some issues with the standalone library build.
When we're building static libraries, we don't need to include the
threading objects in both Concurrency and Core, and we also don't need
two copies of the threading library's fatal error handler.

rdar://90776105
2022-05-31 16:08:20 +01:00
Max Desiatov
1ef2eeffa4 Fix typo in DistributedActorSystem.swift doc comment
`an distributed actor` -> `a distributed actor`
2022-05-29 19:21:43 +01:00
Jager-yoo
3b8db192a0 [Gardening] fix typo "supercede" -> "supersede" 2022-05-29 03:35:24 +09:00
Mike Ash
0bf212ad76 Merge pull request #59095 from mikeash/dont-trust-unmangled-names
[Runtime] Don't try to demangle unprefixed untrusted names. Remove operator new/delete hackery.
2022-05-26 09:27:39 -04:00
Yuta Saito
b6baa3fd2a Merge pull request #58514 from kateinoigakukun/katei/upstream-clock-cpp
[stdlib] Port SE-0329 Clock APIs to WASI
2022-05-26 22:02:07 +09:00
Mike Ash
8f072d1c29 [Runtime] Don't try to demangle unprefixed untrusted names. Remove operator new/delete hackery.
The operator new/delete overrides aren't working out due to inconsistent inlining of std::string creation/deletion. We can end up creating one with the global new but destroying it with our local delete. If they aren't compatible, this crashes.

Instead, avoid problematic new/delete activity coming from lookup of ObjC class names. Names passed to getObjCClassByMangledName must either have a standard mangled name prefix, start with a digit (for unprefixed mangled names) or use the convenience dot syntax. Check for those up front and immediately reject anything else. This has the added bonus of failing more quickly for non-Swift names.

rdar://93863030
2022-05-25 22:40:33 -04:00
Philip Turner
c74cbce95a Fix incorrect derivative (#41423) 2022-05-24 23:32:04 -07:00
Yuta Saito
594d3adabd Merge pull request #39300 from kateinoigakukun/katei/wasm-least-valid-addr
[Wasm] Specify the least valid pointer for wasm32
2022-05-25 14:31:38 +09:00
Max Desiatov
1d500723d6 Set SWIFT_ABI_WASM32_LEAST_VALID_POINTER to 4096 2022-05-24 18:59:31 +01:00
Alastair Houghton
43cc1f97ba [Threading] Use llvm::Optional<> rather than making a zero lower bound special.
While most systems aren't going to have their stack bottom at zero,
using llvm::Optional<> here is cleaner.

rdar://90776105
2022-05-24 17:46:33 +01:00
Alastair Houghton
3a5f10356c [Threading] Fix a few things following rebase.
After rebasing, a few things broke.  Fix them.

rdar://90776105
2022-05-24 16:42:36 +01:00
Alastair Houghton
a987cb9eac [Concurrency] Remove redundant include.
Clean up an unnecesary include.

rdar://90776105
2022-05-24 14:57:42 +01:00
Alastair Houghton
fc4f941185 [Threading] Move stack bounds fetching into the threading library.
Fetching the current stack bounds is done using threading functions, so
should be in the threading library.

rdar://90776105
2022-05-24 14:57:42 +01:00
Alastair Houghton
69f0b03a73 [Threading] Don't use TLS keys as template arguments.
There's no guarantee that e.g. pthread_key_t is an integral type.  It could
be some kind of struct, or some other thing that isn't valid as a template
argument.

rdar://90776105
2022-05-24 14:57:42 +01:00
Alastair Houghton
2884ddbc3e [Threading] Fix some problems with the C11 threading code.
These changes are needed to get things building with a C11 threads shim
header on macOS.

rdar://90776105
2022-05-24 14:57:42 +01:00
Alastair Houghton
b5bd267ff1 [Threading] Put everything through git clang-format.
Just formatting changes.

rdar://90776105
2022-05-24 14:57:41 +01:00
Alastair Houghton
6e875dacc9 [Threading] Remove thread_get_main().
Removing thread_get_main() means we don't need a static initializer on
Darwin, which means we can delete Darwin.cpp as well.  We can also delete
Nothreads.cpp while we're about it, because there's nothing in that file.

rdar://90776105
2022-05-24 14:57:41 +01:00