Skip to content

Commit 9167a17

Browse files
authored
Merge branch 'main' into cal--implicit-weak-self
2 parents 778a2fc + 63fdef8 commit 9167a17

File tree

2,267 files changed

+76906
-30045
lines changed

Some content is hidden

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

2,267 files changed

+76906
-30045
lines changed

.dir-locals.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
(add-to-list 'load-path
1212
(concat this-directory "utils")
1313
:append)
14+
(defvar swift-project-directory)
1415
(let ((swift-project-directory this-directory))
1516
(require 'swift-project-settings)))
1617
(set (make-local-variable 'swift-project-directory)

.flake8

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ ignore =
5151
# compliant (https://github.com/psf/black#slices).
5252
E203,
5353

54-
# FIXME: We should not have trailing whitespace.
55-
W291,
56-
5754
# Line breaks before binary operators are not explicitly disallowed in
5855
# PEP8, rather it should be consistent throughout the project. The black
5956
# tool puts them on new lines which is to be considered a best practice

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Resolves SR-NNNN.
77
<!--
88
Before merging this pull request, you must run the Swift continuous integration tests.
99
For information about triggering CI builds via @swift-ci, see:
10-
https://github.com/apple/swift/blob/master/docs/ContinuousIntegration.md#swift-ci
10+
https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci
1111
1212
Thank you for your contribution to Swift!
1313
-->

CHANGELOG.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,56 @@ CHANGELOG
33

44
_**Note:** This is in reverse chronological order, so newer entries are added to the top._
55

6+
## Swift 5.8
7+
8+
* [SE-0362][]:
9+
10+
The compiler flag `-enable-upcoming-feature X` can now be used to enable a specific feature `X` that has been accepted by the evolution process, but whose introduction into the language is waiting for the next major version (e.g., version 6). The `X` is specified by any proposal that falls into this category:
11+
* `ConciseMagicFile` enables the new `#file` semantics in [SE-0274][].
12+
* `ForwardTrailingClosures` disables the "backward" scanning behavior of [SE-0286][].
13+
* `BareSlashRegexLiterals` enables the regex literal syntax of [SE-0354][].
14+
15+
Features can be detected in source code with `#if hasFeature(X)`.
16+
617
## Swift 5.7
718

19+
* [SE-0327][]:
20+
21+
There are a few notable changes in Swift 5.7 with respect to SE-0327.
22+
23+
First, the deinitializer and most kinds of initializers for `actor` types, and types constrained by a global actor like the `@MainActor`, have revised rules about what expressions are permitted in their body. The goal of these revisions has been to improve language expressivity and safety. In particular, many more programming patterns are now permitted in these initializers.
24+
25+
For example, a non-async initializer of an `actor` prior to Swift 5.7 would raise a diagnostic any time `self` escapes the initializer before returning. That diagnostic's purpose was to protect against a possible data race when accessing isolated stored proeprties. But, that diagnostic was emitted even if there was no dangerous racy access.
26+
27+
In Swift 5.7, the compiler now checks these initializers for dangerous accesses to isolated stored properties that occur after an escape of `self`:
28+
29+
```swift
30+
actor Database {
31+
// ... other properties ...
32+
var rows: Int = 0
33+
34+
init(_ world: DataUser) {
35+
defer {
36+
print("last = \(self.rows)") // ❌ this access to 'rows' is illegal.
37+
}
38+
39+
print("before = \(self.rows)") // ✅ this access to 'rows' is OK
40+
world.publishDatabase(self) // ✅ passing 'self' is OK in Swift 5.7+
41+
print("after = \(self.rows)") // ❌ this access to 'rows' is illegal.
42+
43+
Task { [weak self] in // ✅ capturing 'self' is OK in Swift 5.7+
44+
while let db = self { await db.prune() }
45+
}
46+
}
47+
}
48+
```
49+
50+
This is a control-flow sensitive check, meaning an illegal access does not necessarily appear on a source line after an escape of `self` (in the example above, consider _when_ the `defer` is executed). The compiler will always point out one of the escapes of `self` that is causing an access to become illegal.
51+
52+
Next, delegating initializers of an actor are no longer always non-isolated. This means an `async` delegating initializer can do the same things as a non-delegating one.
53+
54+
Finally, the diagnostic about non-isolated default-value expressions introduced for Swift 5.6 in the Xcode 13.3 release has been removed. The proposed rule was not precise enough to avoid flagging an innocuous yet common pattern in SwiftUI code involving `@StateObject` properties and `@MainActor`.
55+
856
* The Swift compiler no longer warns about redundant requirements in generic declarations. For example,
957
the following code diagnosed a warning in Swift 5.6 about the `T.Iterator : IteratorProtocol`
1058
requirement being redundant, because it is implied by `T : Sequence`:
@@ -9459,6 +9507,7 @@ Swift 1.0
94599507
[SE-0267]: <https://github.com/apple/swift-evolution/blob/main/proposals/0267-where-on-contextually-generic.md>
94609508
[SE-0268]: <https://github.com/apple/swift-evolution/blob/main/proposals/0268-didset-semantics.md>
94619509
[SE-0269]: <https://github.com/apple/swift-evolution/blob/main/proposals/0269-implicit-self-explicit-capture.md>
9510+
[SE-0274]: <https://github.com/apple/swift-evolution/blob/main/proposals/0274-magic-file.md>
94629511
[SE-0276]: <https://github.com/apple/swift-evolution/blob/main/proposals/0276-multi-pattern-catch-clauses.md>
94639512
[SE-0279]: <https://github.com/apple/swift-evolution/blob/main/proposals/0279-multiple-trailing-closures.md>
94649513
[SE-0280]: <https://github.com/apple/swift-evolution/blob/main/proposals/0280-enum-cases-as-protocol-witnesses.md>
@@ -9509,6 +9558,7 @@ Swift 1.0
95099558
[SE-0355]: <https://github.com/apple/swift-evolution/blob/main/proposals/0355-regex-syntax-run-time-construction.md>
95109559
[SE-0357]: <https://github.com/apple/swift-evolution/blob/main/proposals/0357-regex-string-processing-algorithms.md>
95119560
[SE-0358]: <https://github.com/apple/swift-evolution/blob/main/proposals/0358-primary-associated-types-in-stdlib.md>
9561+
[SE-0362]: <https://github.com/apple/swift-evolution/blob/main/proposals/0362-piecemeal-future-features.md>
95129562

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

CMakeLists.txt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,15 @@ set(SWIFT_DARWIN_DEPLOYMENT_VERSION_TVOS "9.0" CACHE STRING
454454
set(SWIFT_DARWIN_DEPLOYMENT_VERSION_WATCHOS "2.0" CACHE STRING
455455
"Minimum deployment target version for watchOS")
456456

457+
#
458+
# Compatibility library deployment versions
459+
#
460+
461+
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_OSX "10.9")
462+
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_IOS "7.0")
463+
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_TVOS "9.0")
464+
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_WATCHOS "2.0")
465+
457466
#
458467
# User-configurable debugging options.
459468
#
@@ -614,6 +623,11 @@ if(CMAKE_C_COMPILER_ID MATCHES Clang)
614623
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Werror=c++98-compat-extra-semi>)
615624
endif()
616625

