Skip to content

Commit 177f34c

Browse files
committed
Merge branch 'master' into fix-static-stripped-error-bridging
2 parents 3cc86eb + 713eb1a commit 177f34c

File tree

528 files changed

+13163
-6230
lines changed

Some content is hidden

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

528 files changed

+13163
-6230
lines changed

CHANGELOG.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,48 @@ Swift 5.0
5757
Swift 4.2
5858
---------
5959

60+
* [SE-0185][]
61+
62+
Protocol conformances are now able to be synthesized in extensions in the same
63+
file as the type definition, allowing automatic synthesis of conditional
64+
conformances to `Hashable`, `Equatable` and `Codable` (both `Encodable` and
65+
`Decodable`). For instance, if there is a generic wrapper type that can only
66+
be `Equatable` when its wrapped type is also `Equatable`, the `==` method can
67+
be automatically constructed by the compiler:
68+
69+
```swift
70+
struct Generic<Param> {
71+
var property: Param
72+
}
73+
74+
extension Generic: Equatable where Param: Equatable {}
75+
// Automatically synthesized inside the extension:
76+
// static func ==(lhs: Generic, rhs: Generic) -> Bool {
77+
// return lhs.property == rhs.property
78+
// }
79+
```
80+
81+
Code that wants to be as precise as possible should generally not
82+
conditionally conform to `Codable` directly, but rather its two constituent
83+
protocols `Encodable` and `Decodable`, or else one can only (for instance)
84+
decode a `Generic<Param>` if `Param` is `Encodable` in addition to
85+
`Decodable`, even though `Encodable` is likely not required:
86+
87+
```swift
88+
// Unnecessarily restrictive:
89+
extension Generic: Codable where Param: Codable {}
90+
91+
// More precise:
92+
extension Generic: Encodable where Param: Encodable {}
93+
extension Generic: Decodable where Param: Decodable {}
94+
```
95+
96+
Finally, due to `Decodable` having an `init` requirement, it is not possible
97+
to conform to `Decodable` in an extension of a non-final class: such a class
98+
needs to have any `init`s from protocols be `required`, which means they need
99+
to be in the class definition.
100+
101+
60102
* [SE-0054][]
61103

62104
`ImplicitlyUnwrappedOptional<T>` is now an unavailable typealias of `Optional<T>`.

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
# Swift Programming Language
44

55

