Skip to content

Commit 87628ea

Browse files
committed
Merge branch 'release/5.7' of github.com:apple/swift into swiftwasm-release/5.7
# Conflicts: # include/swift/ABI/CompactFunctionPointer.h # include/swift/Runtime/Config.h # lib/IRGen/IRGenSIL.cpp # stdlib/public/core/KeyPath.swift
2 parents b36d317 + 73798d0 commit 87628ea

File tree

548 files changed

+16259
-4970
lines changed

Some content is hidden

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

548 files changed

+16259
-4970
lines changed

CHANGELOG.md

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

66
## Swift 5.7
77

8+
* [SE-0352][]:
9+
10+
It's now possible to call a generic function with a value of protocol type
11+
in places that would previously fail because `any` types do not conform
12+
to their protocols. For example:
13+
14+
```
15+
protocol P {
16+
associatedtype A
17+
func getA() -> A
18+
}
19+
20+
func takeP<T: P>(_ value: T) { }
21+
22+
func test(p: any P) {
23+
takeP(p) // was an error "type 'any P' cannot conform to 'P'", now accepted
24+
}
25+
```
26+
27+
This operates by "opening" the value of protocol type and passing the
28+
underlying type directly to the generic function.
29+
30+
* [SE-0347][]:
31+
32+
It's now possible to use a default value expression with a generic parameter type
33+
to default the argument and its type:
34+
35+
```
36+
func compute<C: Collection>(_ values: C = [0, 1, 2]) {
37+
...
38+
}
39+
```
40+
41+
`compute` is now accepted by compiler and `[Int]` is going to be inferred
42+
for `C` at call sites that do not provide the argument explicitly.
43+
44+
* [SE-0326][]:
45+
46+
It's now possible to infer parameter and result types from the body of a multi-statement
47+
closure. The distinction between single- and multi-statement closures has been removed.
48+
49+
Use of closures becomes less cumbersome by removing the need to constantly specify explicit
50+
closure types which sometimes could be pretty large e.g. when there are multiple parameters
51+
or a complex tuple result type.
52+
53+
For example:
54+
55+
```swift
56+
func map<T>(fn: (Int) -> T) -> T {
57+
return fn(42)
58+
}
59+
60+
func computeResult<U: BinaryInteger>(_: U) -> U { /* processing */ }
61+
62+
let _ = map {
63+
if let $0 < 0 {
64+
// do some processing
65+
}
66+
67+
return computeResult($0)
68+
}
69+
```
70+
71+
The result type of `map` can now be inferred from the body of the trailing closure
72+
passed as an argument.
73+
874
* [SE-0345][]:
975

1076
It is now possible to unwrap optional variables with a shorthand syntax that
@@ -9119,6 +9185,9 @@ Swift 1.0
91199185
[SE-0343]: <https://github.com/apple/swift-evolution/blob/main/proposals/0343-top-level-concurrency.md>
91209186
[SE-0340]: <https://github.com/apple/swift-evolution/blob/main/proposals/0340-swift-noasync.md>
91219187
[SE-0345]: <https://github.com/apple/swift-evolution/blob/main/proposals/0345-if-let-shorthand.md>
9188+
[SE-0326]: <https://github.com/apple/swift-evolution/blob/main/proposals/0326-extending-multi-statement-closure-inference.md>
9189+
[SE-0347]: <https://github.com/apple/swift-evolution/blob/main/proposals/0347-type-inference-from-default-exprs.md>
9190+
[SE-0352]: <https://github.com/apple/swift-evolution/blob/main/proposals/0352-implicit-open-existentials.md>
91229191

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

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ option(SWIFT_BUILD_PERF_TESTSUITE
137137
"Create in-tree targets for building swift performance benchmarks."
138138
FALSE)
139139

140+
option(SWIFT_BUILD_REGEX_PARSER_IN_COMPILER
141+
"Build the Swift regex parser as part of the compiler."
142+
TRUE)
143+
140144
option(SWIFT_INCLUDE_TESTS "Create targets for building/running tests." TRUE)
141145

