Skip to content

Commit 29ec7d4

Browse files
Merge branch 'apple:main' into fix-it-for-repeated-any-or-some-in-composition
2 parents f5d920f + c9d9226 commit 29ec7d4

File tree

591 files changed

+11185
-16931
lines changed

Some content is hidden

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

591 files changed

+11185
-16931
lines changed

CHANGELOG.md

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
330330

331331
* [SE-0328][]:
332332

333-
Opaque types (expressed with 'some') can now be used in structural positions
333+
Opaque types (expressed with `some`) can now be used in structural positions
334334
within a result type, including having multiple opaque types in the same
335335
result. For example:
336336

@@ -942,7 +942,7 @@ Swift 5.5
942942
}
943943
```
944944

945-
* The 'lazy' keyword now works in local contexts, making the following valid:
945+
* The `lazy` keyword now works in local contexts, making the following valid:
946946

947947
```swift
948948
func test(useIt: Bool) {
@@ -2901,7 +2901,7 @@ Swift 3.0
29012901

29022902
* [SE-0101][]:
29032903

2904-
The functions `sizeof()`, `strideof()`, and `alignof()` have been removed.
2904+
The functions `sizeof()`, `strideof()`, and `alignof()` have been removed.
29052905
Memory layout properties for a type `T` are now spelled
29062906
`MemoryLayout<T>.size`, `MemoryLayout<T>.stride`, and
29072907
`MemoryLayout<T>.alignment`, respectively.
@@ -2943,7 +2943,7 @@ Swift 3.0
29432943

29442944
* [SE-0124][]:
29452945

2946-
Initializers on `Int` and `UInt` that accept an `ObjectIdentifier` must now use an explicit `bitPattern` label.
2946+
Initializers on `Int` and `UInt` that accept an `ObjectIdentifier` must now use an explicit `bitPattern` label.
29472947

29482948
```swift
29492949
let x: ObjectIdentifier = ...
@@ -3199,7 +3199,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
31993199
didFailToRegisterForRemoteNotificationsWithError error: NSError)
32003200
```
32013201

3202-
Now it accepts an `Error` argument:
3202+
Now it accepts an `Error` argument:
32033203

32043204
```swift
32053205
optional func application(_ application: UIApplication,
@@ -3422,7 +3422,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
34223422
foo/* comment */! // no longer works
34233423
```
34243424

3425-
Parse errors resulting from this change can be resolved by moving the comment outside the expression.
3425+
Parse errors resulting from this change can be resolved by moving the comment outside the expression.
34263426

34273427
* [SE-0031][]:
34283428

@@ -3483,7 +3483,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
34833483
Attributes change from using `=` in parameters lists
34843484
to using `:`, aligning with function call syntax.
34853485

3486-
```
3486+
```swift
34873487
// before
34883488
@available(*, unavailable, renamed="MyRenamedProtocol")
34893489

@@ -3524,13 +3524,13 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
35243524

35253525
Curried function syntax (with successive parenthesized groups of arguments) is removed, and now produces a compile-time error. Use chained functional return types instead.
35263526

3527-
```
3528-
// Before
3529-
public func project(function f: FunctionType)(p0: CGPoint, p1: CGPoint)(x: CGFloat) -> CGPoint
3527+
```swift
3528+
// Before
3529+
public func project(function f: FunctionType)(p0: CGPoint, p1: CGPoint)(x: CGFloat) -> CGPoint
35303530

3531-
// After
3532-
public func project(function f: FunctionType) -> (p0: CGPoint, p1: CGPoint) -> (x: CGFloat) -> CGPoint
3533-
```
3531+
// After
3532+
public func project(function f: FunctionType) -> (p0: CGPoint, p1: CGPoint) -> (x: CGFloat) -> CGPoint
3533+
```
35343534

35353535
* Generic signatures can now contain superclass requirements with generic parameter types, for example:
35363536

@@ -4877,11 +4877,15 @@ Swift 1.2
48774877
* The `@autoclosure` attribute is now an attribute on a parameter, not an
48784878
attribute on the parameter's type.
48794879

4880-
Where before you might have used:
4880+
Where before you might have used
48814881

48824882
```swift
48834883
func assert(predicate : @autoclosure () -> Bool) {...}
4884-
you now write this as:
4884+
```
4885+
4886+
you now write this as
4887+
4888+
```swift
48854889
func assert(@autoclosure predicate : () -> Bool) {...}
48864890
```
48874891

@@ -4923,7 +4927,11 @@ Swift 1.2
49234927
// redeclares Objective-C method
49244928
//'setProperty:'
49254929
}
4930+
```
4931+
49264932
Similar checking applies to accidental overrides in the Objective-C runtime:
4933+
4934+
```swift
49274935
class B : NSObject {
49284936
func method(arg: String) { } // note: overridden declaration
49294937
// here has type '(String) -> ()'
@@ -4934,7 +4942,11 @@ Swift 1.2
49344942
// selector 'method:' has incompatible
49354943
// type '([String]) -> ()'
49364944
}
4945+
```
4946+
49374947
as well as protocol conformances:
4948+
4949+
```swift
49384950
class MyDelegate : NSObject, NSURLSessionDelegate {
49394951
func URLSession(session: NSURLSession, didBecomeInvalidWithError:
49404952
Bool){ } // error: Objective-C method 'URLSession:didBecomeInvalidWithError:'
@@ -5022,13 +5034,17 @@ Swift 1.2
50225034
that used `unsafeBitCast` as a workaround for this issue can be written to
50235035
use the raw value initializer.
50245036

5025-
For example:
5037+
For example,
50265038

50275039
```swift
50285040
let animationCurve =
50295041
unsafeBitCast(userInfo[UIKeyboardAnimationCurveUserInfoKey].integerValue,
50305042
UIViewAnimationCurve.self)
5031-
can now be written instead as:
5043+
```
5044+
5045+
can now be written instead as
5046+
5047+
```swift
50325048
let animationCurve = UIViewAnimationCurve(rawValue:
50335049
userInfo[UIKeyboardAnimationCurveUserInfoKey].integerValue)!
50345050
```

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ set(SWIFT_ANALYZE_CODE_COVERAGE FALSE CACHE STRING
179179
# SWIFT_VERSION is deliberately /not/ cached so that an existing build directory
180180
# can be reused when a new version of Swift comes out (assuming the user hasn't
181181
# manually set it as part of their own CMake configuration).
182-
set(SWIFT_VERSION "5.7")
182+
set(SWIFT_VERSION "5.8")
183183

184184
set(SWIFT_VENDOR "" CACHE STRING
185185
"The vendor name of the Swift compiler")

SwiftCompilerSources/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.swiftpm

SwiftCompilerSources/CMakeLists.txt

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,16 @@ function(add_swift_compiler_modules_library name)
171171
endforeach()
172172

173173
# Create a static library containing all module object files.
174+
if (XCODE)
175+
# Xcode does not compile libraries that contain only object files.
176+
# Therefore, it fails to create the static library. As a workaround,
177+
# we add an empty source file force_lib.c to the target.
178+
set(all_obj_files force_lib.c ${all_obj_files})
179+
endif()
174180
add_library(${name} STATIC ${all_obj_files})
175181
add_dependencies(${name} ${all_module_targets})
176182
set_target_properties(${name} PROPERTIES LINKER_LANGUAGE CXX)
177183
set_property(GLOBAL APPEND PROPERTY SWIFT_BUILDTREE_EXPORTS ${name})
178-
179-
# Xcode does not compile libraries that contain only object files.
180-
# Therefore, it fails to create the static library. As a workaround,
181-
# we add a dummy script phase to the target.
182-
if (XCODE)
183-
add_custom_command(TARGET ${name} POST_BUILD
184-
COMMAND ""
185-
COMMENT "Dummy script phase to force building this target")
186-
endif()
187184
endfunction()
188185

189186

@@ -267,25 +264,3 @@ else()
267264
endif()
268265

269266
endif()
270-
271-
# Configure 'SwiftCompilerModules' SwiftPM package. The 'Package.swift' will
272-
# be created at '${build_dir}/SwiftCompilerModulesPackage/Package.swift' and can
273-
# be built with 'swift-build'.
274-
# Note that this SwiftPM package itself is just for development purposes, and
275-
# is not actually used for the compiler building.
276-
set(swiftcompiler_modules_package_directory
277-
"${SWIFT_BINARY_DIR}/SwiftCompilerModulesPackage")
278-
configure_file(Package.swift.in
279-
"${swiftcompiler_modules_package_directory}/Package.swift" @ONLY)
280-
# SwiftPM requires all sources are inside the directory of 'Package.swift'.
281-
# Create symlinks to the actual source directories.
282-
execute_process(COMMAND
283-
"${CMAKE_COMMAND}" -E create_symlink
284-
"${CMAKE_CURRENT_SOURCE_DIR}/Sources"
285-
"${swiftcompiler_modules_package_directory}/Sources")
286-
if(SWIFT_BUILD_REGEX_PARSER_IN_COMPILER)
287-
execute_process(COMMAND
288-
"${CMAKE_COMMAND}" -E create_symlink
289-
"${EXPERIMENTAL_STRING_PROCESSING_SOURCE_DIR}/Sources/_RegexParser"
290-
"${swiftcompiler_modules_package_directory}/_RegexParser_Sources")
291-
endif()

SwiftCompilerSources/Package.swift.in renamed to SwiftCompilerSources/Package.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
// NOTE: This 'Package.swift.in' file is for CMake configure_file().
15-
// Generated 'Package.swift' can be found in
16-
// '${swift_build_dir}/SwiftCompilerSources/Package.swift'.
17-
1814
import PackageDescription
1915

2016
private extension Target {
@@ -23,9 +19,7 @@ private extension Target {
2319
"-Xfrontend", "-validate-tbd-against-ir=none",
2420
"-Xfrontend", "-enable-cxx-interop",
2521
// Bridging modules and headers
26-
"-Xcc", "-I", "-Xcc", "@SWIFT_SOURCE_DIR@/include",
27-
// Generated C headers
28-
"-Xcc", "-I", "-Xcc", "@CMAKE_BINARY_DIR@/include",
22+
"-Xcc", "-I", "-Xcc", "../include",
2923
"-cross-module-optimization"
3024
]),
3125
]

SwiftCompilerSources/Sources/Basic/Utils.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,30 @@
1212

1313
@_exported import BasicBridging
1414

15+
//===----------------------------------------------------------------------===//
16+
// StringRef
17+
//===----------------------------------------------------------------------===//
18+
19+
public struct StringRef : CustomStringConvertible, CustomReflectable {
20+
let _bridged : BridgedStringRef
21+
22+
public init(bridged: BridgedStringRef) { self._bridged = bridged }
23+
24+
public var string: String { _bridged.string }
25+
public var description: String { string }
26+
public var customMirror: Mirror { Mirror(self, children: []) }
27+
28+
public static func ==(lhs: StringRef, rhs: StaticString) -> Bool {
29+
let lhsBuffer = UnsafeBufferPointer<UInt8>(start: lhs._bridged.data, count: Int(lhs._bridged.length))
30+
return rhs.withUTF8Buffer { (rhsBuffer: UnsafeBufferPointer<UInt8>) in
31+
if lhsBuffer.count != rhsBuffer.count { return false }
32+
return lhsBuffer.elementsEqual(rhsBuffer, by: ==)
33+
}
34+
}
35+
36+
public static func !=(lhs: StringRef, rhs: StaticString) -> Bool { !(lhs == rhs) }
37+
}
38+
1539
//===----------------------------------------------------------------------===//
1640
// Bridging Utilities
1741
//===----------------------------------------------------------------------===//

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/AssumeSingleThreaded.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let assumeSingleThreadedPass = FunctionPass(
3333
for inst in block.instructions {
3434
guard let rcInst = inst as? RefCountingInst else { continue }
3535

36-
context.setAtomicity(of: rcInst, isAtomic: false)
36+
rcInst.setAtomicity(isAtomic: false, context)
3737
}
3838
}
3939
}

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/StackPromotion.swift

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ private extension EscapeInfo {
207207
var dominatingBlock = value.block
208208

209209
_ = isEscaping(object: value, visitUse: { op, _, _ in
210-
if let defBlock = op.value.definingBlock, defBlock.dominates(dominatingBlock, domTree) {
210+
let defBlock = op.value.definingBlock
211+
if defBlock.dominates(dominatingBlock, domTree) {
211212
dominatingBlock = defBlock
212213
}
213214
return .continueWalking
@@ -230,25 +231,25 @@ private extension EscapeInfo {
230231
outerBlockRange.insert(user.block)
231232

232233
let val = op.value
233-
if let defBlock = val.definingBlock {
234-
// Also insert the operand's definition. Otherwise we would miss allocation
235-
// instructions (for which the `visitUse` closure is not called).
236-
outerBlockRange.insert(defBlock)
237-
238-
// We need to explicitly add predecessor blocks of phi-arguments becaues they
239-
// are not necesesarily visited by `EscapeInfo.walkDown`.
240-
// This is important for the special case where there is a back-edge from the
241-
// inner range to the inner rage's begin-block:
242-
//
243-
// bb0: // <- need to be in the outer range
244-
// br bb1(%some_init_val)
245-
// bb1(%arg):
246-
// %k = alloc_ref $Klass // innerInstRange.begin
247-
// cond_br bb2, bb1(%k) // back-edge to bb1 == innerInstRange.blockRange.begin
248-
//
249-
if val is BlockArgument {
250-
outerBlockRange.insert(contentsOf: defBlock.predecessors)
251-
}
234+
let defBlock = val.definingBlock
235+
236+
// Also insert the operand's definition. Otherwise we would miss allocation
237+
// instructions (for which the `visitUse` closure is not called).
238+
outerBlockRange.insert(defBlock)
239+
240+
// We need to explicitly add predecessor blocks of phi-arguments becaues they
241+
// are not necesesarily visited by `EscapeInfo.walkDown`.
242+
// This is important for the special case where there is a back-edge from the
243+
// inner range to the inner rage's begin-block:
244+
//
245+
// bb0: // <- need to be in the outer range
246+
// br bb1(%some_init_val)
247+
// bb1(%arg):
248+
// %k = alloc_ref $Klass // innerInstRange.begin
249+
// cond_br bb2, bb1(%k) // back-edge to bb1 == innerInstRange.blockRange.begin
250+
//
251+
if val is BlockArgument {
252+
outerBlockRange.insert(contentsOf: defBlock.predecessors)
252253
}
253254
return .continueWalking
254255
})

SwiftCompilerSources/Sources/Optimizer/InstructionPasses/SimplifyBeginCOWMutation.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import Basic
1314
import SIL
1415

1516
/// Simplify begin_cow_mutation instructions.
@@ -66,7 +67,7 @@ private func optimizeEmptySingleton(_ beginCOW: BeginCOWMutationInst,
6667
}
6768
let builder = Builder(at: beginCOW, location: beginCOW.location, context)
6869
let zero = builder.createIntegerLiteral(0, type: beginCOW.uniquenessResult.type);
69-
context.replaceAllUses(of: beginCOW.uniquenessResult, with: zero)
70+
beginCOW.uniquenessResult.uses.replaceAll(with: zero, context)
7071
}
7172

7273
private func isEmptyCOWSingleton(_ value: Value) -> Bool {
@@ -102,7 +103,7 @@ private func optimizeEmptyBeginEndPair(_ beginCOW: BeginCOWMutationInst,
102103

103104
for use in buffer.nonDebugUses {
104105
let endCOW = use.instruction as! EndCOWMutationInst
105-
context.replaceAllUses(of: endCOW, with: beginCOW.operand)
106+
endCOW.uses.replaceAll(with: beginCOW.operand, context)
106107
context.erase(instruction: endCOW)
107108
}
108109
context.erase(instruction: beginCOW, .includingDebugUses)
@@ -121,7 +122,7 @@ private func optimizeEmptyEndBeginPair(_ beginCOW: BeginCOWMutationInst,
121122
return false
122123
}
123124

124-
context.replaceAllUses(of: beginCOW.bufferResult, with: endCOW.operand)
125+
beginCOW.bufferResult.uses.replaceAll(with: endCOW.operand, context)
125126
context.erase(instruction: beginCOW, .includingDebugUses)
126127
context.erase(instruction: endCOW, .includingDebugUses)
127128
return true

SwiftCompilerSources/Sources/Optimizer/InstructionPasses/SimplifyStrongRetainRelease.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ let simplifyStrongReleasePass = InstructionPass<StrongReleaseInst>(
5959
// release of the class, squish the conversion.
6060
if let ier = op as? InitExistentialRefInst {
6161
if ier.uses.isSingleUse {
62-
context.setOperand(of: release, at: 0, to: ier.operand)
62+
release.setOperand(at: 0, to: ier.operand, context)
6363
context.erase(instruction: ier)
6464
return
6565
}

0 commit comments

Comments
 (0)