6-
| | **Swift** | **Package** |
7-
|---|:---:|:---:|
8-
|**macOS** |[![Build Status](https://ci.swift.org/job/oss-swift-incremental-RA-osx/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-incremental-RA-osx)|[![Build Status](https://ci.swift.org/job/oss-swift-package-osx/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-osx)|
9-
|**Ubuntu 14.04** |[![Build Status](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-14_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-14_04)|[![Build Status](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-14_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-14_04)|
10-
|**Ubuntu 16.04** |[![Build Status](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-16_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-16_04)|[![Build Status](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-16_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-16_04)|
11-
|**Ubuntu 16.10** |[![Build Status](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-16_10/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-16_10)|[![Build Status](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-16_10/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-16_10)|
6+
| | **Architecture** | **Master** | **Package** |
7+
|---|:---:|:---:|:---:|
8+
| **macOS** | x86_64 |[![Build Status](https://ci.swift.org/job/oss-swift-incremental-RA-osx/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-incremental-RA-osx)|[![Build Status](https://ci.swift.org/job/oss-swift-package-osx/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-osx)|
9+
| **Ubuntu 14.04** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-14_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-14_04)|[![Build Status](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-14_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-14_04)|
10+
| **Ubuntu 16.04** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-16_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-16_04)|[![Build Status](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-16_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-16_04)|
11+
| **Ubuntu 16.10** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-16_10/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-16_10)|[![Build Status](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-16_10/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-16_10)|
1212

1313
**Swift Community-Hosted CI Platforms**
1414

15-
| | **Swift** |
16-
|---|:---:|
17-
|**Debian 9.1** |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-debian-9_1/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-debian-9_1)|
18-
|**Fedora 27** |[![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)|
19-
|**Ubuntu 16.04** |[![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)|
15+
| **OS** | **Architecture** | **Build** |
16+
|---|:---:|:---:|
17+
|**[Debian 9.1 (Raspberry Pi)](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/armv7_debian_stretch.json)** | ARMv7 | [![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-debian-9_1/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-debian-9_1)|
18+
|**[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)|
19+
|**[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)|
20+
|**[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)|
2021

2122
**Welcome to Swift!**
2223

benchmark/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ set(SWIFT_BENCH_MODULES
124124
single-source/Queue
125125
single-source/RC4
126126
single-source/RGBHistogram
127+
single-source/RandomShuffle
128+
single-source/RandomValues
127129
single-source/RangeAssignment
128130
single-source/RangeIteration
129131
single-source/RangeReplaceableCollectionPlusDefault
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//===--- RandomShuffle.swift ----------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 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+
//
16+
// Benchmark that shuffles arrays of integers. Measures the performance of
17+
// shuffling large arrays.
18+
//
19+
20+
public let RandomShuffle = [
21+
BenchmarkInfo(name: "RandomShuffleDef", runFunction: run_RandomShuffleDef,
22+
tags: [.api], setUpFunction: setup_RandomShuffle),
23+
BenchmarkInfo(name: "RandomShuffleLCG", runFunction: run_RandomShuffleLCG,
24+
tags: [.api], setUpFunction: setup_RandomShuffle),
25+
]
26+
27+
/// A linear congruential PRNG.
28+
struct LCRNG: RandomNumberGenerator {
29+
private var state: UInt64
30+
31+
init(seed: Int) {
32+
state = UInt64(truncatingIfNeeded: seed)
33+
for _ in 0..<10 { _ = next() }
34+
}
35+
36+
mutating func next() -> UInt64 {
37+
state = 2862933555777941757 &* state &+ 3037000493
38+
return state
39+
}
40+
}
41+
42+
var numbers = Array(0...3_000_000)
43+
44+
@inline(never)
45+
func setup_RandomShuffle() {
46+
_ = numbers.count
47+
}
48+
49+
@inline(never)
50+
public func run_RandomShuffleDef(_ N: Int) {
51+
for _ in 0 ..< N {
52+
numbers.shuffle()
53+
blackHole(numbers.first!)
54+
}
55+
}
56+
57+
@inline(never)
58+
public func run_RandomShuffleLCG(_ N: Int) {
59+
var generator = LCRNG(seed: 0)
60+
for _ in 0 ..< N {
61+
numbers.shuffle(using: &generator)
62+
blackHole(numbers.first!)
63+
}
64+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//===--- RandomValues.swift -----------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 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+
//
16+
// Benchmark generating lots of random values. Measures the performance of
17+
// the default random generator and the algorithms for generating integers
18+
// and floating-point values.
19+
//
20+
21+
public let RandomValues = [
22+
BenchmarkInfo(name: "RandomIntegersDef", runFunction: run_RandomIntegersDef, tags: [.api]),
23+
BenchmarkInfo(name: "RandomIntegersLCG", runFunction: run_RandomIntegersLCG, tags: [.api]),
24+
BenchmarkInfo(name: "RandomDoubleDef", runFunction: run_RandomDoubleDef, tags: [.api]),
25+
BenchmarkInfo(name: "RandomDoubleLCG", runFunction: run_RandomDoubleLCG, tags: [.api]),
26+
]
27+
28+
/// A linear congruential PRNG.
29+
struct LCRNG: RandomNumberGenerator {
30+
private var state: UInt64
31+
32+
init(seed: Int) {
33+
state = UInt64(truncatingIfNeeded: seed)
34+
for _ in 0..<10 { _ = next() }
35+
}
36+
37+
mutating func next() -> UInt64 {
38+
state = 2862933555777941757 &* state &+ 3037000493
39+
return state
40+
}
41+
}
42+
43+
@inline(never)
44+
public func run_RandomIntegersDef(_ N: Int) {
45+
for _ in 0 ..< N {
46+
var x = 0
47+
for _ in 0 ..< 100_000 {
48+
x &+= Int.random(in: 0...10_000)
49+
}
50+
blackHole(x)
51+
}
52+
}
53+
54+
@inline(never)
55+
public func run_RandomIntegersLCG(_ N: Int) {
56+
for _ in 0 ..< N {
57+
var x = 0
58+
var generator = LCRNG(seed: 0)
59+
for _ in 0 ..< 100_000 {
60+
x &+= Int.random(in: 0...10_000, using: &generator)
61+
}
62+
CheckResults(x == 498214315)
63+
}
64+
}
65+
66+
@inline(never)
67+
public func run_RandomDoubleDef(_ N: Int) {
68+
for _ in 0 ..< N {
69+
var x = 0.0
70+
for _ in 0 ..< 100_000 {
71+
x += Double.random(in: -1000...1000)
72+
}
73+
blackHole(x)
74+
}
75+
}
76+
77+
@inline(never)
78+
public func run_RandomDoubleLCG(_ N: Int) {
79+
for _ in 0 ..< N {
80+
var x = 0.0
81+
var generator = LCRNG(seed: 0)
82+
for _ in 0 ..< 100_000 {
83+
x += Double.random(in: -1000...1000, using: &generator)
84+
}
85+
blackHole(x)
86+
}
87+
}

benchmark/utils/main.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -112,6 +112,8 @@ import ProtocolDispatch2
112112
import Queue
113113
import RC4
114114
import RGBHistogram
115+
import RandomShuffle
116+
import RandomValues
115117
import RangeAssignment
116118
import RangeIteration
117119
import RangeReplaceableCollectionPlusDefault
@@ -268,6 +270,8 @@ registerBenchmark(QueueGeneric)
268270
registerBenchmark(QueueConcrete)
269271
registerBenchmark(RC4Test)
270272
registerBenchmark(RGBHistogram)
273+
registerBenchmark(RandomShuffle)
274+
registerBenchmark(RandomValues)
271275
registerBenchmark(RangeAssignment)
272276
registerBenchmark(RangeIteration)
273277
registerBenchmark(RangeReplaceableCollectionPlusDefault)

docs/ABI/Mangling.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ Some kinds need arguments, which precede ``Tf``.
789789
ARG-SPEC-KIND ::= 'c' // Consumes n 'type' arguments which are closed over types in argument order
790790
// and one 'identifier' argument which is the closure symbol name
791791
ARG-SPEC-KIND ::= 'p' CONST-PROP // Constant propagated argument
792+
ARG-SPEC-KIND ::= 'e' 'D'? 'G'? 'X'? // Generic argument, with optional dead, owned=>guaranteed or exploded-specifier
792793
ARG-SPEC-KIND ::= 'd' 'G'? 'X'? // Dead argument, with optional owned=>guaranteed or exploded-specifier
793794
ARG-SPEC-KIND ::= 'g' 'X'? // Owned => Guaranteed,, with optional exploded-specifier
794795
ARG-SPEC-KIND ::= 'x' // Exploded

docs/DriverParseableOutput.rst

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,29 @@ This allows the driver to pass as much information as it wants about the ongoing
3333
compilation, and programs which parse this data can decide what to use and what
3434
to ignore.
3535

36+
37+
Quasi-PIDs
38+
==========
39+
40+
In previous versions of this format, certain fields labeled "pid" carry only
41+
legitimate process IDs (PIDs) from the underlying operating system. These PIDs
42+
are used by the driver to associate events that happen to jobs, such as signals
43+
when a job crashes with the file being compiled during that event. Real PIDs are
44+
always positive numbers, in keeping with POSIX semantics and the unsigned
45+
Process ID type on Windows.
46+
47+
In more recent versions of this format, the Swift driver combines multiple jobs
48+
together into batches, running each batch in a single subprocess. In this mode,
49+
the driver writes messages describing each job as before, but assigns to each a
50+
so-called "quasi-PID" for the "pid" field, which does not correspond to an
51+
operating system process ID. Rather, a quasi-PID is a **negative number** that
52+
can be used **like** a PID, both as a unique identifier for each job that was
53+
run and in order to relate messages and tasks together, but it does not denote a
54+
real process. By using negative numbers for quasi-PIDs, we ensure that no two
55+
jobs will have the same PID: no batch mode job can have the same PID as a real
56+
process. Two jobs with the same PID would violate this uniqueness assumption.
57+
58+
3659
Message Kinds
3760
=============
3861

@@ -46,13 +69,13 @@ Began Message
4669
-------------
4770

4871
A "began" message indicates that a new task began. As with all task-based
49-
messages, it will include the task's PID under the "pid" key. It may specify the
50-
task's inputs as an array of paths under the "inputs" key. It may specify the
51-
task's outputs as an array of objects under the "outputs" key. An "outputs"
52-
object will have two fields, a "kind" describing the type of the output, and a
53-
"path" containing the path to the output. A "began" message will specify the
54-
command which was executed under the "command_executable" and "command_arguments"
55-
keys.
72+
messages, it will include the task's PID (or quasi-PID) under the "pid" key. It
73+
may specify the task's inputs as an array of paths under the "inputs" key. It
74+
may specify the task's outputs as an array of objects under the "outputs"
75+
key. An "outputs" object will have two fields, a "kind" describing the type of
76+
the output, and a "path" containing the path to the output. A "began" message
77+
will specify the command which was executed under the "command_executable" and
78+
"command_arguments" keys.
5679

5780
Example::
5881

@@ -83,10 +106,10 @@ Finished Message
83106
----------------
84107

85108
A "finished" message indicates that a task finished execution. As with all task-
86-
based messages, it will include the task's PID under the "pid" key. It will
87-
include the exit status of the task under the "exit-status" key. It may include
88-
the stdout/stderr of the task under the "output" key; if this key is missing,
89-
no output was generated by the task.
109+
based messages, it will include the task's PID (or quasi-PID) under the "pid"
110+
key. It will include the exit status of the task under the "exit-status" key. It
111+
may include the stdout/stderr of the task under the "output" key; if this key is
112+
missing, no output was generated by the task.
90113

91114
Example::
92115

@@ -102,12 +125,12 @@ Signalled Message
102125
-----------------
103126

104127
A "signalled" message indicates that a task exited abnormally due to a signal.
105-
As with all task-based message, it will include the task's PID under the "pid"
106-
key. It may include an error message describing the signal under the
107-
"error-message" key. As with the "finished" message, it may include the
128+
As with all task-based message, it will include the task's PID (or quasi-PID)
129+
under the "pid" key. It may include an error message describing the signal under
130+
the "error-message" key. As with the "finished" message, it may include the
108131
stdout/stderr of the task under the "output" key; if this key is missing, no
109-
output was generated by the task. It may include the "signal" key,
110-
the terminating signal number. (This may not be available on all platforms.)
132+
output was generated by the task. It may include the "signal" key, the
133+
terminating signal number. (This may not be available on all platforms.)
111134

112135
Example::
113136

0 commit comments

Comments
 (0)