Skip to content

Commit 746521b

Browse files
authored
Merge branch 'main' into distributed-protocol-requirement-accessors
2 parents e3dbcd0 + 943e7f1 commit 746521b

File tree

476 files changed

+8852
-3864
lines changed

Some content is hidden

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

476 files changed

+8852
-3864
lines changed

CHANGELOG.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,61 @@
11
# CHANGELOG
22

3-
> **Note**\
3+
> [!NOTE]
44
> This is in reverse chronological order, so newer entries are added to the top.
55
66
## Swift 6.0
7+
* [SE-0408][]:
8+
A `for`-`in` loop statement can now accept a pack expansion expression,
9+
enabling iteration over the elements of its respective value pack. This form
10+
supports pattern matching, control transfer statements, and other features
11+
available to a `Sequence`-driven `for`-`in` loop, except for the `where`
12+
clause. Below is an example implementation of the equality operator for
13+
tuples of arbitrary length using pack iteration:
14+
15+
```swift
16+
func == <each Element: Equatable>(lhs: (repeat each Element),
17+
rhs: (repeat each Element)) -> Bool {
18+
19+
for (left, right) in repeat (each lhs, each rhs) {
20+
guard left == right else { return false }
21+
}
22+
return true
23+
}
24+
```
25+
26+
The elements of the value pack corresponding to the pack expansion expression
27+
are evaluated on demand, meaning the i<sup>th</sup> element is evaluated on
28+
the i<sup>th</sup> iteration:
29+
30+
```swift
31+
func doSomething(_: some Any) {}
32+
33+
func evaluateFirst<each T>(_ t: repeat each T) {
34+
for _ in repeat doSomething(each t) {
35+
break
36+
}
37+
}
38+
39+
evaluateFirst(1, 2, 3)
40+
// 'doSomething' will be called only on the first element of the pack.
41+
```
42+
43+
* [SE-0352][]:
44+
The Swift 6 language mode will open existential values with
45+
"self-conforming" types (such as `any Error` or `@objc` protocols)
46+
passed to generic functions. For example:
47+
48+
```swift
49+
func takeError<E: Error>(_ error: E) { }
50+
51+
func passError(error: any Error) {
52+
takeError(error) // Swift 5 does not open `any Error`, Swift 6 does
53+
}
54+
```
55+
56+
This behavior can be enabled prior to the Swift 6 language mode
57+
using the upcoming language feature `ImplicitOpenExistentials`.
58+
759
* [SE-0422][]:
860
Non-built-in expression macros can now be used as default arguments that
961
expand at each call site. For example, a custom `#CurrentFile` macro used as
@@ -285,6 +337,8 @@ concurrency checking.
285337

286338
## Swift 5.9.2
287339

340+
### 2023-12-11 (Xcode 15.1)
341+
288342
* [SE-0407][]:
289343

