Skip to content

Commit 52ec3d1

Browse files
authored
Merge branch 'main' into problem/63678072
2 parents d57cedd + bee879c commit 52ec3d1

File tree

327 files changed

+10527
-4890
lines changed

Some content is hidden

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

327 files changed

+10527
-4890
lines changed

CHANGELOG.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,47 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
66
Swift 5.5
77
---------
88

9+
* [SE-0316][]:
10+
11+
A type can be defined as a global actor. Global actors extend the notion
12+
of actor isolation outside of a single actor type, so that global state
13+
(and the functions that access it) can benefit from actor isolation,
14+
even if the state and functions are scattered across many different
15+
types, functions and modules. Global actors make it possible to safely
16+
work with global variables in a concurrent program, as well as modeling
17+
other global program constraints such as code that must only execute on
18+
the "main thread" or "UI thread". A new global actor can be defined with
19+
the `globalActor` attribute:
20+
21+
```swift
22+
@globalActor
23+
struct DatabaseActor {
24+
actor ActorType { }
25+
26+
static let shared: ActorType = ActorType()
27+
}
28+
```
29+
30+
Global actor types can be used as custom attributes on various declarations,
31+
which ensures that those declarations are only accessed on the actor described
32+
by the global actor's `shared` instance. For example:
33+
34+
```swift
35+
@DatabaseActor func queryDB(query: Query) throws -> QueryResult
36+
37+
func runQuery(queryString: String) async throws -> QueryResult {
38+
let query = try Query(parsing: queryString)
39+
return try await queryDB(query: query) // 'await' because this implicitly hops to DatabaseActor.shared
40+
}
41+
```
42+
43+
The concurrency library defines one global actor, `MainActor`, which
44+
represents the main thread of execution. It should be used for any code that
45+
must execute on the main thread, e.g., for updating UI.
46+
947
* [SE-0313][]:
1048

11-
Declarations inside an actor that would normally by actor-isolated can
49+
Declarations inside an actor that would normally be actor-isolated can
1250
explicitly become non-isolated using the `nonisolated` keyword. Non-isolated
1351
declarations can be used to conform to synchronous protocol requirements:
1452

@@ -8525,6 +8563,7 @@ Swift 1.0
85258563
[SE-0306]: <https://github.com/apple/swift-evolution/blob/main/proposals/0306-actors.md>
85268564
[SE-0310]: <https://github.com/apple/swift-evolution/blob/main/proposals/0310-effectful-readonly-properties.md>
85278565
[SE-0313]: <https://github.com/apple/swift-evolution/blob/main/proposals/0313-actor-isolation-control.md>
8566+
[SE-0316]: <https://github.com/apple/swift-evolution/blob/main/proposals/0316-global-actors.md>
85288567

85298568
[SR-75]: <https://bugs.swift.org/browse/SR-75>
85308569
[SR-106]: <https://bugs.swift.org/browse/SR-106>

CMakeLists.txt

Lines changed: 21 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
@@ -374,7 +375,7 @@ option(SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS
374375
"${SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS_default}")
375376

376377
option(SWIFT_STDLIB_SIL_DEBUGGING
377-
"Compile the Swift standard library with -gsil to enable debugging and profiling on SIL level"
378+
"Compile the Swift standard library with -sil-based-debuginfo to enable debugging and profiling on SIL level"
378379
FALSE)
379380

