Skip to content

Commit b40da13

Browse files
committed
Merge tag 'swift-DEVELOPMENT-SNAPSHOT-2019-07-10-a' into tensorflow-merge
Tag build swift-DEVELOPMENT-SNAPSHOT-2019-07-10-a
2 parents fe1b848 + e250a02 commit b40da13

File tree

701 files changed

+111027
-42655
lines changed

Some content is hidden

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

701 files changed

+111027
-42655
lines changed

Diff for: CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,8 @@ endif()
11001100
if(SWIFT_BUILD_STDLIB)
11011101
add_subdirectory(stdlib)
11021102
else()
1103+
add_subdirectory(stdlib/public/legacy_layouts)
1104+
11031105
# Some tools (e.g. swift-reflection-dump) rely on a host swiftReflection, so
11041106
# ensure we build that when building tools.
11051107
if(SWIFT_INCLUDE_TOOLS)

Diff for: benchmark/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ set(SWIFT_BENCH_MODULES
7878
single-source/DictionaryRemove
7979
single-source/DictionarySubscriptDefault
8080
single-source/DictionarySwap
81+
single-source/Diffing
8182
single-source/DropFirst
8283
single-source/DropLast
8384
single-source/DropWhile
@@ -104,6 +105,7 @@ set(SWIFT_BENCH_MODULES
104105
single-source/Memset
105106
single-source/MonteCarloE
106107
single-source/MonteCarloPi
108+
single-source/Myers
107109
single-source/NSDictionaryCastToSwift
108110
single-source/NSError
109111
single-source/NSStringConversion

Diff for: benchmark/single-source/AngryPhonebook.swift

+117-6
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,60 @@
1313
// This test is based on single-source/Phonebook, with
1414
// to test uppercase and lowercase ASCII string fast paths.
1515
import TestsUtils
16-
import Foundation
1716

18-
public let AngryPhonebook = BenchmarkInfo(
19-
name: "AngryPhonebook",
20-
runFunction: run_AngryPhonebook,
21-
tags: [.validation, .api, .String],
22-
legacyFactor: 7)
17+
let t: [BenchmarkCategory] = [.validation, .api, .String]
18+
19+
public let AngryPhonebook = [
20+
BenchmarkInfo(
21+
name: "AngryPhonebook",
22+
runFunction: run_AngryPhonebook,
23+
tags: t,
24+
legacyFactor: 7),
25+
26+
// Small String Workloads
27+
BenchmarkInfo(
28+
name: "AngryPhonebook.ASCII.Small",
29+
runFunction: { angryPhonebook($0, ascii) },
30+
tags: t,
31+
setUpFunction: { blackHole(ascii) }),
32+
BenchmarkInfo(
33+
name: "AngryPhonebook.Strasse.Small",
34+
runFunction: { angryPhonebook($0, strasse) },
35+
tags: t,
36+
setUpFunction: { blackHole(strasse) }),
37+
BenchmarkInfo(
38+
name: "AngryPhonebook.Armenian.Small",
39+
runFunction: { angryPhonebook($0, armenian) },
40+
tags: t,
41+
setUpFunction: { blackHole(armenian) }),
42+
BenchmarkInfo(
43+
name: "AngryPhonebook.Cyrillic.Small",
44+
runFunction: { angryPhonebook($0, cyrillic) },
45+
tags: t,
46+
setUpFunction: { blackHole(cyrillic) }),
47+
48+
// Regular String Workloads
49+
BenchmarkInfo(
50+
name: "AngryPhonebook.ASCII",
51+
runFunction: { angryPhonebook($0, precomposed: longASCII) },
52+
tags: t,
53+
setUpFunction: { blackHole(longASCII) }),
54+
BenchmarkInfo(
55+
name: "AngryPhonebook.Strasse",
56+
runFunction: { angryPhonebook($0, precomposed: longStrasse) },
57+
tags: t,
58+
setUpFunction: { blackHole(longStrasse) }),
59+
BenchmarkInfo(
60+
name: "AngryPhonebook.Armenian",
61+
runFunction: { angryPhonebook($0, precomposed: longArmenian) },
62+
tags: t,
63+
setUpFunction: { blackHole(longArmenian) }),
64+
BenchmarkInfo(
65+
name: "AngryPhonebook.Cyrillic",
66+
runFunction: { angryPhonebook($0, precomposed: longCyrillic) },
67+
tags: t,
68+
setUpFunction: { blackHole(longCyrillic) })
69+
]
2370

2471
let words = [
2572
"James", "John", "Robert", "Michael", "William", "David", "Richard", "Joseph",
@@ -39,3 +86,67 @@ public func run_AngryPhonebook(_ N: Int) {
3986
}
4087
}
4188
}
89+
90+
// Workloads for various scripts. Always 20 names for 400 pairings.
91+
// To keep the performance of various scripts roughly comparable, aim for
92+
// a total length of approximately 120 characters.
93+
// E.g.: `ascii.joined(separator: "").count == 124`
94+
// Every name should fit in 15-bytes UTF-8 encoded, to excercise the small
95+
// string optimization.
96+
// E.g.: `armenian.allSatisfy { $0._guts.isSmall } == true`
97+
98+
// Workload Size Statistics
99+
// SMALL | UTF-8 | UTF-16 | REGULAR | UTF-8 | UTF-16
100+
// ---------|-------|--------|--------------|---------|--------
101+
// ascii | 124 B | 248 B | longASCII | 6158 B | 12316 B
102+
// strasse | 140 B | 240 B | longStrasse | 6798 B | 11996 B
103+
// armenian | 232 B | 232 B | longArmenian | 10478 B | 11676 B
104+
// cyrillic | 238 B | 238 B | longCyrillic | 10718 B | 11916 B
105+
106+
let ascii = Array(words.prefix(20))
107+
// Pathological case, uppercase: ß -> SS
108+
let strasse = Array(repeating: "Straße", count: 20)
109+
110+
let armenian = [
111+
"Արմեն", "Աննա", "Հարութ", "Միքայել", "Մարիա", "Դավիթ", "Վարդան",
112+
"Նարինե", "Տիգրան", "Տաթևիկ", "Թագուհի", "Թամարա", "Ազնաուր", "Գրիգոր",
113+
"Կոմիտաս", "Հայկ", "Գառնիկ", "Վահրամ", "Վահագն", "Գևորգ"]
114+
115+
let cyrillic = [
116+
"Ульяна", "Аркадий", "Аня", "Даниил", "Дмитрий", "Эдуард", "Юрій", "Давид",
117+
"Анна", "Дмитрий", "Евгений", "Борис", "Ксения", "Артур", "Аполлон",
118+
"Соломон", "Николай", "Кристи", "Надежда", "Спартак"]
119+
120+
/// Precompose the phonebook into one large string of comma separated names.
121+
func phonebook(_ names: [String]) -> String {
122+
names.map { firstName in
123+
names.map { lastName in
124+
firstName + " " + lastName
125+
}.joined(separator: ", ")
126+
}.joined(separator: ", ")
127+
}
128+
129+
let longASCII = phonebook(ascii)
130+
let longStrasse = phonebook(strasse)
131+
let longArmenian = phonebook(armenian)
132+
let longCyrillic = phonebook(cyrillic)
133+
134+
@inline(never)
135+
public func angryPhonebook(_ N: Int, _ names: [String]) {
136+
assert(names.count == 20)
137+
// Permute the names.
138+
for _ in 1...N {
139+
for firstname in names {
140+
for lastname in names {
141+
blackHole((firstname.uppercased(), lastname.lowercased()))
142+
}
143+
}
144+
}
145+
}
146+
147+
@inline(never)
148+
public func angryPhonebook(_ N: Int, precomposed names: String) {
149+
for _ in 1...N {
150+
blackHole((names.uppercased(), names.lowercased()))
151+
}
152+
}

Diff for: benchmark/single-source/BinaryFloatingPointConversionFromBinaryInteger.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// This test checks performance of generic binary floating-point conversion from
1414
// a binary integer.
1515

16-
import Foundation
1716
import TestsUtils
1817

1918
#if swift(>=4.2)
@@ -110,7 +109,7 @@ extension MockBinaryInteger : BinaryInteger {
110109
var trailingZeroBitCount: Int {
111110
return _value.trailingZeroBitCount
112111
}
113-
112+
114113
func isMultiple(of other: MockBinaryInteger<T>) -> Bool {
115114
return _value.isMultiple(of: other._value)
116115
}
@@ -211,4 +210,3 @@ public func run_BinaryFloatingPointConversionFromBinaryInteger(_ N: Int) {
211210
}
212211

213212
#endif
214-

Diff for: benchmark/single-source/BinaryFloatingPointProperties.swift

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import Foundation
1413
import TestsUtils
1514

1615
public let BinaryFloatingPointPropertiesBinade = BenchmarkInfo(

Diff for: benchmark/single-source/BitCount.swift

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// This test checks performance of Swift bit count.
1414
// and mask operator.
1515
// rdar://problem/22151678
16-
import Foundation
1716
import TestsUtils
1817

1918
public let BitCount = BenchmarkInfo(

Diff for: benchmark/single-source/BucketSort.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@
1616
// https://github.com/raywenderlich/swift-algorithm-club/tree/master/Bucket%20Sort
1717
//
1818
// It sorts an array of generic `SortableItem`s. If the type of `sortingAlgo`
19-
// is not known to the call site at line 90, the `sort` method can not be
19+
// is not known to the call site at line 89, the `sort` method can not be
2020
// specialized to integer array sorting, which will lead to a huge performance
2121
// loss. Since `SortingAlgorithm` and `InsertionSort` are declared to be
22-
// `public` and the lines 89-91 can not be inlined in `bucketSort` (due to
22+
// `public` and the lines 88-90 can not be inlined in `bucketSort` (due to
2323
// inlining heuristic limitations), compiler without ExistentialSpecializer
2424
// optimization can not achieve this feat. With ExistentialSpecializer which
2525
// enables generic specialization recursively in a call chain, we're able to
26-
// specialize line 90 for `InsertionSort` on integers.
26+
// specialize line 89 for `InsertionSort` on integers.
2727

2828
import TestsUtils
29-
import Foundation
3029

3130
public let BucketSort = BenchmarkInfo(
3231
name: "BucketSort",
@@ -117,7 +116,8 @@ let items: [Int] = {
117116
let buckets: [Bucket<Int>] = {
118117
let bucketCount = 10
119118
let maxValue = items.max()!.convertToInt()
120-
let maxCapacity = Int(ceil(Double(maxValue + 1) / Double(bucketCount)))
119+
let maxCapacity = Int(
120+
(Double(maxValue + 1) / Double(bucketCount)).rounded(.up))
121121
return (0..<bucketCount).map { _ in Bucket<Int>(capacity: maxCapacity) }
122122
}()
123123

Diff for: benchmark/single-source/ByteSwap.swift

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// This test checks performance of Swift byte swap.
1414
// rdar://problem/22151907
1515

16-
import Foundation
1716
import TestsUtils
1817

1918
public let ByteSwap = BenchmarkInfo(

Diff for: benchmark/single-source/CString.swift

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import TestsUtils
1414
#if os(Linux)
1515
import Glibc
16+
#elseif os(Windows)
17+
import MSVCRT
1618
#else
1719
import Darwin
1820
#endif

Diff for: benchmark/single-source/Calculator.swift

-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import TestsUtils
14-
import Foundation
1514

1615
public let Calculator = BenchmarkInfo(
1716
name: "Calculator",
@@ -53,4 +52,3 @@ public func run_Calculator(_ N: Int) {
5352
}
5453
CheckResults(c == 0)
5554
}
56-

Diff for: benchmark/single-source/Diffing.swift

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
//===--- Diffing.swift ----------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 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+
import TestsUtils
14+
15+
let t: [BenchmarkCategory] = [.api]
16+
public let Diffing = [
17+
BenchmarkInfo(
18+
name: "DiffSame",
19+
runFunction: run_DiffSame,
20+
tags: t,
21+
legacyFactor: 10),
22+
BenchmarkInfo(
23+
name: "DiffPangramToAlphabet",
24+
runFunction: run_DiffPangramToAlphabet,
25+
tags: t,
26+
legacyFactor: 10),
27+
BenchmarkInfo(
28+
name: "DiffPangrams",
29+
runFunction: run_DiffPangrams,
30+
tags: t,
31+
legacyFactor: 10),
32+
BenchmarkInfo(
33+
name: "DiffReversedAlphabets",
34+
runFunction: run_DiffReversedAlphabets,
35+
tags: t,
36+
legacyFactor: 10),
37+
BenchmarkInfo(
38+
name: "DiffReversedLorem",
39+
runFunction: run_DiffReversedLorem,
40+
tags: t,
41+
legacyFactor: 10),
42+
BenchmarkInfo(
43+
name: "DiffDisparate",
44+
runFunction: run_DiffDisparate,
45+
tags: t,
46+
legacyFactor: 10),
47+
BenchmarkInfo(
48+
name: "DiffSimilar",
49+
runFunction: run_DiffSimilar,
50+
tags: t,
51+
legacyFactor: 10),
52+
]
53+
54+
let numbersAndSymbols = Array("0123456789`~!@#$%^&*()+=_-\"'?/<,>.\\{}'")
55+
let alphabets = Array("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
56+
let alphabetsReversed = Array("ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba")
57+
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")
58+
let typingPangram = Array("The quick brown fox jumps over the lazy dog")
59+
let loremIpsum = Array("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
60+
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")
62+
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) {
120+
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
121+
for _ in 1...N {
122+
let _ = loremIpsum.difference(from: unabridgedLorem)
123+
}
124+
}
125+
}

Diff for: benchmark/single-source/Hanoi.swift

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
// This test checks performance of Swift hanoi tower.
1414
// <rdar://problem/22151932>
15-
import Foundation
1615
import TestsUtils
1716

1817
public let Hanoi = BenchmarkInfo(

0 commit comments

Comments
 (0)