290344
Member macros can specify a list of protocols via the `conformances` argument to the macro role. The macro implementation will be provided with those protocols that are listed but have not already been implemented by the type to which the member macro is attached, in the same manner as extension macros.
@@ -10129,10 +10183,12 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
1012910183
[SE-0394]: https://github.com/apple/swift-evolution/blob/main/proposals/0394-swiftpm-expression-macros.md
1013010184
[SE-0397]: https://github.com/apple/swift-evolution/blob/main/proposals/0397-freestanding-declaration-macros.md
1013110185
[SE-0407]: https://github.com/apple/swift-evolution/blob/main/proposals/0407-member-macro-conformances.md
10186+
[SE-0408]: https://github.com/apple/swift-evolution/blob/main/proposals/0408-pack-iteration.md
1013210187
[SE-0411]: https://github.com/apple/swift-evolution/blob/main/proposals/0411-isolated-default-values.md
1013310188
[SE-0417]: https://github.com/apple/swift-evolution/blob/main/proposals/0417-task-executor-preference.md
1013410189
[SE-0412]: https://github.com/apple/swift-evolution/blob/main/proposals/0412-strict-concurrency-for-global-variables.md
1013510190
[SE-0413]: https://github.com/apple/swift-evolution/blob/main/proposals/0413-typed-throws.md
10191+
[SE-0422]: https://github.com/apple/swift-evolution/blob/main/proposals/0422-caller-side-default-argument-macro-expression.md
1013610192
[#64927]: <https://github.com/apple/swift/issues/64927>
1013710193
[#42697]: <https://github.com/apple/swift/issues/42697>
1013810194
[#42728]: <https://github.com/apple/swift/issues/42728>

SwiftCompilerSources/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,17 @@ function(add_swift_compiler_modules_library name)
9898
"DEPENDS"
9999
${ARGN})
100100

101+
# Prior to 5.9, we have to use the experimental flag for C++ interop.
102+
if (CMAKE_Swift_COMPILER_VERSION VERSION_LESS 5.9)
103+
set(cxx_interop_flag "-enable-experimental-cxx-interop")
104+
else()
105+
set(cxx_interop_flag "-cxx-interoperability-mode=default")
106+
endif()
107+
101108
set(swift_compile_options
102109
"-color-diagnostics"
103110
"-Xfrontend" "-validate-tbd-against-ir=none"
104-
"-Xfrontend" "-enable-experimental-cxx-interop"
111+
"${cxx_interop_flag}"
105112
"-Xfrontend" "-disable-target-os-checking"
106113
"-Xcc" "-std=c++17"
107114
"-Xcc" "-DCOMPILED_WITH_SWIFT" "-Xcc" "-DSWIFT_TARGET"

SwiftCompilerSources/Sources/Optimizer/Utilities/EscapeUtils.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,41 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
420420
return .continueWalk
421421
}
422422
return isEscaping
423+
424+
case .AtomicLoad:
425+
// Treat atomic loads as regular loads and just walk down their uses.
426+
if !followLoads(at: path) {
427+
return .continueWalk
428+
}
429+
430+
// Even when analyzing atomics, a loaded trivial value can be ignored.
431+
if hasRelevantType(bi, at: path.projectionPath) {
432+
return .continueWalk
433+
}
434+
435+
return walkDownUses(ofValue: bi, path: path.with(knownType: nil))
436+
437+
case .AtomicStore, .AtomicRMW:
438+
// If we shouldn't follow the store, then we can keep walking.
439+
if !path.followStores {
440+
return .continueWalk
441+
}
442+
443+
// Be conservative and just say the store is escaping.
444+
return isEscaping
445+
446+
case .CmpXChg:
447+
// If we have to follow loads or stores of a cmpxchg, then just bail.
448+
if followLoads(at: path) || path.followStores {
449+
return isEscaping
450+
}
451+
452+
return .continueWalk
453+
454+
case .Fence:
455+
// Fences do not affect escape analysis.
456+
return .continueWalk
457+
423458
default:
424459
return isEscaping
425460
}

SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ struct LifetimeDependence : CustomStringConvertible {
185185
var parentValue: Value { scope.parentValue }
186186

187187
var function: Function {
188-
dependentValue.parentFunction // dependentValue can't be undef
188+
dependentValue.parentFunction
189189
}
190190

191191
var description: String {

SwiftCompilerSources/Sources/Optimizer/Utilities/OptUtils.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ extension Value {
4747
/// check, because it treats a value_to_bridge_object instruction as "trivial".
4848
/// It can also handle non-trivial enums with trivial cases.
4949
func isTrivial(_ context: some Context) -> Bool {
50-
if self is Undef {
51-
return true
52-
}
5350
var worklist = ValueWorklist(context)
5451
defer { worklist.deinitialize() }
5552

@@ -64,12 +61,12 @@ extension Value {
6461
switch v {
6562
case is ValueToBridgeObjectInst:
6663
break
67-
case is StructInst, is TupleInst:
68-
let inst = (v as! SingleValueInstruction)
69-
worklist.pushIfNotVisited(contentsOf: inst.operands.values.filter { !($0 is Undef) })
64+
case let si as StructInst:
65+
worklist.pushIfNotVisited(contentsOf: si.operands.values)
66+
case let ti as TupleInst:
67+
worklist.pushIfNotVisited(contentsOf: ti.operands.values)
7068
case let en as EnumInst:
71-
if let payload = en.payload,
72-
!(payload is Undef) {
69+
if let payload = en.payload {
7370
worklist.pushIfNotVisited(payload)
7471
}
7572
default:

SwiftCompilerSources/Sources/SIL/Value.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ public protocol Value : AnyObject, CustomStringConvertible {
2525
var definingInstruction: Instruction? { get }
2626

2727
/// The block where the value is defined.
28-
///
29-
/// It's not legal to get the definingBlock of an `Undef` value.
3028
var parentBlock: BasicBlock { get }
3129

30+
/// The function where the value lives in.
31+
///
32+
/// It's not legal to get the parentFunction of an instruction in a global initializer.
33+
var parentFunction: Function { get }
34+
3235
/// True if the value has a trivial type.
3336
var hasTrivialType: Bool { get }
3437

@@ -113,6 +116,7 @@ extension Value {
113116

114117
public var uses: UseList { UseList(bridged.getFirstUse()) }
115118

119+
// Default implementation for all values which have a parent block, like instructions and arguments.
116120
public var parentFunction: Function { parentBlock.parentFunction }
117121

118122
public var type: Type { bridged.getType().type }
@@ -206,8 +210,11 @@ extension BridgedValue {
206210
public final class Undef : Value {
207211
public var definingInstruction: Instruction? { nil }
208212

213+
public var parentFunction: Function { bridged.SILUndef_getParentFunction().function }
214+
209215
public var parentBlock: BasicBlock {
210-
fatalError("undef has no defining block")
216+
// By convention, undefs are considered to be defined at the entry of the function.
217+
parentFunction.entryBlock
211218
}
212219

213220
/// Undef has not parent function, therefore the default `hasTrivialType` does not work.
@@ -221,9 +228,12 @@ public final class Undef : Value {
221228

222229
final class PlaceholderValue : Value {
223230
public var definingInstruction: Instruction? { nil }
231+
224232
public var parentBlock: BasicBlock {
225233
fatalError("PlaceholderValue has no defining block")
226234
}
235+
236+
public var parentFunction: Function { bridged.PlaceholderValue_getParentFunction().function }
227237
}
228238

229239
extension OptionalBridgedValue {

benchmark/scripts/Template.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
//===--- {name}.swift -------------------------------------------===//
1+
//===--- {name}.swift {padding}---===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2021 Apple Inc. and the Swift project authors
5+
// Copyright (c) {year} Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -12,7 +12,7 @@
1212

1313
import TestsUtils
1414

15-
public let {name} = [
15+
public let benchmarks = [
1616
BenchmarkInfo(name: "{name}", runFunction: run_{name}, tags: [.validation, .api]),
1717
]
1818

benchmark/scripts/create_benchmark.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
import argparse
4+
import datetime
45
import os
56
import re
67

@@ -46,18 +47,22 @@ def create_benchmark_file(name):
4647
and places it in the `single-source` directory.
4748
"""
4849

50+
file_text = ""
4951
template_path = create_relative_path("Template.swift")
50-
benchmark_template = ""
5152
with open(template_path, "r") as f:
52-
benchmark_template = "".join(f.readlines())
53+
file_text = "".join(f.readlines())
5354

54-
# fill in template with benchmark name.
55-
formatted_template = benchmark_template.format(name=name)
55+
# fill in missing template details
56+
file_text = file_text.format(
57+
name=name,
58+
padding="-" * (56 - len(name)),
59+
year=datetime.date.today().year
60+
)
5661

57-
relative_path = create_relative_path("../single-source/")
58-
source_file_path = os.path.join(relative_path, name + ".swift")
59-
with open(source_file_path, "w") as f:
60-
f.write(formatted_template)
62+
file_path_prefix = create_relative_path("../single-source/")
63+
file_path = os.path.join(file_path_prefix, name + ".swift")
64+
with open(file_path, "w") as f:
65+
f.write(file_text)
6166

6267

6368
def add_import_benchmark(name):
@@ -119,9 +124,9 @@ def add_register_benchmark(name):
119124

120125
file_new_contents = insert_line_alphabetically(
121126
name,
122-
"registerBenchmark(" + name + ")\n",
127+
"register(" + name + ".benchmarks)\n",
123128
file_contents,
124-
r"registerBenchmark\(([a-zA-Z]+)\)",
129+
r"register\(([a-zA-Z]+)\.benchmarks\)",
125130
)
126131
with open(relative_path, "w") as f:
127132
for line in file_new_contents:

0 commit comments

Comments
 (0)