Skip to content

Commit d5b2ef5

Browse files
authored
Merge pull request #7 from apple/master
merge
2 parents 0089ad4 + 5f2f440 commit d5b2ef5

File tree

1,025 files changed

+35584
-16113
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,025 files changed

+35584
-16113
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,24 @@ CHANGELOG
2323
Swift 5.0
2424
---------
2525

26+
* Public classes may now have internal `required` initializers. The rule for
27+
`required` initializers is that they must be available everywhere the class
28+
can be subclassed, but previously we said that `required` initializers on
29+
public classes needed to be public themselves. (This limitation is a holdover
30+
from before the introduction of the open/public distinction in Swift 3.)
31+
2632
* C macros containing casts are no longer imported to Swift if the type in the
2733
cast is unavailable or deprecated, or produces some other diagnostic when
2834
referenced. (These macros were already only imported under very limited
2935
circumstances with very simple values, so this is unlikely to affect
3036
real-world code.)
3137

38+
* [SE-0143][]
39+
40+
Runtime query of conditional conformances is now implemented. Therefore,
41+
a dynamic cast such as `value as? P`, where the dynamic type of `value`
42+
conditionally conforms to `P`, will succeed when the conditional
43+
requirements are met.
3244

3345
Swift 4.1
3446
---------

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
cmake_minimum_required(VERSION 3.4.3)
22

