Skip to content

Commit d38a72c

Browse files
committed
Merge branch 'master' into master-next
2 parents 9129271 + 08568a5 commit d38a72c

File tree

271 files changed

+5792
-3475
lines changed

Some content is hidden

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

271 files changed

+5792
-3475
lines changed

CHANGELOG.md

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,24 @@ CHANGELOG
2626
Swift Next
2727
----------
2828

29-
* [SR-8974][]:
29+
* [SR-4206][]:
3030

31-
Duplicate tuple element labels are no longer allowed, because it leads
32-
to incorrect behavior. For example:
31+
A method override is no longer allowed to have a generic signature with
32+
requirements not imposed by the base method. For example:
3333

3434
```
35-
let dupLabels: (foo: Int, foo: Int) = (foo: 1, foo: 2)
36-
37-
enum Foo { case bar(x: Int, x: Int) }
38-
let f: Foo = .bar(x: 0, x: 1)
35+
protocol P {}
36+
37+
class Base {
38+
func foo<T>(arg: T) {}
39+
}
40+
41+
class Derived: Base {
42+
override func foo<T: P>(arg: T) {}
43+
}
3944
```
4045

41-
will now be diagnosed as an error.
42-
43-
Note: You can still use duplicate labels when declaring functions and
44-
subscripts, as long as the internal labels are different. For example:
45-
46-
```
47-
func foo(bar x: Int, bar y: Int) {}
48-
subscript(a x: Int, a y: Int) -> Int {}
49-
```
46+
will now be diagnosed as an error.
5047

5148
* [SR-6118][]:
5249

@@ -68,6 +65,28 @@ Swift Next
6865
Swift 5.1
6966
---------
7067

68+
* [SR-8974][]:
69+
70+
Duplicate tuple element labels are no longer allowed, because it leads
71+
to incorrect behavior. For example:
72+
73+
```
74+
let dupLabels: (foo: Int, foo: Int) = (foo: 1, foo: 2)
75+
76+
enum Foo { case bar(x: Int, x: Int) }
77+
let f: Foo = .bar(x: 0, x: 1)
78+
```
79+
80+
will now be diagnosed as an error.
81+
82+
Note: You can still use duplicate argument labels when declaring functions and
83+
subscripts, as long as the internal parameter names are different. For example:
84+
85+
```
86+
func foo(bar x: Int, bar y: Int) {}
87+
subscript(a x: Int, a y: Int) -> Int {}
88+
```
89+
7190
* [SE-0244][]:
7291

7392
Functions can now hide their concrete return type by declaring what protocols
@@ -7708,6 +7727,7 @@ Swift 1.0
77087727
[SR-2608]: <https://bugs.swift.org/browse/SR-2608>
77097728
[SR-2672]: <https://bugs.swift.org/browse/SR-2672>
77107729
[SR-2688]: <https://bugs.swift.org/browse/SR-2688>
7730+
[SR-4206]: <https://bugs.swift.org/browse/SR-4206>
77117731
[SR-4248]: <https://bugs.swift.org/browse/SR-4248>
77127732
[SR-5581]: <https://bugs.swift.org/browse/SR-5581>
77137733
[SR-5719]: <https://bugs.swift.org/browse/SR-5719>