142146
option(SWIFT_INCLUDE_TEST_BINARIES

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @apple/swift5-branch-managers

SwiftCompilerSources/Package.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let package = Package(
1111
.library(
1212
name: "Swift",
1313
type: .static,
14-
targets: ["SIL", "Optimizer", "_RegexParser"]),
14+
targets: ["SIL", "Optimizer", "_CompilerRegexParser"]),
1515
],
1616
dependencies: [
1717
],
@@ -26,15 +26,23 @@ let package = Package(
2626
"-cross-module-optimization"
2727
])]),
2828
.target(
29-
name: "_RegexParser",
29+
name: "_CompilerRegexParser",
3030
dependencies: [],
31-
swiftSettings: [SwiftSetting.unsafeFlags([
31+
path: "_RegexParser",
32+
swiftSettings: [
33+
.unsafeFlags([
3234
"-I", "../include/swift",
33-
"-cross-module-optimization"
35+
"-cross-module-optimization",
36+
]),
37+
// Workaround until `_RegexParser` is imported as implementation-only
38+
// by `_StringProcessing`.
39+
.unsafeFlags([
40+
"-Xfrontend",
41+
"-disable-implicit-string-processing-module-import"
3442
])]),
3543
.target(
3644
name: "Optimizer",
37-
dependencies: ["SIL", "_RegexParser"],
45+
dependencies: ["SIL", "_CompilerRegexParser"],
3846
swiftSettings: [SwiftSetting.unsafeFlags([
3947
"-I", "../include/swift",
4048
"-cross-module-optimization"

SwiftCompilerSources/Sources/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
add_subdirectory(Basic)
1212
add_subdirectory(AST)
13-
if(SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING)
13+
if(SWIFT_BUILD_REGEX_PARSER_IN_COMPILER)
1414
add_subdirectory(_RegexParser)
1515
endif()
1616
add_subdirectory(SIL)

SwiftCompilerSources/Sources/Optimizer/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
set(dependencies)
1010
list(APPEND dependencies Basic SIL)
11-
if(SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING)
12-
list(APPEND dependencies _RegexParser)
11+
if(SWIFT_BUILD_REGEX_PARSER_IN_COMPILER)
12+
list(APPEND dependencies _CompilerRegexParser)
1313
endif()
1414

1515
add_swift_compiler_module(Optimizer DEPENDS ${dependencies})

SwiftCompilerSources/Sources/Optimizer/PassManager/PassRegistration.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
import SIL
1414
import OptimizerBridging
1515

16-
#if canImport(_RegexParser)
17-
import _RegexParser
16+
#if canImport(_CompilerRegexParser)
17+
import _CompilerRegexParser
1818
#endif
1919

2020
@_cdecl("initializeSwiftModules")
2121
public func initializeSwiftModules() {
2222
registerSILClasses()
2323
registerSwiftPasses()
2424

25-
#if canImport(_RegexParser)
25+
#if canImport(_CompilerRegexParser)
2626
registerRegexParser()
2727
#endif
2828
}

SwiftCompilerSources/Sources/_RegexParser/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ foreach(source ${_LIBSWIFT_REGEX_PARSER_SOURCES})
1515
endforeach()
1616
message(STATUS "Using Experimental String Processing library for libswift _RegexParser (${EXPERIMENTAL_STRING_PROCESSING_SOURCE_DIR}).")
1717

18-
add_swift_compiler_module(_RegexParser
18+
add_swift_compiler_module(_CompilerRegexParser
1919
"${LIBSWIFT_REGEX_PARSER_SOURCES}"
2020
Regex.swift)

docs/ABI/Mangling.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ Globals
189189
global ::= global 'MN' // noncanonical specialized generic type metadata for global
190190
global ::= global 'Mz' // canonical specialized generic type metadata caching token
191191

192+
global ::= global 'Mq' // global with a uniquing prefix
193+
192194
#if SWIFT_RUNTIME_VERSION >= 5.4
193195
global ::= context (decl-name '_')+ 'WZ' // global variable one-time initialization function
194196
global ::= context (decl-name '_')+ 'Wz' // global variable one-time initialization token
@@ -635,7 +637,7 @@ Types
635637
type ::= protocol-list 'p' // existential type
636638
type ::= protocol-list superclass 'Xc' // existential type with superclass
637639
type ::= protocol-list 'Xl' // existential type with AnyObject
638-
type ::= protocol-list 'y' (type* '_')* type* retroactive-conformance* 'Xp' // parameterized protocol type
640+
type ::= protocol-list 'y' (type* '_')* type* retroactive-conformance* 'XP' // parameterized protocol type
639641
type ::= type-list 't' // tuple
640642
type ::= type generic-signature 'u' // generic type
641643
type ::= 'x' // generic param, depth=0, idx=0
@@ -914,6 +916,11 @@ than the module of the conforming type or the conformed-to protocol), it is
914916
mangled with its offset into the set of conformance requirements, the
915917
root protocol conformance, and the suffix 'g'.
916918

919+
::
920+
921+
// No generalization signature.
922+
extended-existential-shape ::= type 'Xg' // no generalization signature
923+
extended-existential-shape ::= generic-signature type 'XG'
917924

918925
Identifiers
919926
~~~~~~~~~~~

docs/RequirementMachine/RequirementMachine.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3053,7 +3053,7 @@ \chapter{The Requirement Machine}\label{requirementmachine}
30533053

30543054
\section{Generic Parameters}\label{genericparamsym}
30553055
\index{generic parameter symbol}
3056-
So far, I've only shown you how to build rewrite rules from requirements in the requirement signature of some protocol $\proto{P}$. When lowering a type parameter, the protocol $\genericparam{Self}$ type lowers to the protocol symbol $\protosym{P}$. Once such a rewrite system is built, queries can be performed against the protocol generic signature $\gensig{\genericparam{Self}}{\genericparam{Self}\colon\proto{P}}$. When lowering parameters and requirements in an arbitary generic signature, generic parameter types instead become generic parameter symbols.
3056+
So far, I've only shown you how to build rewrite rules from requirements in the requirement signature of some protocol $\proto{P}$. When lowering a type parameter, the protocol $\genericparam{Self}$ type lowers to the protocol symbol $\protosym{P}$. Once such a rewrite system is built, queries can be performed against the protocol generic signature $\gensig{\genericparam{Self}}{\genericparam{Self}\colon\proto{P}}$. When lowering parameters and requirements in an arbitrary generic signature, generic parameter types instead become generic parameter symbols.
30573057

30583058
Generic parameter symbols should only ever appear as the initial symbol in a term. While the rewrite system would have no trouble with terms where generic parameter symbols appear elsewhere in the abstract, they don't actually make sense semantically, since they do not correspond to valid Swift type parameter types.
30593059

0 commit comments

Comments
 (0)