Skip to content

Commit da1a8f7

Browse files
Merge pull request #4867 from swiftwasm/katei/merge-main-2022-09-09
Merge main 2022-09-09
2 parents e661e7d + 308fb64 commit da1a8f7

File tree

666 files changed

+15337
-9446
lines changed

Some content is hidden

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

666 files changed

+15337
-9446
lines changed

CHANGELOG.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,43 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
1616

1717
## Swift 5.7
1818

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+
1956
* The Swift compiler no longer warns about redundant requirements in generic declarations. For example,
2057
the following code diagnosed a warning in Swift 5.6 about the `T.Iterator : IteratorProtocol`
2158
requirement being redundant, because it is implied by `T : Sequence`:

CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,11 @@ if(CMAKE_C_COMPILER_ID MATCHES Clang)
628628
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Werror=c++98-compat-extra-semi>)
629629
endif()
630630

631+
# Make sure we know where swift-syntax is because we need it to build the parser.
632+
if(NOT EXISTS "${SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE}")
633+
message(SEND_ERROR "swift-syntax is required to build the Swift compiler. Please run update-checkout or specify SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE")
634+
endif()
635+
631636
# Use dispatch as the system scheduler by default.
632637
# For convenience, we set this to false when concurrency is disabled.
633638
set(SWIFT_CONCURRENCY_USES_DISPATCH FALSE)
@@ -755,7 +760,7 @@ elseif(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
755760
else()
756761
set(BOOTSTRAPPING_MODE "HOSTTOOLS")
757762
endif()
758-
elseif(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
763+
elseif(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" OR SWIFT_SWIFT_PARSER)
759764
# We are building using a pre-installed host toolchain but not bootstrapping
760765
# the Swift modules. This happens when building using 'build-tooling-libs'
761766
# where we haven't built a new Swift compiler. Use the Swift compiler from the
@@ -868,6 +873,13 @@ if(XCODE)
868873
set(SWIFT_SDKS "OSX")
869874
endif()
870875

876+
# When we have the early SwiftSyntax build, we can include its parser.
877+
if(SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR)
878+
set(SWIFT_SWIFT_PARSER TRUE)
879+
include(${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/cmake/SwiftSyntaxTargets.cmake)
880+
endif()
881+
882+
871883
# FIXME: the parameters we specify in SWIFT_SDKS are lacking architecture specifics,
872884
# so we need to hard-code it. For example, the SDK for Android is just 'ANDROID',
873885
# and we have to specify SWIFT_SDK_ANDROID_ARCHITECTURES separately.
@@ -1074,6 +1086,7 @@ if(SWIFT_INCLUDE_TOOLS)
10741086
message(STATUS " Assertions: ${LLVM_ENABLE_ASSERTIONS}")
10751087
message(STATUS " LTO: ${SWIFT_TOOLS_ENABLE_LTO}")
10761088
message(STATUS " Bootstrapping: ${BOOTSTRAPPING_MODE}")
1089+
message(STATUS " Swift parser: ${SWIFT_SWIFT_PARSER}")
10771090
message(STATUS "")
10781091
else()
10791092
message(STATUS "Not building host Swift tools")
@@ -1168,6 +1181,7 @@ endif()
11681181
if(SWIFT_BUILD_STDLIB)
11691182
add_subdirectory(stdlib)
11701183
else()
1184+
set(SWIFT_STDLIB_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/stdlib")
11711185
# Some of the things below depend on the threading library
11721186
add_subdirectory(stdlib/public/Threading)
11731187

SwiftCompilerSources/CMakeLists.txt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,21 @@ 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}
@@ -173,14 +188,7 @@ function(add_swift_compiler_modules_library name)
173188
"-emit-module-path" "${build_dir}/${module}.swiftmodule"
174189
"-parse-as-library" ${sources}
175190
"-wmo" ${swift_compile_options}
176-
# LLVM modules and headers.
177-
"-Xcc" "-I" "-Xcc" "${LLVM_MAIN_INCLUDE_DIR}"
178-
# Generated LLVM headers.
179-
"-Xcc" "-I" "-Xcc" "${LLVM_INCLUDE_DIR}"
180-
# Bridging modules and headers.
181-
"-Xcc" "-I" "-Xcc" "${SWIFT_SOURCE_DIR}/include"
182-
# Generated C headers.
183-
"-Xcc" "-I" "-Xcc" "${CMAKE_CURRENT_BINARY_DIR}/../include"
191+
${c_include_paths_args}
184192
# Generated swift modules.
185193
"-I" "${build_dir}"
186194
COMMENT "Building swift module ${module}")

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/Optimizer/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ add_subdirectory(Analysis)
1515
add_subdirectory(DataStructures)
1616
add_subdirectory(InstructionPasses)
1717
add_subdirectory(PassManager)
18+
add_subdirectory(ModulePasses)
1819
add_subdirectory(FunctionPasses)
1920
add_subdirectory(TestPasses)
2021
add_subdirectory(Utilities)

SwiftCompilerSources/Sources/Optimizer/DataStructures/FunctionUses.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,6 @@ struct FunctionUses {
109109
// The use-list head for each function.
110110
private var uses: [Function: FirstUse] = [:]
111111

112-
init() {
113-
// Already start with a reasonable big capacity to reduce the number of
114-
// re-allocations when appending to the data structures.
115-
useStorage.reserveCapacity(128)
116-
uses.reserveCapacity(64)
117-
}
118-
119112
/// Returns the use-list of `function`.
120113
///
121114
/// Note that `collect` must be called before `getUses` can be used.
@@ -125,7 +118,12 @@ struct FunctionUses {
125118

126119
/// Collects all uses of all function in the module.
127120
mutating func collect(context: ModulePassContext) {
128-
121+
122+
// Already start with a reasonable big capacity to reduce the number of
123+
// re-allocations when appending to the data structures.
124+
useStorage.reserveCapacity(128)
125+
uses.reserveCapacity(64)
126+
129127
// Mark all functions, which are referenced from tables, to have "unknown" uses.
130128

131129
for vTable in context.vTables {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
swift_compiler_sources(Optimizer
10+
StackProtection.swift
11+
)

0 commit comments

Comments
 (0)