Skip to content

Commit 112acd5

Browse files
authored
---
yaml --- r: 286327 b: refs/heads/master-next c: d6f44cc h: refs/heads/master i: 286325: 002ef6c 286323: 922e35a 286319: 55e486c
1 parent ab8e88a commit 112acd5

File tree

214 files changed

+3995
-1364
lines changed

Some content is hidden

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

214 files changed

+3995
-1364
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: a67ffadd758dfc7a0f10a8afde063b8864663208
3-
refs/heads/master-next: 1dbb4830c5ca465b4ee2de334f78f96db31f41b6
3+
refs/heads/master-next: d6f44ccdd8cd92daa48a3829ac6e961e31357926
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/CMakeLists.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ else()
598598
# FIXME: Only matches v6l/v7l - by far the most common variants
599599
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv6l")
600600
set(SWIFT_HOST_VARIANT_ARCH_default "armv6")
601-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l")
601+
elseif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "armv7l|armv7-a")
602602
set(SWIFT_HOST_VARIANT_ARCH_default "armv7")
603603
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
604604
set(SWIFT_HOST_VARIANT_ARCH_default "x86_64")
@@ -998,17 +998,17 @@ if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
998998
else()
999999
set(SOURCEKIT_RUNTIME_DIR lib)
10001000
endif()
1001-
swift_install_in_component(sourcekit-inproc
1002-
FILES
1001+
swift_install_in_component(FILES
10031002
$<TARGET_FILE:dispatch>
10041003
$<TARGET_FILE:BlocksRuntime>
1005-
DESTINATION ${SOURCEKIT_RUNTIME_DIR})
1004+
DESTINATION ${SOURCEKIT_RUNTIME_DIR}
1005+
COMPONENT sourcekit-inproc)
10061006
if(SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS)
1007-
swift_install_in_component(sourcekit-inproc
1008-
FILES
1007+
swift_install_in_component(FILES
10091008
$<TARGET_LINKER_FILE:dispatch>
10101009
$<TARGET_LINKER_FILE:BlocksRuntime>
1011-
DESTINATION lib)
1010+
DESTINATION lib
1011+
COMPONENT sourcekit-inproc)
10121012
endif()
10131013

10141014

@@ -1083,9 +1083,9 @@ endif()
10831083

10841084
add_subdirectory(cmake/modules)
10851085

1086-
swift_install_in_component(license
1087-
FILES "LICENSE.txt"
1088-
DESTINATION "share/swift")
1086+
swift_install_in_component(FILES "LICENSE.txt"
1087+
DESTINATION "share/swift"
1088+
COMPONENT license)
10891089

10901090
# Add a documentation target so that documentation shows up in the
10911091
# Xcode project.

branches/master-next/apinotes/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ add_custom_target("copy_apinotes"
3131
# This is treated as an OPTIONAL target because if we don't build the SDK
3232
# overlay, the files will be missing anyway. It also allows us to build
3333
# single overlays without installing the API notes.
34-
swift_install_in_component(sdk-overlay
35-
DIRECTORY "${output_dir}"
36-
DESTINATION "lib/swift/"
37-
OPTIONAL)
34+
swift_install_in_component(DIRECTORY "${output_dir}"
35+
DESTINATION "lib/swift/"
36+
COMPONENT sdk-overlay
37+
OPTIONAL)

branches/master-next/benchmark/single-source/Breadcrumbs.swift

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,6 @@ extension String {
4545
}
4646
}
4747

