Skip to content

Commit 7bc5e93

Browse files
authored
Merge branch 'main' into disable-property-wrapper-based-isolation
2 parents 3e2d614 + bd11fce commit 7bc5e93

File tree

2,817 files changed

+104366
-40900
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,817 files changed

+104366
-40900
lines changed

.github/CODEOWNERS

+9
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
/include/swift/PrintAsClang @zoecarver @hyp @egorzhdan
7070
# TODO: /include/swift/SIL/
7171
# TODO: /include/swift/SILOptimizer/
72+
/include/swift/SIL/*Coverage* @hamishknight
73+
/include/swift/SIL/SILProfiler.h @hamishknight
7274
/include/swift/SIL/SILDebug* @adrian-prantl
7375
/include/swift/SILOptimizer/Utils/Distributed* @ktoso
7476
/include/swift/Sema/ @hborla @slavapestov @xedin
@@ -94,23 +96,28 @@
9496
/lib/ClangImporter/DWARFImporter* @adrian-prantl
9597
/lib/DependencyScan @artemcm
9698
/lib/Driver @artemcm
99+
/lib/DriverTool/autolink_extract_main.cpp @MaxDesiatov @etcwilde
97100
/lib/DriverTool/swift_symbolgraph_extract_main.cpp @QuietMisdreavus
98101
/lib/Frontend/*ModuleInterface* @artemcm @tshortli
99102
# TODO: /lib/IRGen/
100103
/lib/IDE/ @ahoppen @bnbarham @rintaro
101104
/lib/IDETool/ @ahoppen @bnbarham @rintaro
102105
/lib/Index/ @bnbarham
103106
/lib/Refactoring/ @ahoppen @bnbarham
107+
/lib/IRGen/*Coverage* @hamishknight
104108
/lib/IRGen/*Debug* @adrian-prantl
105109
/lib/IRGen/*Distributed* @ktoso
106110
/lib/Parse/ @ahoppen @bnbarham @CodaFi @DougGregor @rintaro
107111
/lib/PrintAsClang @zoecarver @hyp @egorzhdan
108112
# TODO: /lib/SIL/
113+
/lib/SIL/IR/*Coverage* @hamishknight
114+
/lib/SIL/IR/SILProfiler.cpp @hamishknight
109115
/lib/SIL/IR/SILDebug* @adrian-prantl
110116
/lib/SIL/IR/SILLocation* @adrian-prantl
111117
# TODO: /lib/SILGen/
112118
/lib/SILGen/*Distributed* @ktoso
113119
# TODO: /lib/SILOptimizer/
120+
/lib/SILOptimizer/Mandatory/FlowIsolation.cpp @kavon
114121
/lib/SILOptimizer/Utils/Distributed* @ktoso
115122
/lib/Sema/ @hborla @slavapestov @xedin
116123
/lib/Sema/*Availability* @tshortli
@@ -143,6 +150,7 @@
143150
/test/DebugInfo/ @adrian-prantl
144151
/test/Distributed/ @ktoso
145152
/test/Driver/ @artemcm
153+
/test/Driver/static* @MaxDesiatov @etcwilde
146154
/test/Generics/ @hborla @slavapestov
147155
# TODO: /test/IRGen/
148156
/test/IDE/ @ahoppen @bnbarham @rintaro
@@ -151,6 +159,7 @@
151159
/test/SourceKit/ @ahoppen @bnbarham @rintaro
152160
/test/Interop/ @zoecarver @hyp @egorzhdan
153161
/test/Parse/ @ahoppen @bnbarham @CodaFi @DougGregor @rintaro
162+
/test/Profiler @hamishknight
154163
# TODO: /test/SIL/
155164
# TODO: /test/SILGen/
156165
# TODO: /test/SILOptimizer/

CHANGELOG.md

+102-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,102 @@
55
66
## Swift 5.9
77

8+
* [SE-0382][], [SE-0389][], [SE-0394][], [SE-0397][]:
9+
10+
Swift 5.9 includes a new macro system that can be used to eliminate boilerplate and provide new forms of expressive APIs. Macros are declared with the new `macro` introducer:
11+
12+
```swift
13+
@freestanding(expression)
14+
macro assert(_ condition: Bool) = #externalMacro(module: "PowerAssertMacros", type: "AssertMacro")
15+
```
16+
17+
Macros have parameter and result types, like functions, but are defined as separate programs that operate on syntax trees (using [swift-syntax][]) and produce new syntax trees that are incorporated into the program. Freestanding macros, indicated with the `@freestanding` attribute, are expanded in source code with a leading `#`:
18+
19+
```swift
20+
#assert(x + y == z) // expands to check the result of x + y == z and report failure if it's false
21+
```
22+
23+
Macros can also be marked as `@attached`, in which case they will be meaning that they will be expanded using custom attribute syntax. For example:
24+
25+
```swift
26+
@attached(peer, names: overloaded)
27+
macro AddCompletionHandler() = #externalMacro(
28+
module: "ConcurrencyHelperMacros",
29+
type: "AddCompletionHandlerMacro"
30+
)
31+
32+
@AddCompletionHandler
33+
func fetchAvatar(from url: URL) throws -> Image { ... }
34+
35+
// expands to...
36+
func fetchAvatar(from url: URL, completionHandler: @escaping (Result<Image, Error>) -> Void) {
37+
Task.detached {
38+
do {
39+
let result = try await fetchAvatar(from: url)
40+
completionHandler(.success(result))
41+
} catch {
42+
completionHandler(.failure(error))
43+
}
44+
}
45+
}
46+
```
47+
48+
Macros are implemented in separate programs, which are executed by the Swift compiler. The Swift Package Manager's manifest provides a new `macro` target type to describe macros:
49+
50+
```swift
51+
import PackageDescription
52+
import CompilerPluginSupport
53+
54+
let package = Package(
55+
name: "ConcurrencyHelpers",
56+
dependencies: [
57+
.package(url: "https://github.com/apple/swift-syntax", from: "509.0.0"),
58+
],
59+
targets: [
60+
.macro(name: "ConcurrencyHelperMacros",
61+
dependencies: [
62+
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
63+
.product(name: "SwiftCompilerPlugin", package: "swift-syntax")
64+
]),
65+
.target(name: "ConcurrencyHelpers", dependencies: ["ConcurrencyHelperMacros"]),
66+
.testTarget(name: "ConcurrencyHelperMacroTests", dependencies: ["ConcurrencyHelperMacros"]),
67+
]
68+
)
69+
```
70+
71+
* [SE-0380][]:
72+
73+
`if` and `switch` statements may now be used as expressions to:
74+
75+
* Return values from functions, properties, and closures (either with
76+
implicit or explicit `return`)
77+
* Throw errors using `throw`
78+
* Assign values to variables
79+
* Declare variables
80+
81+
Each branch of the `if` or `switch` must be a single expression, the value
82+
of which becomes the value of the overall expression when that branch is
83+
chosen.
84+
85+
```swift
86+
let bullet =
87+
if isRoot && (count == 0 || !willExpand) { "" }
88+
else if count == 0 { "- " }
89+
else if maxDepth <= 0 { "" }
90+
else { "" }
91+
```
92+
93+
```swift
94+
public static func width(_ x: Unicode.Scalar) -> Int {
95+
switch x.value {
96+
case 0..<0x80: 1
97+
case 0x80..<0x0800: 2
98+
case 0x0800..<0x1_0000: 3
99+
default: 4
100+
}
101+
}
102+
```
103+
8104
* [#64927][]:
9105

10106
Swift 5.9 introduces warnings that catch conversions from an inout
@@ -9732,7 +9828,11 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
97329828
[SE-0370]: <https://github.com/apple/swift-evolution/blob/main/proposals/0370-pointer-family-initialization-improvements.md>
97339829
[SE-0376]: <https://github.com/apple/swift-evolution/blob/main/proposals/0376-function-back-deployment.md>
97349830
[SE-0377]: <https://github.com/apple/swift-evolution/blob/main/proposals/0377-parameter-ownership-modifiers.md>
9735-
9831+
[SE-0380]: <https://github.com/apple/swift-evolution/blob/main/proposals/0380-if-switch-expressions.md>
9832+
[SE-0382]: https://github.com/apple/swift-evolution/blob/main/proposals/0382-expression-macros.md
9833+
[SE-0389]: https://github.com/apple/swift-evolution/blob/main/proposals/0389-attached-macros.md
9834+
[SE-0394]: https://github.com/apple/swift-evolution/blob/main/proposals/0394-swiftpm-expression-macros.md
9835+
[SE-0397]: https://github.com/apple/swift-evolution/blob/main/proposals/0397-freestanding-declaration-macros.md
97369836
[#64927]: <https://github.com/apple/swift/issues/64927>
97379837
[#42697]: <https://github.com/apple/swift/issues/42697>
97389838
[#42728]: <https://github.com/apple/swift/issues/42728>
@@ -9774,3 +9874,4 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
97749874
[#57081]: <https://github.com/apple/swift/issues/57081>
97759875
[#57225]: <https://github.com/apple/swift/issues/57225>
97769876
[#56139]: <https://github.com/apple/swift/issues/56139>
9877+
[swift-syntax]: https://github.com/apple/swift-syntax

CMakeLists.txt

+19-9
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,10 @@ option(SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP
609609
"Enable experimental C++ interop modules"
610610
FALSE)
611611

612+
option(SWIFT_ENABLE_CXX_INTEROP_SWIFT_BRIDGING_HEADER
613+
"Install the <swift/bridging> C++ interoperability header alongside compiler"
614+
TRUE)
615+
612616
option(SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED
613617
"Enable experimental distributed actors and functions"
614618
FALSE)
@@ -642,6 +646,11 @@ option(SWIFT_THREADING_PACKAGE
642646
Valid package names are 'pthreads', 'darwin', 'linux', 'win32', 'c11', 'none'
643647
or the empty string for the SDK default.")
644648

649+
option(SWIFT_THREADING_HAS_DLSYM
650+
"Enable the use of the dlsym() function. This gets used to provide TSan
651+
support on some platforms."
652+
TRUE)
653+
645654
option(SWIFT_ENABLE_MACCATALYST
646655
"Build the Standard Library and overlays with MacCatalyst support"
647656
FALSE)
@@ -687,13 +696,6 @@ if(NOT EXISTS "${SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE}")
687696
message(SEND_ERROR "swift-syntax is required to build the Swift compiler. Please run update-checkout or specify SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE")
688697
endif()
689698

690-
# Use dispatch as the system scheduler by default.
691-
# For convenience, we set this to false when concurrency is disabled.
692-
set(SWIFT_CONCURRENCY_USES_DISPATCH FALSE)
693-
if(SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY AND "${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "dispatch")
694-
set(SWIFT_CONCURRENCY_USES_DISPATCH TRUE)
695-
endif()
696-
697699
set(SWIFT_BUILD_HOST_DISPATCH FALSE)
698700
if(SWIFT_ENABLE_DISPATCH AND NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
699701
# Only build libdispatch for the host if the host tools are being built and
@@ -702,9 +704,9 @@ if(SWIFT_ENABLE_DISPATCH AND NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
702704
set(SWIFT_BUILD_HOST_DISPATCH TRUE)
703705
endif()
704706

705-
if(SWIFT_BUILD_HOST_DISPATCH OR SWIFT_CONCURRENCY_USES_DISPATCH)
707+
if(SWIFT_BUILD_HOST_DISPATCH)
706708
if(NOT EXISTS "${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}")
707-
message(SEND_ERROR "SourceKit and concurrency require libdispatch on non-Darwin hosts. Please specify SWIFT_PATH_TO_LIBDISPATCH_SOURCE")
709+
message(SEND_ERROR "SourceKit requires libdispatch on non-Darwin hosts. Please specify SWIFT_PATH_TO_LIBDISPATCH_SOURCE")
708710
endif()
709711
endif()
710712
endif()
@@ -1046,6 +1048,14 @@ elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "ANDROID")
10461048
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
10471049
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
10481050

1051+
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WASI")
1052+
set(SWIFT_HOST_VARIANT "wasi" CACHE STRING
1053+
"Deployment OS for Swift host tools (the compiler) [wasi]")
1054+
1055+
configure_sdk_unix("WASI" "wasm32")
1056+
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
1057+
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
1058+
10491059
elseif("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)")
10501060

10511061
set(SWIFT_HOST_VARIANT "macosx" CACHE STRING

SwiftCompilerSources/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ function(add_swift_compiler_modules_library name)
8787
list(APPEND swift_compile_options "-O" "-cross-module-optimization")
8888
endif()
8989

90+
if(NOT LLVM_ENABLE_ASSERTIONS)
91+
list(APPEND swift_compile_options "-Xcc" "-DNDEBUG")
92+
endif()
93+
9094
if(NOT SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT)
9195
list(APPEND swift_compile_options "-Xfrontend" "-disable-legacy-type-info")
9296
endif()
@@ -227,7 +231,7 @@ else()
227231
add_subdirectory(Sources)
228232

229233
# TODO: generate this dynamically through the modulemap; this cannot use `sed`
230-
# as that is not available on all paltforms (e.g. Windows).
234+
# as that is not available on all platforms (e.g. Windows).
231235
#
232236
# step 1: generate a dummy source file, which just includes all headers
233237
# defined in include/swift/module.modulemap

SwiftCompilerSources/Sources/Basic/Utils.swift

+12-2
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,21 @@ public struct StringRef : CustomStringConvertible, NoReflectionChildren {
6464

6565
public var string: String { _bridged.string }
6666
public var description: String { string }
67-
67+
68+
public var count: Int {
69+
Int(_bridged.__bytes_endUnsafe() - _bridged.__bytes_beginUnsafe())
70+
}
71+
72+
public subscript(index: Int) -> UInt8 {
73+
let buffer = UnsafeBufferPointer<UInt8>(start: _bridged.__bytes_beginUnsafe(),
74+
count: count)
75+
return buffer[index]
76+
}
77+
6878
public static func ==(lhs: StringRef, rhs: StaticString) -> Bool {
6979
let lhsBuffer = UnsafeBufferPointer<UInt8>(
7080
start: lhs._bridged.__bytes_beginUnsafe(),
71-
count: Int(lhs._bridged.__bytes_endUnsafe() - lhs._bridged.__bytes_beginUnsafe()))
81+
count: lhs.count)
7282
return rhs.withUTF8Buffer { (rhsBuffer: UnsafeBufferPointer<UInt8>) in
7383
if lhsBuffer.count != rhsBuffer.count { return false }
7484
return lhsBuffer.elementsEqual(rhsBuffer, by: ==)

SwiftCompilerSources/Sources/Optimizer/Analysis/AliasAnalysis.swift

+41-14
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,17 @@ struct AliasAnalysis {
6868
let inst = bridgedInst.instruction
6969
let val = bridgedVal.value
7070
let path = AliasAnalysis.getPtrOrAddressPath(for: val)
71-
if let apply = inst as? ApplySite {
72-
let effect = getMemoryEffect(of: apply, for: val, path: path, context)
73-
switch (effect.read, effect.write) {
74-
case (false, false): return .None
75-
case (true, false): return .MayRead
76-
case (false, true): return .MayWrite
77-
case (true, true): return .MayReadWrite
71+
switch inst {
72+
case let apply as ApplySite:
73+
return getMemoryEffect(ofApply: apply, for: val, path: path, context).bridged
74+
case let builtin as BuiltinInst:
75+
return getMemoryEffect(ofBuiltin: builtin, for: val, path: path, context).bridged
76+
default:
77+
if val.at(path).isEscaping(using: EscapesToInstructionVisitor(target: inst, isAddress: true), context) {
78+
return .MayReadWrite
7879
}
80+
return .None
7981
}
80-
if val.at(path).isEscaping(using: EscapesToInstructionVisitor(target: inst, isAddress: true), context) {
81-
return .MayReadWrite
82-
}
83-
return .None
8482
},
8583

8684
// isObjReleasedFn
@@ -121,7 +119,7 @@ struct AliasAnalysis {
121119
}
122120
}
123121

124-
private func getMemoryEffect(of apply: ApplySite, for address: Value, path: SmallProjectionPath, _ context: FunctionPassContext) -> SideEffects.Memory {
122+
private func getMemoryEffect(ofApply apply: ApplySite, for address: Value, path: SmallProjectionPath, _ context: FunctionPassContext) -> SideEffects.Memory {
125123
let calleeAnalysis = context.calleeAnalysis
126124
let visitor = SideEffectsVisitor(apply: apply, calleeAnalysis: calleeAnalysis, isAddress: true)
127125
let memoryEffects: SideEffects.Memory
@@ -132,7 +130,7 @@ private func getMemoryEffect(of apply: ApplySite, for address: Value, path: Smal
132130
memoryEffects = result.memory
133131
} else {
134132
// `address` has unknown escapes. So we have to take the global effects of the called function(s).
135-
memoryEffects = calleeAnalysis.getSideEffects(of: apply).memory
133+
memoryEffects = calleeAnalysis.getSideEffects(ofApply: apply).memory
136134
}
137135
// Do some magic for `let` variables. Function calls cannot modify let variables.
138136
// The only exception is that the let variable is directly passed to an indirect out of the
@@ -144,14 +142,28 @@ private func getMemoryEffect(of apply: ApplySite, for address: Value, path: Smal
144142
return memoryEffects
145143
}
146144

145+
private func getMemoryEffect(ofBuiltin builtin: BuiltinInst, for address: Value, path: SmallProjectionPath, _ context: FunctionPassContext) -> SideEffects.Memory {
146+
147+
switch builtin.id {
148+
case .Once, .OnceWithContext:
149+
if !address.at(path).isEscaping(using: AddressVisibleByBuiltinOnceVisitor(), context) {
150+
return SideEffects.Memory()
151+
}
152+
let callee = builtin.operands[1].value
153+
return context.calleeAnalysis.getSideEffects(ofCallee: callee).memory
154+
default:
155+
return builtin.memoryEffects
156+
}
157+
}
158+
147159
private func getOwnershipEffect(of apply: ApplySite, for value: Value, path: SmallProjectionPath, _ context: FunctionPassContext) -> SideEffects.Ownership {
148160
let visitor = SideEffectsVisitor(apply: apply, calleeAnalysis: context.calleeAnalysis, isAddress: false)
149161
if let result = value.at(path).visit(using: visitor, context) {
150162
// The resulting effects are the argument effects to which `value` escapes to.
151163
return result.ownership
152164
} else {
153165
// `value` has unknown escapes. So we have to take the global effects of the called function(s).
154-
return visitor.calleeAnalysis.getSideEffects(of: apply).ownership
166+
return visitor.calleeAnalysis.getSideEffects(ofApply: apply).ownership
155167
}
156168
}
157169

@@ -180,6 +192,11 @@ private struct SideEffectsVisitor : EscapeVisitorWithResult {
180192
var followLoads: Bool { !isAddress }
181193
}
182194

195+
private struct AddressVisibleByBuiltinOnceVisitor : EscapeVisitor {
196+
var followTrivialTypes: Bool { true }
197+
var followLoads: Bool { false }
198+
}
199+
183200
/// Lets `ProjectedValue.isEscaping` return true if the value is "escaping" to the `target` instruction.
184201
private struct EscapesToInstructionVisitor : EscapeVisitor {
185202
let target: Instruction
@@ -229,3 +246,13 @@ private struct IsIndirectResultWalker: AddressDefUseWalker {
229246
}
230247
}
231248

249+
private extension SideEffects.Memory {
250+
var bridged: swift.MemoryBehavior {
251+
switch (read, write) {
252+
case (false, false): return .None
253+
case (true, false): return .MayRead
254+
case (false, true): return .MayWrite
255+
case (true, true): return .MayReadWrite
256+
}
257+
}
258+
}

0 commit comments

Comments
 (0)