3+
# TODO: Fix RPATH usage to be CMP0068 compliant
4+
# Disable Policy CMP0068 for CMake 3.9
5+
# rdar://37725888
6+
if(POLICY CMP0068)
7+
cmake_policy(SET CMP0068 OLD)
8+
endif()
9+
310
# Add path for custom CMake modules.
411
list(APPEND CMAKE_MODULE_PATH
512
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
@@ -11,6 +18,8 @@ set_property(GLOBAL PROPERTY JOB_POOLS local_jobs=${localhost_logical_cores})
1118
# Put linking in that category
1219
set_property(GLOBAL PROPERTY JOB_POOL_LINK local_jobs)
1320

21+
ENABLE_LANGUAGE(C)
22+
1423
# First include general CMake utilities.
1524
include(SwiftUtils)
1625
include(CheckSymbolExists)
@@ -374,6 +383,10 @@ if(SWIFT_BUILT_STANDALONE)
374383
project(Swift C CXX ASM)
375384
endif()
376385

386+
if(MSVC OR "${CMAKE_SIMULATE_ID}" STREQUAL MSVC)
387+
include(ClangClCompileRules)
388+
endif()
389+
377390
precondition(CMAKE_SYSTEM_NAME)
378391
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
379392
set(SWIFT_BUILD_SOURCEKIT_default TRUE)

benchmark/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ set(SWIFT_BENCH_MODULES
5959
single-source/DictTest
6060
single-source/DictTest2
6161
single-source/DictTest3
62+
single-source/DictTest4
6263
single-source/DictionaryBridge
6364
single-source/DictionaryGroup
6465
single-source/DictionaryLiteral
@@ -113,15 +114,18 @@ set(SWIFT_BENCH_MODULES
113114
single-source/Prims
114115
single-source/ProtocolDispatch
115116
single-source/ProtocolDispatch2
117+
single-source/Queue
116118
single-source/RC4
117119
single-source/RGBHistogram
118120
single-source/RangeAssignment
119121
single-source/RangeIteration
120122
single-source/RangeReplaceableCollectionPlusDefault
121123
single-source/RecursiveOwnedParameter
122124
single-source/ReduceInto
125+
single-source/RemoveWhere
123126
single-source/ReversedCollections
124127
single-source/RomanNumbers
128+
single-source/SequenceAlgos
125129
single-source/SetTests
126130
single-source/SevenBoom
127131
single-source/Sim2DArray

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ function (swift_benchmark_compile_archopts)
219219
endif()
220220
endif()
221221

222-
set(common_swift3_options ${common_options} "-swift-version" "3")
223222
set(common_swift4_options ${common_options} "-swift-version" "4")
224223

225224
# Always optimize the driver modules.
@@ -247,7 +246,7 @@ function (swift_benchmark_compile_archopts)
247246
SOURCE_DIR "${srcdir}"
248247
OBJECT_DIR "${objdir}"
249248
SOURCES ${sources}
250-
LIBRARY_FLAGS ${common_swift3_options})
249+
LIBRARY_FLAGS ${common_swift4_options})
251250
precondition(objfile_out)
252251
list(APPEND bench_library_objects "${objfile_out}")
253252
if (SWIFT_BENCHMARK_EMIT_SIB)
@@ -316,7 +315,7 @@ function (swift_benchmark_compile_archopts)
316315
${stdlib_dependencies} ${bench_library_objects}
317316
"${srcdir}/${module_name_path}.swift"
318317
COMMAND "${SWIFT_EXEC}"
319-
${common_swift3_options}
318+
${common_swift4_options}
320319
${extra_options}
321320
"-parse-as-library"
322321
${bench_flags}
@@ -334,7 +333,7 @@ function (swift_benchmark_compile_archopts)
334333
${stdlib_dependencies} ${bench_library_sibfiles}
335334
"${srcdir}/${module_name_path}.swift"
336335
COMMAND "${SWIFT_EXEC}"
337-
${common_swift3_options}
336+
${common_swift4_options}
338337
"-parse-as-library"
339338
${bench_flags}
340339
"-module-name" "${module_name}"
@@ -364,7 +363,7 @@ function (swift_benchmark_compile_archopts)
364363
SOURCE_DIR "${srcdir}"
365364
OBJECT_DIR "${objdir}"
366365
SOURCES ${${module_name}_sources}
367-
LIBRARY_FLAGS ${common_swift3_options} ${bench_flags}
366+
LIBRARY_FLAGS ${common_swift4_options} ${bench_flags}
368367
DEPENDS ${bench_library_objects} ${stdlib_dependencies})
369368
precondition(objfile_out)
370369
list(APPEND SWIFT_BENCH_OBJFILES "${objfile_out}")
@@ -382,7 +381,7 @@ function (swift_benchmark_compile_archopts)
382381
SOURCE_DIR "${srcdir}"
383382
OBJECT_DIR "${objdir}"
384383
SOURCES ${${module_name}_sources}
385-
LIBRARY_FLAGS ${common_swift3_options} ${bench_flags}
384+
LIBRARY_FLAGS ${common_swift4_options} ${bench_flags}
386385
DEPENDS ${bench_library_objects} ${stdlib_dependencies})
387386
precondition(objfiles_out)
388387
list(APPEND SWIFT_BENCH_OBJFILES ${objfiles_out})
@@ -435,7 +434,7 @@ function (swift_benchmark_compile_archopts)
435434
${bench_library_sibfiles} ${bench_driver_sibfiles}
436435
${SWIFT_BENCH_SIBFILES} "${source}"
437436
COMMAND "${SWIFT_EXEC}"
438-
${common_swift3_options}
437+
${common_swift4_options}
439438
"-force-single-frontend-invocation"
440439
"-emit-module" "-module-name" "${module_name}"
441440
"-I" "${objdir}"