48-
let seed = 0x12345678
49-
50-
/// A linear congruential PRNG.
51-
struct LCRNG: RandomNumberGenerator {
52-
private var state: UInt64
53-
54-
init(seed: Int) {
55-
state = UInt64(truncatingIfNeeded: seed)
56-
for _ in 0..<10 { _ = next() }
57-
}
58-
59-
mutating func next() -> UInt64 {
60-
state = 2862933555777941757 &* state &+ 3037000493
61-
return state
62-
}
63-
}
64-
6548
extension Collection {
6649
/// Returns a randomly ordered array of random non-overlapping index ranges
6750
/// that cover this collection entirely.
@@ -254,7 +237,7 @@ class UTF16ToIdx: BenchmarkBase {
254237

255238
override func setUp() {
256239
super.setUp()
257-
var rng = LCRNG(seed: seed)
240+
var rng = SplitMix64(seed: 42)
258241
let range = 0 ..< inputString.utf16.count
259242
inputOffsets = Array(range.shuffled(using: &rng).prefix(count))
260243
}
@@ -286,7 +269,7 @@ class IdxToUTF16: BenchmarkBase {
286269

287270
override func setUp() {
288271
super.setUp()
289-
var rng = LCRNG(seed: seed)
272+
var rng = SplitMix64(seed: 42)
290273
inputIndices = Array(inputString.indices.shuffled(using: &rng).prefix(count))
291274
}
292275

@@ -318,7 +301,7 @@ class UTF16ToIdxRange: BenchmarkBase {
318301

319302
override func setUp() {
320303
super.setUp()
321-
var rng = LCRNG(seed: seed)
304+
var rng = SplitMix64(seed: 42)
322305
inputOffsets = (
323306
0 ..< inputString.utf16.count
324307
).randomIndexRanges(count: count, using: &rng)
@@ -352,7 +335,7 @@ class IdxToUTF16Range: BenchmarkBase {
352335

353336
override func setUp() {
354337
super.setUp()
355-
var rng = LCRNG(seed: seed)
338+
var rng = SplitMix64(seed: 42)
356339
inputIndices = self.inputString.randomIndexRanges(count: count, using: &rng)
357340
}
358341

@@ -384,7 +367,7 @@ class CopyUTF16CodeUnits: BenchmarkBase {
384367

385368
override func setUp() {
386369
super.setUp()
387-
var rng = LCRNG(seed: seed)
370+
var rng = SplitMix64(seed: 42)
388371
inputIndices = (
389372
0 ..< inputString.utf16.count
390373
).randomIndexRanges(count: count, using: &rng)
@@ -425,7 +408,7 @@ class MutatedUTF16ToIdx: BenchmarkBase {
425408

426409
override func setUp() {
427410
super.setUp()
428-
var generator = LCRNG(seed: seed)
411+
var generator = SplitMix64(seed: 42)
429412
let range = 0 ..< inputString.utf16.count
430413
inputOffsets = Array(range.shuffled(using: &generator).prefix(count))
431414
}
@@ -469,7 +452,7 @@ class MutatedIdxToUTF16: BenchmarkBase {
469452

470453
override func setUp() {
471454
super.setUp()
472-
var rng = LCRNG(seed: seed)
455+
var rng = SplitMix64(seed: 42)
473456
inputIndices = Array(inputString.indices.shuffled(using: &rng).prefix(count))
474457
}
475458

Lines changed: 41 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- BucketSort.swift ----------------------------------------------------===//
1+
//===--- BucketSort.swift -------------------------------------------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -9,21 +9,21 @@
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12-
// Adapted from the original implementation:
12+
// This benchmark demonstrates the benefits of ExistentialSpecializer
13+
// optimization pass. It's a generic version of the classic BucketSort algorithm
14+
// adapted from an original implementation from the Swift Algorithm Club.
15+
// See https://en.wikipedia.org/wiki/Bucket_sort and
1316
// https://github.com/raywenderlich/swift-algorithm-club/tree/master/Bucket%20Sort
14-
// Issue: https://github.com/raywenderlich/swift-algorithm-club/issues/863
15-
16-
// This benchmark implements the classical BucketSort algorithm described at
17-
// https://en.wikipedia.org/wiki/Bucket_sort. The implementation allows for an
18-
// array of generic type of "SortableItem" to be sorted. Unfortunately, if
19-
// ``sortingAlgo'' type is not known for the callsite in line 84, then the
20-
// ``sort'' method can not be specialized to integer array sorting, which will
21-
// lead to a huge performance loss. Since SortingAlgorithm and InsertionSort are
22-
// declared to be ``public'' and that lines 83-85 can not be inlined in
23-
// BucketSortImpl (due to inlining heuristic limitations), today swift
24-
// compiler (without ExistentialSpecializer) can not achieve this feat. With
25-
// ExistentialSpecializer which enables generic specialization recursively in a
26-
// call chain, we are able to specialize line 84 for InsertionSort on integers.
17+
//
18+
// 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
20+
// specialized to integer array sorting, which will lead to a huge performance
21+
// loss. Since `SortingAlgorithm` and `InsertionSort` are declared to be
22+
// `public` and the lines 89-91 can not be inlined in `bucketSort` (due to
23+
// inlining heuristic limitations), compiler without ExistentialSpecializer
24+
// optimization can not achieve this feat. With ExistentialSpecializer which
25+
// enables generic specialization recursively in a call chain, we're able to
26+
// specialize line 90 for `InsertionSort` on integers.
2727

2828
import TestsUtils
2929
import Foundation
@@ -32,21 +32,25 @@ public let BucketSort = BenchmarkInfo(
3232
name: "BucketSort",
3333
runFunction: run_BucketSort,
3434
tags: [.validation, .algorithm],
35-
setUpFunction: { buildWorkload() },
36-
legacyFactor: 10)
35+
setUpFunction: { blackHole(buckets) }
36+
)
3737

3838
public protocol IntegerConvertible {
3939
func convertToInt() -> Int
4040
}
41+
4142
extension Int: IntegerConvertible, SortableItem {
4243
public func convertToInt() -> Int {
4344
return self
4445
}
4546
}
47+
4648
public protocol SortableItem: IntegerConvertible, Comparable { }
49+
4750
public protocol SortingAlgorithm {
4851
func sort<T: SortableItem>(_ items: [T]) -> [T]
4952
}
53+
5054
public struct InsertionSort: SortingAlgorithm {
5155
public func sort<T: SortableItem>(_ items: [T]) -> [T] {
5256
var sortedItems = items
@@ -62,12 +66,14 @@ public struct InsertionSort: SortingAlgorithm {
6266
return sortedItems
6367
}
6468
}
69+
6570
func distribute<T>(_ item: T, bucketArray: inout [Bucket<T>]) {
6671
let val = item.convertToInt()
6772
let capacity = bucketArray.first!.capacity
6873
let index = val / capacity
6974
bucketArray[index].add(item)
7075
}
76+
7177
struct Bucket<T: SortableItem> {
7278
var items: [T]
7379
let capacity: Int
@@ -84,7 +90,10 @@ struct Bucket<T: SortableItem> {
8490
return sortingAlgo.sort(items)
8591
}
8692
}
87-
func BucketSortImpl<T>(_ items: [T], sortingAlgorithm: SortingAlgorithm, bucketArray: [Bucket<T>]) -> [T] {
93+
94+
func bucketSort<T>(
95+
_ items: [T], sortingAlgorithm: SortingAlgorithm, bucketArray: [Bucket<T>]
96+
) -> [T] {
8897
var copyBucketArray = bucketArray
8998
for item in items {
9099
distribute(item, bucketArray: &copyBucketArray)
@@ -95,45 +104,28 @@ func BucketSortImpl<T>(_ items: [T], sortingAlgorithm: SortingAlgorithm, bucketA
95104
}
96105
return sortedArray
97106
}
98-
func isArraySorted(_ arr: [Int]) -> Bool {
99-
var idx = 0
100-
while idx < (arr.count - 1) {
101-
if arr[idx] > arr[idx+1] {
102-
return false
103-
}
104-
idx += 1
105-
}
106-
return true
107+
108+
func isAscending(_ a: [Int]) -> Bool {
109+
return zip(a, a.dropFirst()).allSatisfy(<=)
107110
}
108-
let NUMITEMS = 2500
109-
let MAXBUCKETSIZE = 1000
110-
let NUMBUCKETS: Int = 10
111+
111112
let items: [Int] = {
112-
var array: [Int]? = [Int]()
113-
for _ in 0..<NUMITEMS {
114-
array!.append(Int.random(in: 0..<MAXBUCKETSIZE))
115-
}
116-
return array!
113+
var g = SplitMix64(seed: 42)
114+
return (0..<10_000).map {_ in Int.random(in: 0..<1000, using: &g) }
117115
}()
118116

119117
let buckets: [Bucket<Int>] = {
120-
let val = (items.max()?.convertToInt())! + 1
121-
let maxCapacity = Int( ceil( Double(val) / Double(NUMBUCKETS)))
122-
var bucketArray = [Bucket<Int>]()
123-
for _ in 0..<NUMBUCKETS {
124-
bucketArray.append(Bucket<Int>(capacity: maxCapacity))
125-
}
126-
return bucketArray
118+
let bucketCount = 10
119+
let maxValue = items.max()!.convertToInt()
120+
let maxCapacity = Int(ceil(Double(maxValue + 1) / Double(bucketCount)))
121+
return (0..<bucketCount).map { _ in Bucket<Int>(capacity: maxCapacity) }
127122
}()
123+
128124
@inline(never)
129125
func run_BucketSort(_ N : Int) {
130126
for _ in 0..<N {
131-
let sortedArray = BucketSortImpl(items, sortingAlgorithm: InsertionSort(), bucketArray: buckets)
132-
CheckResults(isArraySorted(sortedArray))
127+
let sortedArray = bucketSort(
128+
items, sortingAlgorithm: InsertionSort(), bucketArray: buckets)
129+
CheckResults(isAscending(sortedArray))
133130
}
134131
}
135-
@inline(never)
136-
func buildWorkload() {
137-
blackHole(items)
138-
blackHole(buckets)
139-
}

branches/master-next/benchmark/single-source/ObjectiveCBridging.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public let ObjectiveCBridging = [
7373
BenchmarkInfo(name: "ObjectiveCBridgeFromNSDateComponents",
7474
runFunction: run_ObjectiveCBridgeFromNSDateComponents, tags: t,
7575
setUpFunction: setup_dateComponents),
76+
BenchmarkInfo(name: "ObjectiveCBridgeASCIIStringFromFile",
77+
runFunction: run_ASCIIStringFromFile, tags: ts,
78+
setUpFunction: setup_ASCIIStringFromFile),
7679
]
7780

7881
#if _runtime(_ObjC)
@@ -709,3 +712,35 @@ public func run_ObjectiveCBridgeFromNSDateComponents(_ N: Int) {
709712
}
710713
#endif
711714
}
715+
716+
var ASCIIStringFromFile:String? = nil
717+
public func setup_ASCIIStringFromFile() {
718+
#if _runtime(_ObjC)
719+
let url:URL
720+
if #available(OSX 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *) {
721+
url = FileManager.default.temporaryDirectory.appendingPathComponent(
722+
"sphinx.txt"
723+
)
724+
} else {
725+
url = URL(fileURLWithPath: "/tmp/sphinx.txt")
726+
}
727+
var str = "Sphinx of black quartz judge my vow"
728+
str = Array(repeating: str, count: 100).joined()
729+
try? str.write(
730+
to: url,
731+
atomically: true,
732+
encoding: .ascii
733+
)
734+
ASCIIStringFromFile = try! String(contentsOf: url, encoding: .ascii)
735+
#endif
736+
}
737+
738+
@inline(never)
739+
public func run_ASCIIStringFromFile(_ N: Int) {
740+
#if _runtime(_ObjC)
741+
for _ in 0 ..< N {
742+
blackHole((ASCIIStringFromFile! + "").utf8.count)
743+
}
744+
#endif
745+
}
746+

0 commit comments

Comments
 (0)