benchmark/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ set(SWIFT_BENCH_MODULES
7979
single-source/DictionarySubscriptDefault
8080
single-source/DictionarySwap
8181
single-source/Diffing
82+
single-source/DiffingMyers
8283
single-source/DropFirst
8384
single-source/DropLast
8485
single-source/DropWhile
@@ -105,7 +106,6 @@ set(SWIFT_BENCH_MODULES
105106
single-source/Memset
106107
single-source/MonteCarloE
107108
single-source/MonteCarloPi
108-
single-source/Myers
109109
single-source/NSDictionaryCastToSwift
110110
single-source/NSError
111111
single-source/NSStringConversion

benchmark/single-source/Diffing.swift

Lines changed: 25 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -15,111 +15,55 @@ import TestsUtils
1515
let t: [BenchmarkCategory] = [.api]
1616
public let Diffing = [
1717
BenchmarkInfo(
18-
name: "DiffSame",
19-
runFunction: run_DiffSame,
18+
name: "Diffing.Same",
19+
runFunction: { diff($0, from: longPangram, to: longPangram) },
2020
tags: t,
21-
legacyFactor: 10),
21+
setUpFunction: { blackHole(longPangram) }),
2222
BenchmarkInfo(
23-
name: "DiffPangramToAlphabet",
24-
runFunction: run_DiffPangramToAlphabet,
23+
name: "Diffing.PangramToAlphabet",
24+
runFunction: { diff($0, from: longPangram, to: alphabets) },
2525
tags: t,
26-
legacyFactor: 10),
26+
setUpFunction: { blackHole((longPangram, alphabets)) }),
2727
BenchmarkInfo(
28-
name: "DiffPangrams",
29-
runFunction: run_DiffPangrams,
28+
name: "Diffing.Pangrams",
29+
runFunction: { diff($0, from:typingPangram, to: longPangram) },
3030
tags: t,
31-
legacyFactor: 10),
31+
setUpFunction: { blackHole((longPangram, typingPangram)) }),
3232
BenchmarkInfo(
33-
name: "DiffReversedAlphabets",
34-
runFunction: run_DiffReversedAlphabets,
33+
name: "Diffing.ReversedAlphabets",
34+
runFunction: { diff($0, from:alphabets, to: alphabetsReversed) },
3535
tags: t,
36-
legacyFactor: 10),
36+
setUpFunction: { blackHole((alphabets, alphabetsReversed)) }),
3737
BenchmarkInfo(
38-
name: "DiffReversedLorem",
39-
runFunction: run_DiffReversedLorem,
38+
name: "Diffing.ReversedLorem",
39+
runFunction: { diff($0, from: loremIpsum, to: loremReversed) },
4040
tags: t,
41-
legacyFactor: 10),
41+
setUpFunction: { blackHole((loremIpsum, loremReversed)) }),
4242
BenchmarkInfo(
43-
name: "DiffDisparate",
44-
runFunction: run_DiffDisparate,
43+
name: "Diffing.Disparate",
44+
runFunction: { diff($0, from: numbersAndSymbols, to: alphabets) },
4545
tags: t,
46-
legacyFactor: 10),
46+
setUpFunction: { blackHole((numbersAndSymbols, alphabets)) }),
4747
BenchmarkInfo(
48-
name: "DiffSimilar",
49-
runFunction: run_DiffSimilar,
48+
name: "Diffing.Similar",
49+
runFunction: { diff($0, from: unabridgedLorem, to: loremIpsum) },
5050
tags: t,
51-
legacyFactor: 10),
51+
setUpFunction: { blackHole((unabridgedLorem, loremIpsum)) }),
5252
]
5353

5454
let numbersAndSymbols = Array("0123456789`~!@#$%^&*()+=_-\"'?/<,>.\\{}'")
5555
let alphabets = Array("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
56-
let alphabetsReversed = Array("ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba")
56+
let alphabetsReversed = Array(alphabets.reversed())
5757
let longPangram = Array("This pangram contains four As, one B, two Cs, one D, thirty Es, six Fs, five Gs, seven Hs, eleven Is, one J, one K, two Ls, two Ms, eighteen Ns, fifteen Os, two Ps, one Q, five Rs, twenty-seven Ss, eighteen Ts, two Us, seven Vs, eight Ws, two Xs, three Ys, & one Z")
5858
let typingPangram = Array("The quick brown fox jumps over the lazy dog")
5959
let loremIpsum = Array("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
6060
let unabridgedLorem = Array("Lorem ipsum, quia dolor sit amet consectetur adipisci[ng] velit, sed quia non-numquam [do] eius modi tempora inci[di]dunt, ut labore et dolore magnam aliqua.")
61-
let loremReverse = Array(".auqila angam erolod te erobal tu tnudidicni ropmet domsuie od des ,tile gnicsipida rutetcesnoc ,tema tis rolod muspi meroL")
61+
let loremReversed = Array(loremIpsum.reversed())
6262

63-
64-
@inline(never)
65-
public func run_DiffSame(_ N: Int) {
66-
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
67-
for _ in 1...N {
68-
let _ = longPangram.difference(from: longPangram)
69-
}
70-
}
71-
}
72-
73-
@inline(never)
74-
public func run_DiffPangramToAlphabet(_ N: Int) {
75-
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
76-
for _ in 1...N {
77-
let _ = longPangram.difference(from: alphabets)
78-
}
79-
}
80-
}
81-
82-
@inline(never)
83-
public func run_DiffPangrams(_ N: Int) {
84-
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
85-
for _ in 1...N {
86-
let _ = longPangram.difference(from: typingPangram)
87-
}
88-
}
89-
}
90-
91-
@inline(never)
92-
public func run_DiffReversedAlphabets(_ N: Int) {
93-
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
94-
for _ in 1...N {
95-
let _ = alphabets.difference(from: alphabetsReversed)
96-
}
97-
}
98-
}
99-
100-
@inline(never)
101-
public func run_DiffReversedLorem(_ N: Int) {
102-
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
103-
for _ in 1...N {
104-
let _ = loremIpsum.difference(from: loremReverse)
105-
}
106-
}
107-
}
108-
109-
@inline(never)
110-
public func run_DiffDisparate(_ N: Int) {
111-
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
112-
for _ in 1...N {
113-
let _ = alphabets.difference(from: numbersAndSymbols)
114-
}
115-
}
116-
}
117-
118-
@inline(never)
119-
public func run_DiffSimilar(_ N: Int) {
63+
@inline(never) func diff(_ N: Int, from older: [Character], to newer: [Character]) {
12064
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
12165
for _ in 1...N {
122-
let _ = loremIpsum.difference(from: unabridgedLorem)
66+
blackHole(newer.difference(from: older))
12367
}
12468
}
12569
}