benchmark/single-source/ArraySubscript.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public func run_ArraySubscript(_ N: Int) {
3030
var arrays = [[Int]](repeating: [], count: numArrays)
3131
for i in 0..<numArrays {
3232
for _ in 0..<numArrayElements {
33-
arrays[i].append(Int(truncatingBitPattern: Random()))
33+
arrays[i].append(Int(truncatingIfNeeded: Random()))
3434
}
3535
}
3636

benchmark/single-source/CString.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public func run_StringWithCString(_ N: Int) {
3737

3838
@inline(never)
3939
public func run_CStringLongAscii(_ N: Int) {
40-
var res: UInt = 0
40+
var res = 0
4141
for _ in 1...N*500 {
4242
// static string to c -> from c to String -> implicit conversion
4343
res &= strlen(ascii.withCString(String.init(cString:)))
@@ -47,7 +47,7 @@ public func run_CStringLongAscii(_ N: Int) {
4747

4848
@inline(never)
4949
public func run_CStringLongNonAscii(_ N: Int) {
50-
var res: UInt = 0
50+
var res = 0
5151
for _ in 1...N*500 {
5252
res &= strlen(japanese.withCString(String.init(cString:)))
5353
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
//===--- DictTest4.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+
import TestsUtils
14+
15+
// This benchmark mostly measures lookups in dictionaries with complex keys,
16+
// exercising the default hash compression function.
17+
18+
public let Dictionary4 = [
19+
BenchmarkInfo(name: "Dictionary4", runFunction: run_Dictionary4, tags: [.validation, .api, .Dictionary]),
20+
BenchmarkInfo(name: "Dictionary4OfObjects", runFunction: run_Dictionary4OfObjects, tags: [.validation, .api, .Dictionary]),
21+
]
22+
23+
struct LargeKey: Hashable {
24+
let i: Int
25+
let j: Int
26+
let k: Double
27+
let l: UInt32
28+
let m: Bool
29+
let n: Bool
30+
let o: Bool
31+
let p: Bool
32+
let q: Bool
33+
34+
init(_ value: Int) {
35+
self.i = value
36+
self.j = 2 * value
37+
self.k = Double(value) / 7
38+
self.l = UInt32(truncatingIfNeeded: value)
39+
self.m = value & 1 == 0
40+
self.n = value & 2 == 0
41+
self.o = value & 4 == 0
42+
self.p = value & 8 == 0
43+
self.q = value & 16 == 0
44+
}
45+
}
46+
47+
@inline(never)
48+
public func run_Dictionary4(_ N: Int) {
49+
let size1 = 100
50+
let reps = 20
51+
let ref_result = "1 99 \(reps) \(reps * 99)"
52+
var hash1 = [LargeKey: Int]()
53+
var hash2 = [LargeKey: Int]()
54+
var res = ""
55+
56+
for _ in 1...N {
57+
// Test insertions
58+
hash1 = [:]
59+
for i in 0..<size1 {
60+
hash1[LargeKey(i)] = i
61+
}
62+
63+
hash2 = hash1
64+
65+
// Test lookups & value replacement
66+
for _ in 1..<reps {
67+
for (k, v) in hash1 {
68+
hash2[k] = hash2[k]! + v
69+
}
70+
}
71+
72+
res = "\(hash1[LargeKey(1)]!) \(hash1[LargeKey(99)]!)" +
73+
" \(hash2[LargeKey(1)]!) \(hash2[LargeKey(99)]!)"
74+
if res != ref_result {
75+
break
76+
}
77+
}
78+
CheckResults(res == ref_result)
79+
}
80+
81+
class Box<T : Hashable> : Hashable {
82+
var value: T
83+
84+
init(_ v: T) {
85+
value = v
86+
}
87+
88+
var hashValue: Int {
89+
return value.hashValue
90+
}
91+
92+
static func ==(lhs: Box, rhs: Box) -> Bool {
93+
return lhs.value == rhs.value
94+
}
95+
}
96+
97+
@inline(never)
98+
public func run_Dictionary4OfObjects(_ N: Int) {
99+
let size1 = 100
100+
let reps = 20
101+
let ref_result = "1 99 \(reps) \(reps * 99)"
102+
var hash1 = [Box<LargeKey>: Int]()
103+
var hash2 = [Box<LargeKey>: Int]()
104+
var res = ""
105+
106+
for _ in 1...N {
107+
// Test insertions
108+
hash1 = [:]
109+
for i in 0..<size1 {
110+
hash1[Box(LargeKey(i))] = i
111+
}
112+
113+
hash2 = hash1
114+
115+
// Test lookups & value replacement
116+
for _ in 1..<reps {
117+
for (k, v) in hash1 {
118+
hash2[k] = hash2[k]! + v
119+
}
120+
}
121+
122+
res = "\(hash1[Box(LargeKey(1))]!) \(hash1[Box(LargeKey(99))]!)" +
123+
" \(hash2[Box(LargeKey(1))]!) \(hash2[Box(LargeKey(99))]!)"
124+
if res != ref_result {
125+
break
126+
}
127+
}
128+
CheckResults(res == ref_result)
129+
}

benchmark/single-source/DoubleWidthDivision.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@
1212

1313
// This test checks performance of division using DoubleWidth.
1414

15-
import Foundation
15+
// FIXME: This needs to be disabled with an #if because it runs into pathological
16+
// compile time and code size problems.
17+
// [SR-6947] DoubleWidth compile time.
18+
// import Foundation
1619
import TestsUtils
1720

1821
public let DoubleWidthDivision = BenchmarkInfo(
1922
name: "DoubleWidthDivision",
20-
runFunction: run_DoubleWidthDivision,
23+
runFunction: disabled,
2124
tags: [.validation, .algorithm]
2225
)
26+
public func disabled(_ N: Int) {}
27+
28+
#if false
2329

2430
private typealias Int128 = DoubleWidth<Int64>
2531
private typealias Int256 = DoubleWidth<Int128>
@@ -54,3 +60,4 @@ public func run_DoubleWidthDivision(_ N: Int) {
5460
}
5561
CheckResults(sum == 0)
5662
}
63+
#endif

benchmark/single-source/Hash.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,17 @@ class Hash {
114114
final
115115
func rol(_ x: UInt32, _ c: UInt32) -> UInt32 {
116116
// TODO: use the &>> operator.
117-
let a = UInt32(truncatingBitPattern: Int64(x) << Int64(c))
118-
let b = UInt32(truncatingBitPattern: Int64(x) >> (32 - Int64(c)))
117+
let a = UInt32(truncatingIfNeeded: Int64(x) << Int64(c))
118+
let b = UInt32(truncatingIfNeeded: Int64(x) >> (32 - Int64(c)))
119119
return a|b
120120
}
121121

122122
/// \brief Right-rotate \p x by \p c.
123123
final
124124
func ror(_ x: UInt32, _ c: UInt32) -> UInt32 {
125125
// TODO: use the &>> operator.
126-
let a = UInt32(truncatingBitPattern: Int64(x) >> Int64(c))
127-
let b = UInt32(truncatingBitPattern: Int64(x) << (32 - Int64(c)))
126+
let a = UInt32(truncatingIfNeeded: Int64(x) >> Int64(c))
127+
let b = UInt32(truncatingIfNeeded: Int64(x) << (32 - Int64(c)))
128128
return a|b
129129
}
130130
}
@@ -177,10 +177,10 @@ class MD5 : Hash {
177177
}
178178

179179
func appendBytes(_ Val: Int, _ Message: inout Array<UInt8>, _ Offset : Int) {
180-
Message[Offset] = UInt8(truncatingBitPattern: Val)
181-
Message[Offset + 1] = UInt8(truncatingBitPattern: Val >> 8)
182-
Message[Offset + 2] = UInt8(truncatingBitPattern: Val >> 16)
183-
Message[Offset + 3] = UInt8(truncatingBitPattern: Val >> 24)
180+
Message[Offset] = UInt8(truncatingIfNeeded: Val)
181+
Message[Offset + 1] = UInt8(truncatingIfNeeded: Val >> 8)
182+
Message[Offset + 2] = UInt8(truncatingIfNeeded: Val >> 16)
183+
Message[Offset + 3] = UInt8(truncatingIfNeeded: Val >> 24)
184184
}
185185

186186
override

benchmark/single-source/IterateData.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ public let IterateData = BenchmarkInfo(
2121
@inline(never)
2222
func generateData() -> Data {
2323
var data = Data(count: 16 * 1024)
24+
let n = data.count
2425
data.withUnsafeMutableBytes { (ptr: UnsafeMutablePointer<UInt8>) -> () in
25-
for i in 0..<data.count {
26+
for i in 0..<n {
2627
ptr[i] = UInt8(i % 23)
2728
}
2829
}

0 commit comments

Comments
 (0)