Commit Graph

45 Commits

Author SHA1 Message Date
Allan Shortlidge
a549d0144e stdlib: Resolve -Wmissing-designated-field-initializers warnings. 2024-11-13 09:51:29 -08:00
Yuta Saito
3198412db0 [wasm][stdlib] Fix return-address strategy selection
__GNUC__ can be defined on Wasm targets as well, so we need to check
__wasm__ first.
2023-06-10 10:15:34 +00:00
Anthony Latsis
c731089068 Gardening: Migrate stdlib sources to GH issues 2022-09-26 06:30:49 +03:00
Egor Zhdan
84a1ffcb33 [Shims] Include SwiftShims headers without ../
This replaces a number of `#include`-s like this:
```
#include "../../../stdlib/public/SwiftShims/Visibility.h"
```
with this:
```
#include "swift/shims/Visibility.h"
```

This is needed to allow SwiftCompilerSources to use C++ headers which include SwiftShims headers. Currently trying to do that results in errors:
```
swift/swift/include/swift/Demangling/../../../stdlib/public/SwiftShims/module.modulemap:1:8: error: redefinition of module 'SwiftShims'
module SwiftShims {
       ^
Builds.noindex/swift/swift/bootstrapping0/lib/swift/shims/module.modulemap:1:8: note: previously defined here
module SwiftShims {
       ^
```
This happens because the headers in both the source dir and the build dir refer to SwiftShims headers by relative path, and both the source root and the build root contain SwiftShims headers (which are equivalent, but since they are located in different dirs, Clang treats them as different modules).
2022-09-14 11:14:50 +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
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
Alastair Houghton
63a09007a1 [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-05-24 14:57:39 +01:00
Yuta Saito
d99b84e489 [Wasm] Disable use of returnaddress in exclusivity diagnostics
Function calls and returns in Wasm are protected by Wasm runtime
and there is no way to get or control return address.
2022-03-30 11:20:58 +00:00
Doug Gregor
6fd85ac7a3 Clone exclusivity save/restore for tasks into back-deployment library
The code that saves/restores the exclusivity checks for tasks was
newly introduced into the runtime. Clone that code into the back-
deployed version of the runtime.
2021-08-30 16:39:33 -07:00
Michael Gottesman
3e64d03a52 [exclusivity] Split out of Exclusivity.cpp FunctionReplacement and the Global TLSContext.
Some notes:

1. Even though I refactored out AccessSet/Access from Exclusivity.cpp ->
ExclusivityPrivate.h, I left the actual implementations of insert/remove in
Exclusivity.cpp to allow for the most aggressive optimization for use in
Exclusivity.cpp without exposing a bunch of internal details to other parts of
the runtime. Smaller routines like getHead() and manipulating the linked list
directly I left as methods that can be used by other parts of the runtime. I am
going to use these methods to enable backwards deployment of exclusivity support
for concurrency.

2. I moved function replacements out of the Exclusivity header/cpp files since
it has nothing to do with Exclusivity beyond taking advantage of the TLS context
that we are already using.
2021-07-26 12:26:08 -07:00
Michael Gottesman
e662a146de [exclusivity] Add logging lock/flushing to prevent output interleaving. 2021-07-22 13:25:10 -07:00
Michael Gottesman
f79108caf7 [exclusivity] Introduce an env variable to in asserts builds cause the exclusivity part of the runtime to emit logging information.
The specific environment variable is SWIFT_DEBUG_RUNTIME_EXCLUSIVITY_LOGGING. We only
check the environment the first time we try to lookup the TLSContext, so it
shouldn't impact exclusivity performance.

My intention is to use this to write some FileCheck tests so that we can really
be sure that the runtime is doing what we think it is. As such I also changed
the small amount of logging routines meant for use in the debugger to use stdout.
2021-07-22 13:25:10 -07:00
Michael Gottesman
0aec81614d [exclusivity] Add support for Task local exclusivity access sets.
The implemented semantics are that:

1. Tasks have separate exclusivity access sets.
2. Any synchronous context that creates tasks will have its exclusive access set
   merged into the Tasks while the Task is running.

rdar://80492364
2021-07-22 13:25:10 -07:00
Kavon Farvardin
70b7b34f09 add assertion to catch AccessSet usage errors
I ran into this while implementing
async actor inits; where I was emitting
an actor hop in the middle of
an access region, which caused the
access set to be unexpectedly empty.
2021-07-16 15:01:12 -07:00
Mike Ash
190d3fd22e [Concurrency] Use pthread_specific for thread-local storage on Darwin.
The pthread_specific APIs are better than C++ thread_local storage on Darwin since we can use Swift's reserved pthread keys there.

rdar://79504652
2021-06-29 16:56:59 -04:00
John McCall
0fb407943f [NFC] Rename swift_runtime_unreachable to swift_unreachable and make it use LLVM's support when available. 2020-10-03 02:54:56 -04:00
Kuba (Brecka) Mracek
9ead8d57fa Add a single-threaded stdlib mode, use it for the 'minimal' stdlib (#33437) 2020-08-25 06:03:14 -07:00
Saleem Abdulrasool
158332c088 runtime: remove llvm/DataTypes.h, llvm-c/DataTypes.h
Inline the standard headers that they included and remove the extra
include path.
2020-06-04 21:00:39 +00:00
Saleem Abdulrasool
70bd271e99 runtime: remove dependency on LLVM_ENABLE_THREADS
This removes the LLVMSupport usage for thread local.  This effectively
is a no-op as the runtime requires that it is built with clang, which
provides the C++11 `thread_local` support on all the targets.  In the
case that the target does not support `thread_local`, clang would
fallback to `__declspec(thread)` on MSVC and `__thread` on other modes.
However, because the runtime is always built in C++14 mode, the
`thread_local` support should be assumed to be present.  Remove the
unnecessary condition and inline the single use of the macro for
`thread_local`.
2020-05-07 12:48:57 -07:00
Saleem Abdulrasool
61ddd09199 runtime: replace LLVM_ATTRIBUTE_ALWAYS_INLINE with SWIFT_INLINE (NFC)
This replaces the `LLVM_ATTRIBUTE_ALWAYS_INLINE` with `SWIFT_INLINE`
which is equivalent but namespaced to Swift instead.  This reduces the
unnecessary reliance on LLVMSupport.
2020-05-05 11:19:15 -07:00
Kuba Mracek
84c4864911 [arm64e] Add Swift compiler support for arm64e pointer authentication 2020-02-27 16:10:31 -08:00
Erik Eckstein
7a5de47aa1 runtime: change the naming of TLS related stuff to make it more general and not specific to exclusivity checking.
Just a refactoring, NFC
2019-05-30 15:28:16 -07:00
Erik Eckstein
2ea531c3b3 IRGen/runtime: change the code generation for dynamically replaceable functions
Instead of a thunk insert the dispatch into the original function.
If the original function should be executed the prolog just jumps to the "real" code in the function. Otherwise the replacement function is called.
There is one little complication here: when the replacement function calls the original function, the original function should not dispatch to the replacement again.
To pass this information, we use a flag in thread local storage.
The setting and reading of the flag is done in two new runtime functions.

rdar://problem/51043781
2019-05-30 15:28:16 -07:00
Andrew Trick
823137b2f4 Remove runtime support for exclusivity warnings. 2018-10-13 10:06:35 -07:00
Andrew Trick
2ecb48a89d Remove exclusivity support for Swift 3 mode.
Remove the compiler support for exclusivity warnings.

Leave runtime support for exclusivity warnings in non-release builds
only for unit testing convenience.

Remove a test case that checked the warning log output.

Modify test cases that relied on successful compilation in the
presence of exclusivity violations.

Fixes: <rdar://problem/45146046> Remaining -swift-version 3 tests for exclusivity
2018-10-12 09:08:42 -07:00
Mike Ash
29ff3de4ab [Runtime][Stdlib] Use dedicated thread-local storage keys when possible.
rdar://problem/32275323 rdar://problem/44104305
2018-09-13 14:36:57 -04:00
Mike Ash
9638cb8f6e [Runtime] Fix format string warnings in Errors.cpp and Exclusivity.cpp when built for 32-bit.
rdar://problem/40345076
2018-05-25 16:16:02 -04:00
Andrew Trick
495d5aecf6 [exclusivity] Add an access marker folding pass.
Use AccessedStorageAnalysis to find access markers with no nested conflicts.

This optimization analyzes the scope of each access to determine
whether it contains a potentially conflicting access. If not, then it
can be demoted to an instantaneous check, which still catches
conflicts on any enclosing outer scope.

This removes up to half of the runtime calls associated with
exclusivity checking.
2018-05-15 12:29:19 -07:00
Michael Gottesman
636b5f67f0 [runtime] Add support for an asserts only debugging routine called swift_dumpTrackedAccesses().
This makes it easy to perform printf debugging in the debugger. I have found it
to be useful in understanding programs around exclusivity quickly.
2018-04-19 21:37:12 -07:00
Andrew Trick
89d96bff4e Runtime support for nontracking begin_access.
There are multiple reasons to do this. Primarily this is
useful as an optimization. Whenever analysis can determine that no
potentially conflicting access occurs within the scope, the access can
be demoted to "nontracking". It is also useful as an escape hatch for
future code deploying to older runtimes. For example, if a future access
scope may cross threads, and the older runtime doesn't know how to
migrate threads.

See <rdar://problem/37507434> add a flag to swift_beginAccess to inform
the runtime that an access might migrate between threads
2018-03-27 12:04:32 -07:00
Greg Parker
1a0e3e7c31 [runtime] Don't use C++ thread_local on two old Apple simulators.
32-bit iOS 9 simulator and 32-bit watchOS 2 simulator do not support
C++ thread_local, even though clang's has_feature(cxx_thread_local)
thinks they do.

rdar://35063043
2017-10-19 16:55:19 -07:00
Saleem Abdulrasool
ef70671f77 runtime: clean up some warnings
This is a smorgasbord of warning cleanups in the runtime.  This just
adjusts the casts for the various types.  There were a number of casts
which lost const qualifiers on the type.
2017-09-17 16:20:16 -07:00
Jordan Rose
9c10398514 [runtime] Expose reportToDebugger as swift_reportToDebugger.
...so that the overlays can use it. See next commit.
2017-07-13 11:18:41 -07:00
Andrew Trick
91405a7f91 Remove the hash function from the runtime's exclusive access checks.
I expect this to improve the following Onone benchmarks:
- 1.09x accessGlobal
- 1.08x accessInMatSet
- 1.06x accessIndependent

And the preexisting benchmarks:

| TEST                    | DELTA | SPEEDUP   |
|                         |       |           |
| Random                  | -7.9% | **1.09x** |
| MatMul                  | -7.6% | **1.08x** |
| XorShift                | -7.2% | **1.08x** |
| PolymorphicCalls        | -6.2% | **1.07x** |
| NopDeinit               | -6.1% | **1.06x** |
| Ary                     | -6.0% | **1.06x** |
| Integrate               | -5.8% | **1.06x** |
| StringWalk              | -5.5% | **1.06x** |
| ArrayInClass            | -5.2% | **1.06x** |
| MultiFileTogether       | -5.2% | **1.06x** |
| DictionaryHashableClass | -5.2% | **1.05x** |
| MultiFileSeparate       | -4.9% | **1.05x** |
2017-06-29 16:32:35 -07:00
Kuba (Brecka) Mracek
8cb95b8fcd Improve reporting of @objc inference issues from the Swift runtime (#10406)
* Extend Swift runtime issue reporting for @objc inference to include details about the declaration of the method (that is missing the @objc annotation) and a suggested fix-it. This changes the ABI of RuntimeErrorDetails, so we're also bumping the version.

* Update SwiftObject.mm
2017-06-22 21:35:48 -07:00
Kuba (Brecka) Mracek
d29557bd24 Change the signature of reportToDebugger and _swift_runtime_on_report to avoid using 'bool'. It's much easier to work with native-width integers only in LLDB. (#10523) 2017-06-22 21:22:27 -07:00
John McCall
4399bd37fa Fix some embarrassing list-management bugs with the exclusivity runtime
which can arise when accesses are not strictly nested.
2017-06-21 19:04:46 -04:00
Kuba (Brecka) Mracek
fec8d72ea3 Debugger hook/breakpoint for issue reporting from the Swift runtime (#10293)
* Implements a debugger hook (breakpoint) API and data structure. This structure is passed to the debugger and describes extra information about a fatal error or a non-fatal warning, which should be logged as a runtime issue.

This debugger hook is then used from two places, which currently only log to stderr:
- Runtime exclusivity violations.
- Swift 3 implicit Obj-C entrypoints.

A subsequent LLDB support will be able to catch these callbacks and show the runtime issues in a better way than just logging them to stderr.  When the debugger is not attached, this shouldn't have any effect.
2017-06-19 14:28:19 -07:00
Kuba (Brecka) Mracek
a5a59f5aed [runtime] Enhance output from dynamic exclusivity violations. Print current stacktrace and the symbolicated frame of the previous conflicting access. (#9501) 2017-05-12 20:28:28 -07:00
practicalswift
8a26719344 [gardening] Fix duplicate include. 2017-05-11 16:04:48 +02:00
John McCall
ab250848b4 Downgrade dynamic exclusivity failures to a warning in Swift 3 compatibility mode. 2017-05-10 14:44:59 -04:00
John McCall
e01c31a17c Remember a PC in the exclusivity-tracking set and report it during failures. 2017-05-10 14:44:56 -04:00
John McCall
2525710017 Make the exclusivity-set tracking a singly-linked list.
We'll use this space for something else in a follow-up.
2017-05-10 01:35:34 -04:00
Devin Coughlin
73aabd73f7 [Exclusivity] Fix insertion/remove in AccessSet in runtime.
And add some basic tests for trapping on accesses to globals.
2017-04-27 15:38:07 -07:00
John McCall
6c16cfaa14 Implement a basic dynamic-enforcement runtime and teach IRGen to use it. 2017-04-18 11:23:43 -04:00