benchmark/single-source/Myers.swift renamed to benchmark/single-source/DiffingMyers.swift

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- Myers.swift -------------------------------------------===//
1+
//===--- DiffingMyers.swift -----------------------------------------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -12,18 +12,25 @@
1212

1313
import TestsUtils
1414

15-
public let Myers = [
16-
BenchmarkInfo(name: "Myers", runFunction: run_Myers, tags: [.algorithm]),
17-
]
15+
// The DiffingMyers test benchmarks Swift's performance running the algorithm
16+
// described in Myers (1986). The Diffing benchmark tracks the performance
17+
// of `Collection.difference(from:to:)`.
1818

19-
let loremShort = Array("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
20-
let loremLong = Array("Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos, qui ratione voluptatem sequi nesciunt, neque porro quisquam est, qui dolorem ipsum, quia dolor sit amet consectetur adipisci[ng] velit, sed quia non-numquam [do] eius modi tempora inci[di]dunt, ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum[d] exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur?")
19+
public let DiffingMyers = BenchmarkInfo(
20+
name: "Diffing.Myers.Similar",
21+
runFunction: run_Myers,
22+
tags: [.algorithm],
23+
setUpFunction: { blackHole((loremIpsum, unabridgedLorem)) })
24+
25+
26+
let loremIpsum = Array("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
27+
let unabridgedLorem = Array("Lorem ipsum, quia dolor sit amet consectetur adipisci[ng] velit, sed quia non-numquam [do] eius modi tempora inci[di]dunt, ut labore et dolore magnam aliqua.")
2128

2229
@inline(never)
2330
public func run_Myers(N: Int) {
2431
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
2532
for _ in 1...N {
26-
let _ = myers(from: loremShort, to: loremLong, using: ==)
33+
blackHole(myers(from: unabridgedLorem, to: loremIpsum, using: ==))
2734
}
2835
}
2936
}
@@ -193,4 +200,4 @@ fileprivate func myers<C,D>(
193200
return CollectionDifference(_formChanges(from: a, to: b, using:_descent(from: a, to: b)))!
194201
}
195202
}
196-
}
203+
}

benchmark/utils/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import DictionaryRemove
6767
import DictionarySubscriptDefault
6868
import DictionarySwap
6969
import Diffing
70+
import DiffingMyers
7071
import DropFirst
7172
import DropLast
7273
import DropWhile
@@ -93,7 +94,6 @@ import MapReduce
9394
import Memset
9495
import MonteCarloE
9596
import MonteCarloPi
96-
import Myers
9797
import NibbleSort
9898
import NIOChannelPipeline
9999
import NSDictionaryCastToSwift
@@ -243,6 +243,7 @@ registerBenchmark(DictionaryRemove)
243243
registerBenchmark(DictionarySubscriptDefault)
244244
registerBenchmark(DictionarySwap)
245245
registerBenchmark(Diffing)
246+
registerBenchmark(DiffingMyers)
246247
registerBenchmark(DropFirst)
247248
registerBenchmark(DropLast)
248249
registerBenchmark(DropWhile)
@@ -270,7 +271,6 @@ registerBenchmark(MapReduce)
270271
registerBenchmark(Memset)
271272
registerBenchmark(MonteCarloE)
272273
registerBenchmark(MonteCarloPi)
273-
registerBenchmark(Myers)
274274
registerBenchmark(NSDictionaryCastToSwift)
275275
registerBenchmark(NSErrorTest)
276276
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)

cmake/modules/AddSwift.cmake

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,10 +1512,9 @@ function(add_swift_host_library name)
15121512

15131513
if(NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
15141514
swift_install_in_component(TARGETS ${name}
1515-
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
1516-
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
1517-
RUNTIME DESTINATION bin
1518-
COMPONENT dev)
1515+
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT dev
1516+
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT dev
1517+
RUNTIME DESTINATION bin COMPONENT dev)
15191518
endif()
15201519

15211520
swift_is_installing_component(dev is_installing)
@@ -2139,10 +2138,15 @@ function(add_swift_target_library name)
21392138

