Skip to content

Commit da9803d

Browse files
authored
Merge branch 'main' into problem/63410196
2 parents 779b10d + 286d22b commit da9803d

File tree

65 files changed

+1365
-364
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1365
-364
lines changed

CMakeLists.txt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,10 @@ set(SWIFT_TOOLS_ENABLE_LTO OFF CACHE STRING "Build Swift tools with LTO. One
191191
option only affects the tools that run on the host (the compiler), and has
192192
no effect on the target libraries (the standard library and the runtime).")
193193

194-
option(SWIFT_TOOLS_ENABLE_LIBSWIFT
195-
"Enable building libswift and linking libswift into the compiler itself."
196-
FALSE)
194+
# NOTE: We do not currently support building libswift with the Xcode generator.
195+
cmake_dependent_option(SWIFT_TOOLS_ENABLE_LIBSWIFT
196+
"Enable building libswift and linking libswift into the compiler itself." FALSE
197+
"NOT CMAKE_GENERATOR STREQUAL \"Xcode\"" FALSE)
197198

198199
# The following only works with the Ninja generator in CMake >= 3.0.
199200
set(SWIFT_PARALLEL_LINK_JOBS "" CACHE STRING
@@ -511,8 +512,6 @@ message(STATUS "C Compiler (${CMAKE_C_COMPILER}) Version: ${CMAKE_C_COMPILER_VER
511512
message(STATUS "C++ Compiler (${CMAKE_CXX_COMPILER}) Version: ${CMAKE_CXX_COMPILER_VERSION}")
512513
if (CMAKE_Swift_COMPILER)
513514
message(STATUS "Swift Compiler (${CMAKE_Swift_COMPILER}) Version: ${CMAKE_Swift_COMPILER_VERSION}")
514-
elseif (SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER)
515-
message(FATAL_ERROR "Swift Compiler not found and SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER is set")
516515
else()
517516
message(STATUS "Swift Compiler (None).")
518517
endif()
@@ -1060,9 +1059,7 @@ if(SWIFT_INCLUDE_TOOLS)
10601059
# which is used in add_swift_host_tool for the lldb workaround.
10611060
#
10621061
# NOTE: We do not currently support libswift with the Xcode generator.
1063-
if (NOT CMAKE_GENERATOR STREQUAL "Xcode")
1064-
add_subdirectory(libswift)
1065-
endif()
1062+
add_subdirectory(libswift)
10661063

10671064
# Always include this after including stdlib/!
10681065
# Refer to the large comment above the add_subdirectory(stdlib) call.

benchmark/single-source/ChaCha.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ func checkResult(_ plaintext: [UInt8]) {
361361
}
362362

363363
@inline(never)
364+
@_assemblyVision
364365
public func run_ChaCha(_ N: Int) {
365366
let key = Array(repeating: UInt8(1), count: 32)
366367
let nonce = Array(repeating: UInt8(2), count: 12)

docs/DebuggingTheCompiler.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ One of the first steps is an invocation of the driver's
922922
In order to create a Swift compiler installation (`--install-swift`), the
923923
standalone driver must be built as a separate build product using the
924924
*just-built* Swift compiler and toolchain (the ones built in the same
925-
`build-script` invocation, preceeding the SwiftDriver build product). The
925+
`build-script` invocation, preceding the SwiftDriver build product). The
926926
additional build product is added to the build by specifying the
927927
`--swift-driver` option of the `build-script`. The driver product is istalled
928928
into the resulting toolchain installation by specifying the

docs/HowToGuides/GettingStarted.md

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -151,35 +151,18 @@ Double-check that running `pwd` prints a path ending with `swift`.
151151
[Homebrew]: https://brew.sh/
152152
[Homebrew Bundle]: https://github.com/Homebrew/homebrew-bundle
153153
154-
### Ubuntu Linux
155-
156-
1. For Ubuntu 16.04 LTS and 18.04 LTS, run the following:
157-
158-
```sh
159-
sudo apt-get install \
160-
clang \
161-
cmake \
162-
git \
163-
icu-devtools \
164-
libcurl4-openssl-dev \
165-
libedit-dev \
166-
libicu-dev \
167-
libncurses5-dev \
168-
libpython3-dev \
169-
libsqlite3-dev \
170-
libxml2-dev \
171-
ninja-build \
172-
pkg-config \
173-
python \
174-
python-six \
175-
rsync \
176-
swig \
177-
systemtap-sdt-dev \
178-
tzdata \
179-
uuid-dev
154+
### Linux
155+
156+
1. The latest Linux dependencies are listed in the respective Dockerfiles:
157+
* [Ubuntu 20.04](https://github.com/apple/swift-docker/blob/main/swift-ci/master/ubuntu/20.04/Dockerfile)
158+
* [CentOS 7](https://github.com/apple/swift-docker/blob/main/swift-ci/master/centos/7/Dockerfile)
159+
* [CentOS 8](https://github.com/apple/swift-docker/blob/main/swift-ci/master/centos/8/Dockerfile)
160+
* [Amazon Linux 2](https://github.com/apple/swift-docker/blob/main/swift-ci/master/amazon-linux/2/Dockerfile)
161+
162+
2. To install sccache (optional):
163+
```
180164
sudo snap install sccache --candidate --classic
181165
```
182-
183166
**Note:** LLDB currently requires at least `swig-1.3.40` but will
184167
successfully build with version 2 shipped with Ubuntu.
185168

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4357,6 +4357,8 @@ ERROR(async_objc_dynamic_self,none,
43574357
ERROR(actor_inheritance,none,
43584358
"%select{actor|distributed actor}0 types do not support inheritance",
43594359
(bool))
4360+
NOTE(actor_inheritance_nsobject,none,
4361+
"use '@objc' to expose actor %0 to Objective-C", (DeclName))
43604362

43614363
ERROR(actor_protocol_illegal_inheritance,none,
43624364
"non-actor type %0 cannot conform to the 'Actor' protocol",

include/swift/DependencyScan/DependencyScanningTool.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class DependencyScanningTool {
3131
/// Construct a dependency scanning tool.
3232
DependencyScanningTool();
3333

34-
/// Collect the full module depenedency graph for the input, ignoring any
34+
/// Collect the full module dependency graph for the input, ignoring any
3535
/// placeholder modules.
3636
///
3737
/// \returns a \c StringError with the diagnostic output if errors
@@ -47,11 +47,11 @@ class DependencyScanningTool {
4747
llvm::ErrorOr<swiftscan_import_set_t>
4848
getImports(ArrayRef<const char *> Command);
4949

50-
/// Collect the full module depenedency graph for the input collection of
50+
/// Collect the full module dependency graph for the input collection of
5151
/// module names (batch inputs) and output them to the
5252
/// BatchScanInput-specified output locations.
5353
///
54-
/// \returns a \c std::error_code if errors occured during scan.
54+
/// \returns a \c std::error_code if errors occurred during scan.
5555
std::vector<llvm::ErrorOr<swiftscan_dependency_graph_t>>
5656
getDependencies(ArrayRef<const char *> Command,
5757
const std::vector<BatchScanInput> &BatchInput,

include/swift/Reflection/ReflectionContext.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,9 +1361,7 @@ class ReflectionContext
13611361
if (!AsyncTaskObj)
13621362
return std::string("failure reading async task");
13631363

1364-
auto *Allocator = reinterpret_cast<const StackAllocator *>(
1365-
&AsyncTaskObj->AllocatorPrivate);
1366-
StoredPointer SlabPtr = Allocator->FirstSlab;
1364+
StoredPointer SlabPtr = AsyncTaskObj->PrivateStorage.Allocator.FirstSlab;
13671365
while (SlabPtr) {
13681366
auto SlabBytes = getReader().readBytes(
13691367
RemoteAddress(SlabPtr), sizeof(typename StackAllocator::Slab));

include/swift/Reflection/RuntimeInternals.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ struct HeapObject {
6868

6969
template <typename Runtime>
7070
struct Job {
71-
typename Runtime::StoredPointer Opaque[4];
71+
HeapObject<Runtime> HeapObject;
72+
typename Runtime::StoredPointer SchedulerPrivate[2];
73+
uint32_t Flags;
74+
uint32_t Id;
75+
typename Runtime::StoredPointer Reserved[2];
76+
typename Runtime::StoredPointer RunJob;
7277
};
7378

7479
template <typename Runtime>
@@ -86,12 +91,19 @@ struct StackAllocator {
8691
};
8792

8893
template <typename Runtime>
89-
struct AsyncTask {
90-
HeapObject<Runtime> HeapObject;
91-
Job<Runtime> Job;
92-
typename Runtime::StoredPointer ResumeContext;
94+
struct AsyncTaskPrivateStorage {
9395
typename Runtime::StoredSize Status;
94-
typename Runtime::StoredPointer AllocatorPrivate[4];
96+
StackAllocator<Runtime> Allocator;
97+
typename Runtime::StoredPointer Local;
98+
};
99+
100+
template <typename Runtime>
101+
struct AsyncTask: Job<Runtime> {
102+
// On 64-bit, there's a Reserved64 after ResumeContext.
103+
typename Runtime::StoredPointer ResumeContextAndReserved[
104+
sizeof(typename Runtime::StoredPointer) == 8 ? 2 : 1];
105+
106+
AsyncTaskPrivateStorage<Runtime> PrivateStorage;
95107
};
96108

97109
} // end namespace reflection

include/swift/Runtime/ThreadLocal.h

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@
1818
#ifndef SWIFT_RUNTIME_THREADLOCAL_H
1919
#define SWIFT_RUNTIME_THREADLOCAL_H
2020

21+
#include <type_traits>
22+
#include "ThreadLocalStorage.h"
23+
2124
/// SWIFT_RUNTIME_SUPPORTS_THREAD_LOCAL - Does the current configuration
2225
/// allow the use of SWIFT_RUNTIME_ATTRIBUTE_THREAD_LOCAL?
23-
#if defined(SWIFT_STDLIB_SINGLE_THREADED_RUNTIME)
26+
#if defined(__APPLE__)
27+
// The pthread TLS APIs work better than C++ TLS on Apple platforms.
28+
#define SWIFT_RUNTIME_SUPPORTS_THREAD_LOCAL 0
29+
#elif defined(SWIFT_STDLIB_SINGLE_THREADED_RUNTIME)
2430
// We define SWIFT_RUNTIME_ATTRIBUTE_THREAD_LOCAL to nothing in this
2531
// configuration and just use a global variable, so this is okay.
2632
#define SWIFT_RUNTIME_SUPPORTS_THREAD_LOCAL 1
@@ -57,6 +63,17 @@
5763
#endif
5864

5965
namespace swift {
66+
// Validate a type stored in thread-local storage, using static asserts. Such
67+
// types must fit in a pointer and be trivially copyable/destructible.
68+
#define VALIDATE_THREAD_LOCAL_TYPE(T) \
69+
static_assert(sizeof(T) <= sizeof(void *), \
70+
"cannot store more than a pointer"); \
71+
static_assert(std::is_trivially_copyable<T>::value, \
72+
"ThreadLocal values must be trivially copyable"); \
73+
static_assert(std::is_trivially_destructible<T>::value, \
74+
"ThreadLocal cleanup is not supported, stored types must be " \
75+
"trivially destructible");
76+
6077
// A wrapper class for thread-local storage.
6178
//
6279
// - On platforms that report SWIFT_RUNTIME_SUPPORTS_THREAD_LOCAL
@@ -72,50 +89,70 @@ namespace swift {
7289
// - On platforms that don't report SWIFT_RUNTIME_SUPPORTS_THREAD_LOCAL,
7390
// we have to simulate thread-local storage. Fortunately, all of
7491
// these platforms (at least for now) support pthread_getspecific.
92+
#if SWIFT_RUNTIME_SUPPORTS_THREAD_LOCAL
7593
template <class T>
7694
class ThreadLocal {
77-
static_assert(sizeof(T) <= sizeof(void*), "cannot store more than a pointer");
95+
VALIDATE_THREAD_LOCAL_TYPE(T)
7896

79-
#if SWIFT_RUNTIME_SUPPORTS_THREAD_LOCAL
8097
T value;
98+
99+
public:
100+
constexpr ThreadLocal() {}
101+
102+
T get() { return value; }
103+
104+
void set(T newValue) { value = newValue; }
105+
};
81106
#else
107+
// A wrapper around a pthread_key_t that is lazily initialized using
108+
// dispatch_once.
109+
class ThreadLocalKey {
82110
// We rely on the zero-initialization of objects with static storage
83111
// duration.
84112
dispatch_once_t once;
85113
pthread_key_t key;
86114

115+
public:
87116
pthread_key_t getKey() {
88-
dispatch_once_f(&once, this, [](void *ctx) {
89-
pthread_key_create(&reinterpret_cast<ThreadLocal*>(ctx)->key, nullptr);
117+
dispatch_once_f(&once, &key, [](void *ctx) {
118+
pthread_key_create(reinterpret_cast<pthread_key_t *>(ctx), nullptr);
90119
});
91120
return key;
92121
}
93-
#endif
122+
};
123+
124+
// A type representing a constant pthread_key_t, for use on platforms that
125+
// provide reserved keys.
126+
template <pthread_key_t constantKey>
127+
class ConstantThreadLocalKey {
128+
public:
129+
pthread_key_t getKey() { return constantKey; }
130+
};
131+
132+
template <class T, class Key>
133+
class ThreadLocal {
134+
VALIDATE_THREAD_LOCAL_TYPE(T)
135+
136+
Key key;
94137

95138
public:
96139
constexpr ThreadLocal() {}
97140

98141
T get() {
99-
#if SWIFT_RUNTIME_SUPPORTS_THREAD_LOCAL
100-
return value;
101-
#else
102-
void *storedValue = pthread_getspecific(getKey());
142+
void *storedValue = SWIFT_THREAD_GETSPECIFIC(key.getKey());
103143
T value;
104144
memcpy(&value, &storedValue, sizeof(T));
105145
return value;
106-
#endif
107146
}
108147

109148
void set(T newValue) {
110-
#if SWIFT_RUNTIME_SUPPORTS_THREAD_LOCAL
111-
value = newValue;
112-
#else
113149
void *storedValue;
114150
memcpy(&storedValue, &newValue, sizeof(T));
115-
pthread_setspecific(getKey(), storedValue);
116-
#endif
151+
SWIFT_THREAD_SETSPECIFIC(key.getKey(), storedValue);
117152
}
118153
};
154+
#endif
155+
119156
} // end namespace swift
120157

121158
/// SWIFT_RUNTIME_DECLARE_THREAD_LOCAL(TYPE, NAME) - Declare a variable
@@ -124,13 +161,16 @@ class ThreadLocal {
124161
///
125162
/// Because of the fallback path, the default-initialization of the
126163
/// type must be equivalent to a bitwise zero-initialization, and the
127-
/// type must be small and trivially copyable.
164+
/// type must be small and trivially copyable and destructible.
128165
#if SWIFT_RUNTIME_SUPPORTS_THREAD_LOCAL
129-
#define SWIFT_RUNTIME_DECLARE_THREAD_LOCAL(TYPE, NAME) \
166+
#define SWIFT_RUNTIME_DECLARE_THREAD_LOCAL(TYPE, NAME, KEY) \
130167
SWIFT_RUNTIME_ATTRIBUTE_THREAD_LOCAL swift::ThreadLocal<TYPE> NAME
168+
#elif SWIFT_TLS_HAS_RESERVED_PTHREAD_SPECIFIC
169+
#define SWIFT_RUNTIME_DECLARE_THREAD_LOCAL(TYPE, NAME, KEY) \
170+
swift::ThreadLocal<TYPE, ConstantThreadLocalKey<KEY>> NAME
131171
#else
132-
#define SWIFT_RUNTIME_DECLARE_THREAD_LOCAL(TYPE, NAME) \
133-
swift::ThreadLocal<TYPE> NAME
172+
#define SWIFT_RUNTIME_DECLARE_THREAD_LOCAL(TYPE, NAME, KEY) \
173+
swift::ThreadLocal<TYPE, ThreadLocalKey> NAME
134174
#endif
135175

136176
#endif

stdlib/public/runtime/ThreadLocalStorage.h renamed to include/swift/Runtime/ThreadLocalStorage.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,33 @@ extern "C" int pthread_key_init_np(int key, void (*destructor)(void *));
4848
# ifndef __PTK_FRAMEWORK_SWIFT_KEY3
4949
# define __PTK_FRAMEWORK_SWIFT_KEY3 103
5050
# endif
51+
# ifndef __PTK_FRAMEWORK_SWIFT_KEY4
52+
# define __PTK_FRAMEWORK_SWIFT_KEY4 104
53+
# endif
54+
# ifndef __PTK_FRAMEWORK_SWIFT_KEY5
55+
# define __PTK_FRAMEWORK_SWIFT_KEY5 105
56+
# endif
57+
# ifndef __PTK_FRAMEWORK_SWIFT_KEY6
58+
# define __PTK_FRAMEWORK_SWIFT_KEY6 106
59+
# endif
60+
# ifndef __PTK_FRAMEWORK_SWIFT_KEY7
61+
# define __PTK_FRAMEWORK_SWIFT_KEY7 107
62+
# endif
63+
# ifndef __PTK_FRAMEWORK_SWIFT_KEY8
64+
# define __PTK_FRAMEWORK_SWIFT_KEY8 108
65+
# endif
66+
# ifndef __PTK_FRAMEWORK_SWIFT_KEY9
67+
# define __PTK_FRAMEWORK_SWIFT_KEY9 109
68+
# endif
5169

5270

5371
# define SWIFT_RUNTIME_TLS_KEY __PTK_FRAMEWORK_SWIFT_KEY0
5472
# define SWIFT_STDLIB_TLS_KEY __PTK_FRAMEWORK_SWIFT_KEY1
5573
# define SWIFT_COMPATIBILITY_50_TLS_KEY __PTK_FRAMEWORK_SWIFT_KEY2
5674
# define SWIFT_CONCURRENCY_TASK_KEY __PTK_FRAMEWORK_SWIFT_KEY3
75+
# define SWIFT_CONCURRENCY_EXECUTOR_TRACKING_INFO_KEY __PTK_FRAMEWORK_SWIFT_KEY4
76+
# define SWIFT_CONCURRENCY_FALLBACK_TASK_LOCAL_STORAGE_KEY \
77+
__PTK_FRAMEWORK_SWIFT_KEY5
5778

5879
#endif
5980

include/swift/SIL/OptimizationRemark.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ enum class SourceLocInferenceBehavior : unsigned {
153153
BackwardsThenForwards = BackwardScan | ForwardScan2nd,
154154
ForwardScanAlwaysInfer = ForwardScan | AlwaysInfer,
155155
BackwardScanAlwaysInfer = BackwardScan | AlwaysInfer,
156+
BackwardThenForwardAlwaysInfer = BackwardScan | ForwardScan2nd | AlwaysInfer,
156157
};
157158

158159
inline SourceLocInferenceBehavior operator&(SourceLocInferenceBehavior lhs,

0 commit comments

Comments
 (0)