380381
option(SWIFT_CHECK_INCREMENTAL_COMPILATION
@@ -480,7 +481,9 @@ endif()
480481

481482
set(SWIFT_BUILD_HOST_DISPATCH FALSE)
482483
if(SWIFT_ENABLE_DISPATCH AND NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
483-
if(SWIFT_BUILD_SYNTAXPARSERLIB OR SWIFT_BUILD_SOURCEKIT)
484+
# Only build libdispatch for the host if the host tools are being built and
485+
# specifically if these two libraries that depend on it are built.
486+
if(SWIFT_INCLUDE_TOOLS AND (SWIFT_BUILD_SYNTAXPARSERLIB OR SWIFT_BUILD_SOURCEKIT))
484487
set(SWIFT_BUILD_HOST_DISPATCH TRUE)
485488
endif()
486489

@@ -507,6 +510,11 @@ execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} --version
507510
message(STATUS "CMake Make Program (${CMAKE_MAKE_PROGRAM}) Version: ${_CMAKE_MAKE_PROGRAM_VERSION}")
508511
message(STATUS "C Compiler (${CMAKE_C_COMPILER}) Version: ${CMAKE_C_COMPILER_VERSION}")
509512
message(STATUS "C++ Compiler (${CMAKE_CXX_COMPILER}) Version: ${CMAKE_CXX_COMPILER_VERSION}")
513+
if (CMAKE_Swift_COMPILER)
514+
message(STATUS "Swift Compiler (${CMAKE_Swift_COMPILER}) Version: ${CMAKE_Swift_COMPILER_VERSION}")
515+
else()
516+
message(STATUS "Swift Compiler (None).")
517+
endif()
510518
if(SWIFT_PATH_TO_CMARK_BUILD)
511519
execute_process(COMMAND ${SWIFT_PATH_TO_CMARK_BUILD}/src/cmark --version
512520
OUTPUT_VARIABLE _CMARK_VERSION
@@ -523,6 +531,13 @@ else()
523531
set(SWIFT_PREBUILT_CLANG TRUE)
524532
endif()
525533

534+
# Also mark if we have a prebuilt swift before we do anything.
535+
if("${SWIFT_NATIVE_SWIFT_TOOLS_PATH}" STREQUAL "")
536+
set(SWIFT_PREBUILT_SWIFT FALSE)
537+
else()
538+
set(SWIFT_PREBUILT_SWIFT TRUE)
539+
endif()
540+
526541
include(SwiftSharedCMakeConfig)
527542

528543
# NOTE: We include this before SwiftComponents as it relies on some LLVM CMake
@@ -1044,9 +1059,7 @@ if(SWIFT_INCLUDE_TOOLS)
10441059
# which is used in add_swift_host_tool for the lldb workaround.
10451060
#
10461061
# NOTE: We do not currently support libswift with the Xcode generator.
1047-
if (NOT CMAKE_GENERATOR STREQUAL "Xcode")
1048-
add_subdirectory(libswift)
1049-
endif()
1062+
add_subdirectory(libswift)
10501063

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

benchmark/scripts/test_Benchmark_Driver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ def test_filters_benchmarks_by_pattern(self):
264264
self.assertEqual(driver.tests, ["Benchmark3"])
265265
self.assertEqual(driver.all_tests, ["Benchmark1", "Benchmark2", "Benchmark3"])
266266

267+
@unittest.skip("comparing against localtime() is flaky. rdar://79701124")
267268
def test_log_file(self):
268269
"""When swift-repo is set, log is tied to Git branch and revision."""
269270
self.assertIsNone(

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)

cmake/modules/AddSwift.cmake

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -600,13 +600,22 @@ function(add_swift_host_library name)
600600
# find all of the necessary swift libraries on Darwin.
601601
if (NOT ASHL_PURE_SWIFT)
602602
if (CMAKE_Swift_COMPILER)
603-
# Add in the SDK directory for the host platform and add an rpath.
604-
target_link_directories(${name} PRIVATE
605-
${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}/usr/lib/swift)
606603
# Add in the toolchain directory so we can grab compatibility libraries
607604
get_filename_component(TOOLCHAIN_BIN_DIR ${CMAKE_Swift_COMPILER} DIRECTORY)
608605
get_filename_component(TOOLCHAIN_LIB_DIR "${TOOLCHAIN_BIN_DIR}/../lib/swift/macosx" ABSOLUTE)
609606
target_link_directories(${name} PUBLIC ${TOOLCHAIN_LIB_DIR})
607+
608+
# Add in the SDK directory for the host platform.
609+
#
610+
# NOTE: We do this /after/ target_link_directorying TOOLCHAIN_LIB_DIR to
611+
# ensure that we first find libraries from the toolchain, rather than
612+
# from the SDK. The reason why this is important is that when we perform
613+
# a stage2 build, this path is into the stage1 build. This is not a pure
614+
# SDK and also contains compatibility libraries. We need to make sure
615+
# that the compiler sees the actual toolchain's compatibility libraries
616+
# first before the just built compability libraries or build errors occur.
617+
target_link_directories(${name} PRIVATE
618+
${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}/usr/lib/swift)
610619
endif()
611620
endif()
612621
@@ -808,14 +817,23 @@ function(add_swift_host_tool executable)
808817
# host side tools but link with clang, add the appropriate -L paths so we
809818
# find all of the necessary swift libraries on Darwin.
810819
if (CMAKE_Swift_COMPILER)
811-
# Add in the SDK directory for the host platform and add an rpath.
812-
target_link_directories(${executable} PRIVATE
813-
${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}/usr/lib/swift)
814820
# Add in the toolchain directory so we can grab compatibility libraries
815821
get_filename_component(TOOLCHAIN_BIN_DIR ${CMAKE_Swift_COMPILER} DIRECTORY)
816822
get_filename_component(TOOLCHAIN_LIB_DIR "${TOOLCHAIN_BIN_DIR}/../lib/swift/macosx" ABSOLUTE)
817823
target_link_directories(${executable} PUBLIC ${TOOLCHAIN_LIB_DIR})
818824
825+
# Add in the SDK directory for the host platform and add an rpath.
826+
#
827+
# NOTE: We do this /after/ target_link_directorying TOOLCHAIN_LIB_DIR to
828+
# ensure that we first find libraries from the toolchain, rather than from
829+
# the SDK. The reason why this is important is that when we perform a
830+
# stage2 build, this path is into the stage1 build. This is not a pure SDK
831+
# and also contains compatibility libraries. We need to make sure that the
832+
# compiler sees the actual toolchain's compatibility libraries first
833+
# before the just built compability libraries or build errors occur.
834+
target_link_directories(${executable} PRIVATE
835+
${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}/usr/lib/swift)
836+
819837
if (ASHT_HAS_LIBSWIFT AND SWIFT_TOOLS_ENABLE_LIBSWIFT)
820838
# Workaround to make lldb happy: we have to explicitly add all libswift modules
821839
# to the linker command line.
@@ -917,7 +935,9 @@ function(add_swift_fuzzer_host_tool executable)
917935
918936
# Then make sure that we pass the -fsanitize=fuzzer flag both on the cflags
919937
# and cxx flags line.
920-
target_compile_options(${executable} PRIVATE $<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:"-fsanitize=fuzzer">)
938+
target_compile_options(${executable} PRIVATE
939+
$<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:-fsanitize=fuzzer>
940+
$<$<COMPILE_LANGUAGE:Swift>:-sanitize=fuzzer>)
921941
target_link_libraries(${executable} PRIVATE "-fsanitize=fuzzer")
922942
endfunction()
923943

docs/DebuggingTheCompiler.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ benefit of all Swift developers.
2525
- [Getting CommandLine for swift stdlib from Ninja to enable dumping stdlib SIL](#getting-commandline-for-swift-stdlib-from-ninja-to-enable-dumping-stdlib-sil)
2626
- [Dumping the SIL and other Data in LLDB](#dumping-the-sil-and-other-data-in-lldb)
2727
- [Debugging and Profiling on SIL level](#debugging-and-profiling-on-sil-level)
28-
- [SIL source level profiling using -gsil](#sil-source-level-profiling-using--gsil)
28+
- [SIL source level profiling using -sil-based-debuginfo](#sil-source-level-profiling)
2929
- [ViewCFG: Regex based CFG Printer for SIL/LLVM-IR](#viewcfg-regex-based-cfg-printer-for-silllvm-ir)
3030
- [Debugging the Compiler using advanced LLDB Breakpoints](#debugging-the-compiler-using-advanced-lldb-breakpoints)
3131
- [Debugging the Compiler using LLDB Scripts](#debugging-the-compiler-using-lldb-scripts)
@@ -101,6 +101,12 @@ swiftc -emit-sil -Onone file.swift
101101
swiftc -emit-sil -O file.swift
102102
```
103103

104+
* **Debug info in SIL** To print debug info from `file.swift` in SIL:
105+
106+
```sh
107+
swiftc -g -emit-sil -O file.swift
108+
```
109+
104110
* **IRGen** To print the LLVM IR after IR generation:
105111

106112
```sh
@@ -299,12 +305,13 @@ has a `dump()` method you can call.
299305

300306
## Debugging and Profiling on SIL level
301307

302-
### SIL source level profiling using -gsil
308+
### SIL source level profiling
303309

304310
The compiler provides a way to debug and profile on SIL level. To enable SIL
305-
debugging add the front-end option -gsil together with -g. Example:
311+
debugging add the front-end option -sil-based-debuginfo together with -g.
312+
Example:
306313

307-
swiftc -g -Xfrontend -gsil -O test.swift -o a.out
314+
swiftc -g -Xfrontend -sil-based-debuginfo -O test.swift -o a.out
308315

309316
This writes the SIL after optimizations into a file and generates debug info
310317
for it. In the debugger and profiler you can then see the SIL code instead of
@@ -915,7 +922,7 @@ One of the first steps is an invocation of the driver's
915922
In order to create a Swift compiler installation (`--install-swift`), the
916923
standalone driver must be built as a separate build product using the
917924
*just-built* Swift compiler and toolchain (the ones built in the same
918-
`build-script` invocation, preceeding the SwiftDriver build product). The
925+
`build-script` invocation, preceding the SwiftDriver build product). The
919926
additional build product is added to the build by specifying the
920927
`--swift-driver` option of the `build-script`. The driver product is istalled
921928
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/ABI/ObjectFile.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SwiftObjectFileFormat {
3131
};
3232

3333
/// Responsible for providing the Mach-O reflection section identifiers.
34-
class SwiftObjectFileFormatMachO : SwiftObjectFileFormat {
34+
class SwiftObjectFileFormatMachO : public SwiftObjectFileFormat {
3535
public:
3636
llvm::StringRef getSectionName(ReflectionSectionKind section) override {
3737
switch (section) {
@@ -53,7 +53,7 @@ class SwiftObjectFileFormatMachO : SwiftObjectFileFormat {
5353
};
5454

5555
/// Responsible for providing the ELF reflection section identifiers.
56-
class SwiftObjectFileFormatELF : SwiftObjectFileFormat {
56+
class SwiftObjectFileFormatELF : public SwiftObjectFileFormat {
5757
public:
5858
llvm::StringRef getSectionName(ReflectionSectionKind section) override {
5959
switch (section) {
@@ -75,7 +75,7 @@ class SwiftObjectFileFormatELF : SwiftObjectFileFormat {
7575
};
7676

7777
/// Responsible for providing the COFF reflection section identifiers
78-
class SwiftObjectFileFormatCOFF : SwiftObjectFileFormat {
78+
class SwiftObjectFileFormatCOFF : public SwiftObjectFileFormat {
7979
public:
8080
llvm::StringRef getSectionName(ReflectionSectionKind section) override {
8181
switch (section) {

include/swift/ABI/TaskLocal.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ class TaskLocal {
6969
// Trailing storage for the value itself. The storage will be
7070
// uninitialized or contain an instance of \c valueType.
7171

72+
/// Returns true if this item is a 'parent pointer'.
73+
///
74+
/// A parent pointer is special kind of `Item` is created when pointing at
75+
/// the parent storage, forming a chain of task local items spanning multiple
76+
/// tasks.
77+
bool isParentPointer() const {
78+
return !valueType;
79+
}
80+
7281
protected:
7382
explicit Item()
7483
: next(0),
@@ -174,7 +183,7 @@ class TaskLocal {
174183
/// returns, as such, any child tasks potentially accessing the value stack
175184
/// are guaranteed to be completed by the time we pop values off the stack
176185
/// (after the body has completed).
177-
TaskLocal::Item *head;
186+
TaskLocal::Item *head = nullptr;
178187

179188
public:
180189

include/swift/AST/ASTContext.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,10 @@ class ASTContext final {
744744
/// Get the runtime availability of support for differentiation.
745745
AvailabilityContext getDifferentiationAvailability();
746746

747+
/// Get the runtime availability of getters and setters of multi payload enum
748+
/// tag single payloads.
749+
AvailabilityContext getMultiPayloadEnumTagSinglePayload();
750+
747751
/// Get the runtime availability of features introduced in the Swift 5.2
748752
/// compiler for the target platform.
749753
AvailabilityContext getSwift52Availability();
@@ -760,6 +764,10 @@ class ASTContext final {
760764
/// compiler for the target platform.
761765
AvailabilityContext getSwift55Availability();
762766

767+
/// Get the runtime availability of features introduced in the Swift 5.6
768+
/// compiler for the target platform.
769+
AvailabilityContext getSwift56Availability();
770+
763771
/// Get the runtime availability of features that have been introduced in the
764772
/// Swift compiler for future versions of the target platform.
765773
AvailabilityContext getSwiftFutureAvailability();

include/swift/AST/Attr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(isolated, Isolated,
581581
103)
582582

583583
SIMPLE_DECL_ATTR(globalActor, GlobalActor,
584-
OnClass | OnStruct | OnEnum | ConcurrencyOnly |
584+
OnClass | OnStruct | OnEnum |
585585
ABIStableToAdd | ABIBreakingToRemove |
586586
APIStableToAdd | APIBreakingToRemove,
587587
104)

0 commit comments

Comments
 (0)