Skip to content

Commit 0f430e5

Browse files
committed
Merge branch 'master' into generics-manifesto-typo
2 parents 2dc279f + f0cb64d commit 0f430e5

File tree

1,350 files changed

+51373
-34920
lines changed

Some content is hidden

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

1,350 files changed

+51373
-34920
lines changed

CHANGELOG.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ CHANGELOG
2424
Swift 5.0
2525
---------
2626

27-
- [SR-419][]
27+
* Notable bug fix: unowned and unowned(unsafe) variables now support optional
28+
types.
2829

29-
In Swift 5 mode, when setting a property from within its own `didSet` or `willSet` observer, the observer will now only avoid being recursively called if the property is set on `self` (either implicitly or explicitly).
30+
* [SR-419][]
31+
32+
In Swift 5 mode, when setting a property from within its own `didSet` or
33+
`willSet` observer, the observer will now only avoid being recursively called
34+
if the property is set on `self` (either implicitly or explicitly).
3035

3136
For example:
3237
```swift
@@ -225,11 +230,10 @@ Swift 4.2
225230
* [SE-0143][]
226231

227232
The standard library types `Optional`, `Array`, `ArraySlice`,
228-
`ContiguousArray`, `Dictionary`, `DictionaryLiteral`, `Range`, and
229-
`ClosedRange` now conform to the `Hashable` protocol when their element or
230-
bound types (as the case may be) conform to `Hashable`. This makes
231-
synthesized `Hashable` implementations available for types that include stored
232-
properties of these types.
233+
`ContiguousArray`, `Dictionary`, `Range`, and `ClosedRange` now conform to the
234+
`Hashable` protocol when their element or bound types (as the case may be)
235+
conform to `Hashable`. This makes synthesized `Hashable` implementations
236+
available for types that include stored properties of these types.
233237

234238
* [SE-0196][]
235239

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
|**[Fedora 27](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_fedora_27.json)** | x86_64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-fedora-27/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-fedora-27)|
1919
|**[Ubuntu 16.04](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_ubuntu_16_04.json)** | x86_64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04)|
2020
|**[Ubuntu 16.04 (TensorFlow)](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_ubuntu_16_04_tensorflow.json)** | x86_64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-tensorflow/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-tensorflow)|
21-
|**[Ubuntu 16.04 ](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/ppc64le_16_04.json)** | PPC64LE |[![Build Status](https://ci-external.swift.org/job/oss-swift-4.1-RA-linux-ubuntu-16.04-ppc64le/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-4.1-RA-linux-ubuntu-16.04-ppc64le)|
21+
|**[Ubuntu 16.04 ](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/ppc64le_ubuntu_16_04.json)** | PPC64LE |[![Build Status](https://ci-external.swift.org/job/oss-swift-4.1-RA-linux-ubuntu-16.04-ppc64le/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-4.1-RA-linux-ubuntu-16.04-ppc64le)|
22+
|**[Ubuntu 16.04 ](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/aarch64_ubuntu_16.04.json)** | AArch64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-aarch64/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-aarch64)|
23+
|**[Ubuntu 16.04 (Android)](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_ubuntu_16_04_LTS_android.json)** | x86_64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android)|
24+
2225

2326
**Welcome to Swift!**
2427

@@ -66,7 +69,7 @@ supported host development operating systems.
6669

6770
#### macOS
6871

69-
To build for macOS, you need [Xcode 10 beta](https://developer.apple.com/xcode/downloads/).
72+
To build for macOS, you need [Xcode 10 beta 3](https://developer.apple.com/xcode/downloads/).
7073
The required version of Xcode changes frequently, and is often a beta release.
7174
Check this document or the host information on <https://ci.swift.org> for the
7275
current required version.

benchmark/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ set(SWIFT_BENCH_MODULES
6565
single-source/DictTest4
6666
single-source/DictTest4Legacy
6767
single-source/DictionaryBridge
68+
single-source/DictionaryBridgeToObjC
69+
single-source/DictionaryCompactMapValues
6870
single-source/DictionaryCopy
6971
single-source/DictionaryGroup
7072
single-source/DictionaryKeysContains

benchmark/README.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,38 @@ Using the Benchmark Driver
8686
* `--num-samples`
8787
* Control the number of samples to take for each test
8888
* `--list`
89-
* Print a list of available tests
89+
* Print a list of available tests matching specified criteria
90+
* `--tags`
91+
* Run tests that are labeled with specified [tags](https://github.com/apple/swift/blob/master/benchmark/utils/TestsUtils.swift#L19)
92+
(comma separated list); multiple tags are interpreted as logical AND, i.e.
93+
run only test that are labeled with all the supplied tags
94+
* `--skip-tags`
95+
* Don't run tests that are labeled with any of the specified tags (comma
96+
separated list); default value: `skip,unstable`; to get complete list of
97+
tests, specify empty `--skip-tags=`
98+
9099

91100
### Examples
92101

93102
* `$ ./Benchmark_O --num-iters=1 --num-samples=1`
94103
* `$ ./Benchmark_Onone --list`
95104
* `$ ./Benchmark_Osize Ackermann`
105+
* `$ ./Benchmark_O --tags=Dictionary`
106+
* `$ ./Benchmark_O --skip-tags=unstable,skip,validation`
96107

97108
### Note
98109
As a shortcut, you can also refer to benchmarks by their ordinal numbers.
99-
The regular `--list` option does not provide these, but you can run:
100-
* `$ ./Benchmark_O --list --run-all | tail -n +2 | nl`
101-
You can use ordinal numbers instead of test names like this:
110+
These are printed out together with benchmark names and tags using the
111+
`--list` parameter. For a complete list of all available performance tests run
112+
* `$ ./Benchmark_O --list --skip-tags=`
113+
114+
You can use test numbers instead of test names like this:
102115
* `$ ./Benchmark_O 1 42`
103116
* `$ ./Benchmark_Driver run 1 42`
104117

118+
Test numbers are not stable in the long run, adding and removing tests from the
119+
benchmark suite will reorder them, but they are stable for a given build.
120+
105121
Using the Harness Generator
106122
---------------------------
107123

@@ -186,3 +202,21 @@ public func run_YourTestName(N: Int) {
186202

187203
The current set of tags are defined by the `BenchmarkCategory` enum in
188204
`TestsUtils.swift` .
205+
206+
Testing the Benchmark Drivers
207+
-----------------------------
208+
When working on tests, after the initial build
209+
````
210+
swift-source$ ./swift/utils/build-script -R -B
211+
````
212+
you can rebuild just the benchmarks:
213+
````
214+
swift-source$ export SWIFT_BUILD_DIR=`pwd`/build/Ninja-ReleaseAssert/swift-macosx-x86_64
215+
swift-source$ ninja -C ${SWIFT_BUILD_DIR} swift-benchmark-macosx-x86_64
216+
````
217+
218+
When modifying the testing infrastructure, you should verify that your changes
219+
pass all the tests:
220+
````
221+
swift-source$ ./llvm/utils/lit/lit.py -sv ${SWIFT_BUILD_DIR}/test-macosx-x86_64/benchmark
222+
````

benchmark/scripts/Benchmark_Driver

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,28 +118,32 @@ def instrument_test(driver_path, test, num_samples):
118118
return avg_test_output
119119

120120

121-
BENCHMARK_OUTPUT_RE = re.compile('([^,]+),')
122-
123-
124121
def get_tests(driver_path, args):
125122
"""Return a list of available performance tests"""
126123
driver = ([driver_path, '--list'])
124+
# Use tab delimiter for easier parsing to override the default comma.
125+
# (The third 'column' is always comma-separated list of tags in square
126+
# brackets -- currently unused here.)
127+
driver.append('--delim=\t')
127128
if args.benchmarks or args.filters:
128-
driver.append('--run-all')
129-
tests = []
130-
for l in subprocess.check_output(driver).split("\n")[1:]:
131-
m = BENCHMARK_OUTPUT_RE.match(l)
132-
if m is None:
133-
continue
134-
tests.append(m.group(1))
129+
driver.append('--skip-tags=') # list all tests, don't skip any tags
130+
index_name_pairs = [
131+
line.split('\t')[:2] for line in
132+
subprocess.check_output(driver).split('\n')[1:-1]
133+
]
134+
indices, names = zip(*index_name_pairs) # unzip list of pairs into 2 lists
135135
if args.filters:
136136
regexes = [re.compile(pattern) for pattern in args.filters]
137137
return sorted(list(set([name for pattern in regexes
138-
for name in tests if pattern.match(name)])))
138+
for name in names if pattern.match(name)])))
139139
if not args.benchmarks:
140-
return tests
141-
tests.extend(map(str, range(1, len(tests) + 1))) # ordinal numbers
142-
return sorted(list(set(tests).intersection(set(args.benchmarks))))
140+
return names
141+
benchmarks = set(args.benchmarks)
142+
index_to_name = dict(index_name_pairs)
143+
indexed_names = [index_to_name[i]
144+
for i in benchmarks.intersection(set(indices))]
145+
return sorted(list(
146+
benchmarks.intersection(set(names)).union(indexed_names)))
143147

144148

145149
def get_current_git_branch(git_repo_path):

benchmark/single-source/ByteSwap.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public let ByteSwap = BenchmarkInfo(
2424
// a naive O(n) implementation of byteswap.
2525
@inline(never)
2626
func byteswap_n(_ a: UInt64) -> UInt64 {
27-
#if swift(>=4)
2827
return ((a & 0x00000000000000FF) &<< 56) |
2928
((a & 0x000000000000FF00) &<< 40) |
3029
((a & 0x0000000000FF0000) &<< 24) |
@@ -33,16 +32,6 @@ func byteswap_n(_ a: UInt64) -> UInt64 {
3332
((a & 0x0000FF0000000000) &>> 24) |
3433
((a & 0x00FF000000000000) &>> 40) |
3534
((a & 0xFF00000000000000) &>> 56)
36-
#else
37-
return ((a & 0x00000000000000FF) << 56) |
38-
((a & 0x000000000000FF00) << 40) |
39-
((a & 0x0000000000FF0000) << 24) |
40-
((a & 0x00000000FF000000) << 8) |
41-
((a & 0x000000FF00000000) >> 8) |
42-
((a & 0x0000FF0000000000) >> 24) |
43-
((a & 0x00FF000000000000) >> 40) |
44-
((a & 0xFF00000000000000) >> 56)
45-
#endif
4635
}
4736

4837
// a O(logn) implementation of byteswap.

benchmark/single-source/CharacterProperties.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,3 +453,6 @@ public func run_CharacterPropertiesPrecomputed(_ N: Int) {
453453

454454
// TODO: run_CharacterPropertiesComputed
455455

456+
// Local Variables:
457+
// eval: (read-only-mode 1)
458+
// End:

benchmark/single-source/CharacterProperties.swift.gyb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,6 @@ public func run_CharacterPropertiesPrecomputed(_ N: Int) {
175175

176176
// TODO: run_CharacterPropertiesComputed
177177

178+
// ${'Local Variables'}:
179+
// eval: (read-only-mode 1)
180+
// End:
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//===--- DictionaryBridgeToObjC.swift -------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
// Performance benchmark for common operations on Dictionary values bridged to
14+
// NSDictionary.
15+
import TestsUtils
16+
#if _runtime(_ObjC)
17+
import Foundation
18+
19+
public let DictionaryBridgeToObjC = [
20+
BenchmarkInfo(
21+
name: "DictionaryBridgeToObjC_Bridge",
22+
runFunction: run_DictionaryBridgeToObjC_BridgeToObjC,
23+
tags: [.validation, .api, .Dictionary, .bridging]),
24+
BenchmarkInfo(
25+
name: "DictionaryBridgeToObjC_Access",
26+
runFunction: run_DictionaryBridgeToObjC_Access,
27+
tags: [.validation, .api, .Dictionary, .bridging]),
28+
BenchmarkInfo(
29+
name: "DictionaryBridgeToObjC_BulkAccess",
30+
runFunction: run_DictionaryBridgeToObjC_BulkAccess,
31+
tags: [.validation, .api, .Dictionary, .bridging])
32+
]
33+
34+
let numbers: [String: Int] = [
35+
"one": 1,
36+
"two": 2,
37+
"three": 3,
38+
"four": 4,
39+
"five": 5,
40+
"six": 6,
41+
"seven": 7,
42+
"eight": 8,
43+
"nine": 9,
44+
"ten": 10,
45+
"eleven": 11,
46+
"twelve": 12,
47+
"thirteen": 13,
48+
"fourteen": 14,
49+
"fifteen": 15,
50+
"sixteen": 16,
51+
"seventeen": 17,
52+
"eighteen": 18,
53+
"nineteen": 19,
54+
"twenty": 20
55+
]
56+
57+
@inline(never)
58+
public func run_DictionaryBridgeToObjC_BridgeToObjC(_ N: Int) {
59+
for _ in 1 ... 100 * N {
60+
blackHole(numbers as NSDictionary)
61+
}
62+
}
63+
64+
@inline(never)
65+
public func run_DictionaryBridgeToObjC_Access(_ N: Int) {
66+
let d = numbers as NSDictionary
67+
blackHole(d.object(forKey: "one")) // Force bridging of contents
68+
for _ in 1 ... 100 * N {
69+
for key in numbers.keys {
70+
CheckResults(identity(d).object(forKey: key) != nil)
71+
}
72+
}
73+
}
74+
75+
@inline(never)
76+
public func run_DictionaryBridgeToObjC_BulkAccess(_ N: Int) {
77+
let d = numbers as NSDictionary
78+
for _ in 1 ... 100 * N {
79+
let d2 = NSDictionary(dictionary: identity(d))
80+
CheckResults(d2.count == d.count)
81+
}
82+
}
83+
84+
#else // !_runtime(ObjC)
85+
public let DictionaryBridgeToObjC: [BenchmarkInfo] = []
86+
#endif
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Dictionary compact map values benchmark
2+
import TestsUtils
3+
4+
public let DictionaryCompactMapValues = [
5+
BenchmarkInfo(name: "DictionaryCompactMapValuesOfNilValue", runFunction: run_DictionaryCompactMapValuesOfNilValue, tags: [.validation, .api, .Dictionary]),
6+
BenchmarkInfo(name: "DictionaryCompactMapValuesOfCastValue", runFunction: run_DictionaryCompactMapValuesOfCastValue, tags: [.validation, .api, .Dictionary]),
7+
]
8+
9+
@inline(never)
10+
public func run_DictionaryCompactMapValuesOfNilValue(_ N: Int) {
11+
let size = 100
12+
var dict = [Int: Int?](minimumCapacity: size)
13+
14+
// Fill Dictionary
15+
for i in 1...size {
16+
if i % 2 == 0 {
17+
dict[i] = nil
18+
} else {
19+
dict[i] = i
20+
}
21+
}
22+
CheckResults(dict.count == size / 2)
23+
24+
var refDict = [Int: Int]()
25+
for i in stride(from: 1, to: 100, by: 2) {
26+
refDict[i] = i
27+
}
28+
29+
var newDict = [Int: Int]()
30+
for _ in 1...1000*N {
31+
newDict = dict.compactMapValues({$0})
32+
if newDict != refDict {
33+
break
34+
}
35+
}
36+
37+
CheckResults(newDict == refDict)
38+
}
39+
40+
@inline(never)
41+
public func run_DictionaryCompactMapValuesOfCastValue(_ N: Int) {
42+
let size = 100
43+
var dict = [Int: String](minimumCapacity: size)
44+
45+
// Fill Dictionary
46+
for i in 1...size {
47+
if i % 2 == 0 {
48+
dict[i] = "dummy"
49+
} else {
50+
dict[i] = "\(i)"
51+
}
52+
}
53+
54+
CheckResults(dict.count == size)
55+
56+
var refDict = [Int: Int]()
57+
for i in stride(from: 1, to: 100, by: 2) {
58+
refDict[i] = i
59+
}
60+
61+
var newDict = [Int: Int]()
62+
for _ in 1...1000*N {
63+
newDict = dict.compactMapValues(Int.init)
64+
if newDict != refDict {
65+
break
66+
}
67+
}
68+
69+
CheckResults(newDict == refDict)
70+
}
71+

benchmark/single-source/DropFirst.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,7 @@ public func run_DropFirstArrayLazy(_ N: Int) {
237237
CheckResults(result == sumCount)
238238
}
239239
}
240+
241+
// Local Variables:
242+
// eval: (read-only-mode 1)
243+
// End:

benchmark/single-source/DropFirst.swift.gyb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,7 @@ public func run_DropFirst${Name}(_ N: Int) {
6565
}
6666
}
6767
% end
68+
69+
// ${'Local Variables'}:
70+
// eval: (read-only-mode 1)
71+
// End:

benchmark/single-source/DropLast.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,7 @@ public func run_DropLastArrayLazy(_ N: Int) {
236236
CheckResults(result == sumCount)
237237
}
238238
}
239+
240+
// Local Variables:
241+
// eval: (read-only-mode 1)
242+
// End:

0 commit comments

Comments
 (0)