626+
# Make sure we know where swift-syntax is because we need it to build the parser.
627+
if(NOT EXISTS "${SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE}")
628+
message(SEND_ERROR "swift-syntax is required to build the Swift compiler. Please run update-checkout or specify SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE")
629+
endif()
630+
617631
# Use dispatch as the system scheduler by default.
618632
# For convenience, we set this to false when concurrency is disabled.
619633
set(SWIFT_CONCURRENCY_USES_DISPATCH FALSE)
@@ -741,7 +755,7 @@ elseif(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
741755
else()
742756
set(BOOTSTRAPPING_MODE "HOSTTOOLS")
743757
endif()
744-
elseif(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
758+
elseif(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" OR SWIFT_SWIFT_PARSER)
745759
# We are building using a pre-installed host toolchain but not bootstrapping
746760
# the Swift modules. This happens when building using 'build-tooling-libs'
747761
# where we haven't built a new Swift compiler. Use the Swift compiler from the
@@ -854,6 +868,13 @@ if(XCODE)
854868
set(SWIFT_SDKS "OSX")
855869
endif()
856870

871+
# When we have the early SwiftSyntax build, we can include its parser.
872+
if(SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR)
873+
set(SWIFT_SWIFT_PARSER TRUE)
874+
include(${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/cmake/SwiftSyntaxTargets.cmake)
875+
endif()
876+
877+
857878
# FIXME: the parameters we specify in SWIFT_SDKS are lacking architecture specifics,
858879
# so we need to hard-code it. For example, the SDK for Android is just 'ANDROID',
859880
# and we have to specify SWIFT_SDK_ANDROID_ARCHITECTURES separately.
@@ -1060,6 +1081,7 @@ if(SWIFT_INCLUDE_TOOLS)
10601081
message(STATUS " Assertions: ${LLVM_ENABLE_ASSERTIONS}")
10611082
message(STATUS " LTO: ${SWIFT_TOOLS_ENABLE_LTO}")
10621083
message(STATUS " Bootstrapping: ${BOOTSTRAPPING_MODE}")
1084+
message(STATUS " Swift parser: ${SWIFT_SWIFT_PARSER}")
10631085
message(STATUS "")
10641086
else()
10651087
message(STATUS "Not building host Swift tools")
@@ -1154,6 +1176,7 @@ endif()
11541176
if(SWIFT_BUILD_STDLIB)
11551177
add_subdirectory(stdlib)
11561178
else()
1179+
set(SWIFT_STDLIB_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/stdlib")
11571180
# Some of the things below depend on the threading library
11581181
add_subdirectory(stdlib/public/Threading)
11591182

SwiftCompilerSources/CMakeLists.txt

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,26 +160,35 @@ function(add_swift_compiler_modules_library name)
160160
if (add_to_syntaxparse)
161161
set(syntaxparse_obj_files ${syntaxparse_obj_files} ${module_obj_file})
162162
endif()
163+
set(c_include_paths
164+
# LLVM modules and headers.
165+
"${LLVM_MAIN_INCLUDE_DIR}"
166+
# Generated LLVM headers.
167+
"${LLVM_INCLUDE_DIR}"
168+
# Clang modules and headers.
169+
${CLANG_INCLUDE_DIRS}
170+
# Bridging modules and headers.
171+
"${SWIFT_MAIN_INCLUDE_DIR}"
172+
# Generated C headers.
173+
"${CMAKE_CURRENT_BINARY_DIR}/../include")
174+
set(c_include_paths_args)
175+
foreach(c_include_path ${c_include_paths})
176+
list(APPEND c_include_paths_args "-Xcc" "-I" "-Xcc" "${c_include_path}")
177+
endforeach()
163178

164179
# Compile the module into an object file
165180
add_custom_command_target(dep_target OUTPUT ${module_obj_file}
166181
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
167182
DEPENDS ${sources} ${deps} ${ALS_DEPENDS}
183+
importedHeaderDependencies
168184
COMMAND ${ALS_SWIFT_EXEC} "-c" "-o" ${module_obj_file}
169185
${sdk_option}
170186
"-target" ${target}
171187
"-module-name" ${module} "-emit-module"
172188
"-emit-module-path" "${build_dir}/${module}.swiftmodule"
173189
"-parse-as-library" ${sources}
174190
"-wmo" ${swift_compile_options}
175-
# LLVM modules and headers.
176-
"-Xcc" "-I" "-Xcc" "${LLVM_MAIN_INCLUDE_DIR}"
177-
# Generated LLVM headers.
178-
"-Xcc" "-I" "-Xcc" "${LLVM_INCLUDE_DIR}"
179-
# Bridging modules and headers.
180-
"-Xcc" "-I" "-Xcc" "${SWIFT_SOURCE_DIR}/include"
181-
# Generated C headers.
182-
"-Xcc" "-I" "-Xcc" "${CMAKE_BINARY_DIR}/include"
191+
${c_include_paths_args}
183192
# Generated swift modules.
184193
"-I" "${build_dir}"
185194
COMMENT "Building swift module ${module}")
@@ -229,6 +238,34 @@ else()
229238

230239
add_subdirectory(Sources)
231240

241+
# TODO: generate this dynamically through the modulemap; this cannot use `sed`
242+
# as that is not available on all paltforms (e.g. Windows).
243+
#
244+
# step 1: generate a dummy source file, which just includes all headers
245+
# defined in include/swift/module.modulemap
246+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp"
247+
"
248+
#include \"Basic/BridgedSwiftObject.h\"
249+
#include \"Basic/BasicBridging.h\"
250+
#include \"Basic/SourceLoc.h\"
251+
252+
#include \"AST/ASTBridging.h\"
253+
#include \"AST/DiagnosticEngine.h\"
254+
#include \"AST/DiagnosticConsumer.h\"
255+
256+
#include \"SIL/SILBridging.h\"
257+
258+
#include \"SILOptimizer/OptimizerBridging.h\"
259+
260+
#include \"Parse/RegexParserBridging.h\"
261+
")
262+
263+
# step 2: build a library containing that source file. This library depends on all the included header files.
264+
# The swift modules can now depend on that target.
265+
# Note that this library is unused, i.e. not linked to anything.
266+
add_library(importedHeaderDependencies "${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp")
267+
target_include_directories(importedHeaderDependencies PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../include/swift")
268+
232269
if(${BOOTSTRAPPING_MODE} MATCHES "HOSTTOOLS|CROSSCOMPILE")
233270

234271
if (NOT SWIFT_EXEC_FOR_SWIFT_MODULES)
@@ -272,12 +309,13 @@ else()
272309
endif()
273310
endif()
274311
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS AND SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT)
275-
set(platform ${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR})
276-
set(compatibility_libs
277-
"swiftCompatibility50-${platform}"
278-
"swiftCompatibility51-${platform}"
279-
"swiftCompatibilityDynamicReplacements-${platform}")
280-
312+
# We cannot specify directly HostCompatibilityLibs
313+
# because ultimately is used to specify a dependency for a
314+
# custom target and, unlike `target_link_libraries`, such dependency
315+
# would be lost at the generation of the build system.
316+
get_property(compatibility_libs
317+
TARGET HostCompatibilityLibs
318+
PROPERTY INTERFACE_LINK_LIBRARIES)
281319
list(APPEND b0_deps ${compatibility_libs})
282320
list(APPEND b1_deps ${compatibility_libs})
283321
endif()

SwiftCompilerSources/Package.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ private extension Target {
2222
"-Xcc", "-I", "-Xcc", "../include",
2323
// LLVM modules and headers
2424
"-Xcc", "-I", "-Xcc", "../../llvm-project/llvm/include",
25+
// Clang modules and headers
26+
"-Xcc", "-I", "-Xcc", "../../llvm-project/clang/include",
2527
"-cross-module-optimization"
2628
]),
2729
]

SwiftCompilerSources/Sources/AST/DiagnosticEngine.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public protocol DiagnosticArgument {
2121
}
2222
extension String: DiagnosticArgument {
2323
public func _withBridgedDiagnosticArgument(_ fn: (swift.DiagnosticArgument) -> Void) {
24-
withBridgedStringRef { fn(swift.DiagnosticArgument(llvm.StringRef($0))) }
24+
_withStringRef { fn(swift.DiagnosticArgument($0)) }
2525
}
2626
}
2727
extension Int: DiagnosticArgument {
@@ -42,10 +42,10 @@ public struct DiagnosticFixIt {
4242
}
4343

4444
func withBridgedDiagnosticFixIt(_ fn: (swift.DiagnosticInfo.FixIt) -> Void) {
45-
text.withBridgedStringRef { bridgedTextRef in
45+
text._withStringRef { bridgedTextRef in
4646
let bridgedDiagnosticFixIt = swift.DiagnosticInfo.FixIt(
4747
swift.CharSourceRange(start.bridged, UInt32(byteLength)),
48-
llvm.StringRef(bridgedTextRef),
48+
bridgedTextRef,
4949
llvm.ArrayRef<swift.DiagnosticArgument>())
5050
fn(bridgedDiagnosticFixIt)
5151
}

SwiftCompilerSources/Sources/Basic/SourceLoc.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public struct SourceLoc {
2727
guard bridged.isValid() else {
2828
return nil
2929
}
30-
self.locationInFile = bridged.getOpaquePointerValue().assumingMemoryBound(to: UInt8.self)
30+
self.locationInFile = bridged.__getOpaquePointerValueUnsafe().assumingMemoryBound(to: UInt8.self)
3131
}
3232

3333
public var bridged: swift.SourceLoc {
@@ -57,7 +57,7 @@ public struct CharSourceRange {
5757
}
5858

5959
public init?(bridged: swift.CharSourceRange) {
60-
guard let start = SourceLoc(bridged: bridged.getStart()) else {
60+
guard let start = SourceLoc(bridged: bridged.__getStartUnsafe()) else {
6161
return nil
6262
}
6363
self.init(start: start, byteLength: bridged.getByteLength())

SwiftCompilerSources/Sources/Basic/Utils.swift

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@ import std
1818
//===----------------------------------------------------------------------===//
1919

2020
public struct StringRef : CustomStringConvertible, CustomReflectable {
21-
let _bridged : BridgedStringRef
21+
let _bridged: llvm.StringRef
2222

23-
public init(bridged: BridgedStringRef) { self._bridged = bridged }
23+
public init(bridged: llvm.StringRef) { self._bridged = bridged }
2424

2525
public var string: String { _bridged.string }
2626
public var description: String { string }
2727
public var customMirror: Mirror { Mirror(self, children: []) }
2828

2929
public static func ==(lhs: StringRef, rhs: StaticString) -> Bool {
30-
let lhsBuffer = UnsafeBufferPointer<UInt8>(start: lhs._bridged.data, count: Int(lhs._bridged.length))
30+
let lhsBuffer = UnsafeBufferPointer<UInt8>(
31+
start: lhs._bridged.__bytes_beginUnsafe(),
32+
count: Int(lhs._bridged.__bytes_endUnsafe() - lhs._bridged.__bytes_beginUnsafe()))
3133
return rhs.withUTF8Buffer { (rhsBuffer: UnsafeBufferPointer<UInt8>) in
3234
if lhsBuffer.count != rhsBuffer.count { return false }
3335
return lhsBuffer.elementsEqual(rhsBuffer, by: ==)
@@ -41,31 +43,26 @@ public struct StringRef : CustomStringConvertible, CustomReflectable {
4143
// Bridging Utilities
4244
//===----------------------------------------------------------------------===//
4345

44-
extension BridgedStringRef {
45-
public var string: String {
46-
let buffer = UnsafeBufferPointer<UInt8>(start: data, count: Int(length))
47-
return String(decoding: buffer, as: UTF8.self)
48-
}
49-
}
50-
5146
extension llvm.StringRef {
52-
public init(_ bridged: BridgedStringRef) {
53-
self.init(bridged.data, bridged.length)
47+
public var string: String {
48+
String(_cxxString: self.str())
5449
}
5550
}
5651

5752
extension String {
58-
public func withBridgedStringRef<T>(_ c: (BridgedStringRef) -> T) -> T {
53+
/// Underscored to avoid name collision with Swift LLVM Bindings.
54+
/// To be replaced with a bindings call once bindings are a dependency.
55+
public func _withStringRef<T>(_ c: (llvm.StringRef) -> T) -> T {
5956
var str = self
6057
return str.withUTF8 { buffer in
61-
return c(BridgedStringRef(data: buffer.baseAddress, length: buffer.count))
58+
return c(llvm.StringRef(buffer.baseAddress, buffer.count))
6259
}
6360
}
6461

6562
/// Underscored to avoid name collision with the std overlay.
6663
/// To be replaced with an overlay call once the CI uses SDKs built with Swift 5.8.
6764
public init(_cxxString s: std.string) {
68-
self.init(cString: s.c_str())
65+
self.init(cString: s.__c_strUnsafe())
6966
withExtendedLifetime(s) {}
7067
}
7168
}

0 commit comments

Comments
 (0)