21402139
if(sdk STREQUAL WINDOWS AND CMAKE_SYSTEM_NAME STREQUAL Windows)
21412140
swift_install_in_component(TARGETS ${name}-windows-${SWIFT_PRIMARY_VARIANT_ARCH}
2142-
RUNTIME DESTINATION "bin"
2143-
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${SWIFT_PRIMARY_VARIANT_ARCH}"
2144-
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${SWIFT_PRIMARY_VARIANT_ARCH}"
2145-
COMPONENT "${SWIFTLIB_INSTALL_IN_COMPONENT}"
2141+
RUNTIME
2142+
DESTINATION "bin"
2143+
COMPONENT "${SWIFTLIB_INSTALL_IN_COMPONENT}"
2144+
LIBRARY
2145+
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${SWIFT_PRIMARY_VARIANT_ARCH}"
2146+
COMPONENT "${SWIFTLIB_INSTALL_IN_COMPONENT}"
2147+
ARCHIVE
2148+
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${SWIFT_PRIMARY_VARIANT_ARCH}"
2149+
COMPONENT "${SWIFTLIB_INSTALL_IN_COMPONENT}"
21462150
PERMISSIONS ${file_permissions})
21472151
else()
21482152
swift_install_in_component(FILES "${UNIVERSAL_LIBRARY_NAME}"
@@ -2423,8 +2427,9 @@ function(add_swift_host_tool executable)
24232427
${ASHT_UNPARSED_ARGUMENTS})
24242428

24252429
swift_install_in_component(TARGETS ${executable}
2426-
RUNTIME DESTINATION bin
2427-
COMPONENT ${ASHT_SWIFT_COMPONENT})
2430+
RUNTIME
2431+
DESTINATION bin
2432+
COMPONENT ${ASHT_SWIFT_COMPONENT})
24282433

24292434
swift_is_installing_component(${ASHT_SWIFT_COMPONENT} is_installing)
24302435

docs/SIL.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5110,13 +5110,15 @@ cond_fail
51105110
`````````
51115111
::
51125112

5113-
sil-instruction ::= 'cond_fail' sil-operand
5113+
sil-instruction ::= 'cond_fail' sil-operand, string-literal
51145114

5115-
cond_fail %0 : $Builtin.Int1
5115+
cond_fail %0 : $Builtin.Int1, "failure reason"
51165116
// %0 must be of type $Builtin.Int1
51175117

51185118
This instruction produces a `runtime failure`_ if the operand is one.
51195119
Execution proceeds normally if the operand is zero.
5120+
The second operand is a static failure message, which is displayed by the
5121+
debugger in case the failure is triggered.
51205122

51215123
Terminators
51225124
~~~~~~~~~~~

docs/StandardLibraryProgrammersManual.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ TODO: Should this subsume or link to [AccessControlInStdlib.rst](https://github.
5050

5151
Optionals can be unwrapped with `!`, which triggers a trap on nil. Alternatively, they can be `.unsafelyUnwrapped()`, which will check and trap in debug builds of user code. Internal to the standard library is `._unsafelyUnwrappedUnchecked()` which will only check and trap in debug builds of the standard library itself. These correspond directly with `_precondition`, `_debugPrecondition`, and `_sanityCheck`. See [that section](#precondition) for details.
5252

53+
#### UnsafeBitCast and Casting References
54+
55+
In general `unsafeBitCast` should be avoided because it's correctness relies on subtle assumptions that will never be enforced, and it indicates a bug in Swift's type system that should be fixed. It's less bad for non-pointer trivial types. Pointer casting should go through one of the memory binding API instead as a last resort.
56+
57+
Reference casting is more interesting. References casting can include converting to an Optional reference and converting from a class constrained existential.
58+
59+
The regular `as` operator should be able to convert between reference types with full dynamic checking.
60+
61+
`unsafeDownCast` is just as capable, but is only dynamically checked in debug mode or if the cast requires runtime support.
62+
63+
`_unsafeUncheckedDowncast` is the same but is only dynamically checked in the stdlib asserts build, or if the cast requires runtime support.
64+
65+
`_unsafeReferenceCast` is only dynamically checked if the cast requires runtime support. Additionally, it does not impose any static `AnyObject` constraint on the incoming reference. This is useful in a generic context where the object-ness can be determined dynamically, as done in some bridged containers.
5366

5467
### Builtins
5568

include/swift/AST/ASTTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
//===----------------------------------------------------------------------===//
1717
SWIFT_TYPEID_NAMED(NominalTypeDecl *, NominalTypeDecl)
1818
SWIFT_TYPEID_NAMED(VarDecl *, VarDecl)
19+
SWIFT_TYPEID_NAMED(Decl *, Decl)
1920
SWIFT_TYPEID(Type)
2021
SWIFT_TYPEID(PropertyWrapperBackingPropertyInfo)
2122
SWIFT_TYPEID(PropertyWrapperTypeInfo)

0 commit comments

Comments
 (0)