Skip to content

Commit 7928140

Browse files
[SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary
1 parent 0ff3239 commit 7928140

File tree

1,137 files changed

+8796
-8672
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,137 files changed

+8796
-8672
lines changed

CHANGELOG.md

+20
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@ Note: This is in reverse chronological order, so newer entries are added to the
33
Swift 3.0
44
-------
55

6+
* [SE-0046] (https://github.com/apple/swift-evolution/blob/master/proposals/0046-first-label.md) Function parameters now have consistent labelling across all function parameters. With this update the first parameter declarations will now match the existing behavior of the second and later parameters. This change makes the language simpler.
7+
8+
Functions that were written and called as follows
9+
```swift
10+
func foo(x: Int, y: Int) {
11+
}
12+
foo(1, y: 2)
13+
14+
func bar(a a: Int, b: Int) {
15+
}
16+
bar(a: 3, b: 4)
17+
```
18+
will now be written as (to achieve the same behavior):
19+
```swift
20+
func foo(_ x: Int, y: Int) {}
21+
foo(1, y: 2)
22+
func bar(a: Int, b: Int) {}
23+
bar(a: 3, b: 4)
24+
```
25+
626
* [SE-0037](https://github.com/apple/swift-evolution/blob/master/proposals/0037-clarify-comments-and-operators.md)
727
Comments are now treated as whitespace when determining whether an operator is
828
prefix, postfix, or binary. For example, these now work:

benchmark/single-source/Ackermann.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
// for performance measuring.
1515
import TestsUtils
1616

17-
func ackermann(M : Int, _ N : Int) -> Int {
17+
func ackermann(_ M: Int, _ N : Int) -> Int {
1818
if (M == 0) { return N + 1 }
1919
if (N == 0) { return ackermann(M - 1, 1) }
2020
return ackermann(M - 1, ackermann(M, N - 1))
2121
}
2222

2323
@inline(never)
24-
func Ackermann(M : Int, _ N : Int) -> Int {
24+
func Ackermann(_ M: Int, _ N : Int) -> Int {
2525
// This if prevents optimizer from computing return value of Ackermann(3,9)
2626
// at compile time.
2727
if False() { return 0 }
@@ -33,7 +33,7 @@ func Ackermann(M : Int, _ N : Int) -> Int {
3333
let ref_result = [5, 13, 29, 61, 125, 253, 509, 1021, 2045, 4093, 8189, 16381, 32765, 65533, 131069];
3434

3535
@inline(never)
36-
public func run_Ackermann(N: Int) {
36+
public func run_Ackermann(_ N: Int) {
3737
let (m, n) = (3, 9)
3838
var result = 0
3939
for _ in 1...N {

benchmark/single-source/AngryPhonebook.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var words = [
3131
"Bobby", "Dylan", "Johnny", "Phillip", "Craig"]
3232

3333
@inline(never)
34-
public func run_AngryPhonebook(N: Int) {
34+
public func run_AngryPhonebook(_ N: Int) {
3535
// Permute the names.
3636
for _ in 1...N {
3737
for firstname in words {

benchmark/single-source/Array2D.swift

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

1313
@inline(never)
14-
public func run_Array2D(N: Int) {
14+
public func run_Array2D(_ N: Int) {
1515
var A: [[Int]] = []
1616
for _ in 0 ..< 1024 {
1717
var B: [Int] = []

benchmark/single-source/ArrayAppend.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import TestsUtils
1616

1717
@inline(never)
18-
public func run_ArrayAppend(N: Int) {
18+
public func run_ArrayAppend(_ N: Int) {
1919
for _ in 0..<N {
2020
for _ in 0..<10 {
2121
var nums = [Int]()
@@ -27,7 +27,7 @@ public func run_ArrayAppend(N: Int) {
2727
}
2828

2929
@inline(never)
30-
public func run_ArrayAppendReserved(N: Int) {
30+
public func run_ArrayAppendReserved(_ N: Int) {
3131
for _ in 0..<N {
3232
for _ in 0..<10 {
3333
var nums = [Int]()

benchmark/single-source/ArrayInClass.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ArrayContainer {
1717
arr = [Int] (repeating: 0, count: 100_000)
1818
}
1919

20-
func runLoop(N: Int) {
20+
func runLoop(_ N: Int) {
2121
for _ in 0 ..< N {
2222
for i in 0 ..< arr.count {
2323
arr[i] = arr[i] + 1
@@ -32,7 +32,7 @@ func getArrayContainer() -> ArrayContainer {
3232
}
3333

3434
@inline(never)
35-
public func run_ArrayInClass(N: Int) {
35+
public func run_ArrayInClass(_ N: Int) {
3636
let a = getArrayContainer()
3737
a.runLoop(N)
3838
}

benchmark/single-source/ArrayLiteral.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func makeArray() -> [Int] {
2121
}
2222

2323
@inline(never)
24-
public func run_ArrayLiteral(N: Int) {
24+
public func run_ArrayLiteral(_ N: Int) {
2525
for _ in 1...10000*N {
2626
makeArray()
2727
}
@@ -34,7 +34,7 @@ func addLiteralArray() -> Int {
3434
}
3535

3636
@inline(never)
37-
public func run_ArrayValueProp(N: Int) {
37+
public func run_ArrayValueProp(_ N: Int) {
3838
var res = 123
3939
for _ in 1...10000*N {
4040
res += addLiteralArray()
@@ -75,7 +75,7 @@ func addLiteralArray4() -> Int {
7575
}
7676

7777
@inline(never)
78-
public func run_ArrayValueProp2(N: Int) {
78+
public func run_ArrayValueProp2(_ N: Int) {
7979
var res = 123
8080
for _ in 1...10000*N {
8181
res += addLiteralArray2()
@@ -85,7 +85,7 @@ public func run_ArrayValueProp2(N: Int) {
8585
}
8686

8787
@inline(never)
88-
public func run_ArrayValueProp3(N: Int) {
88+
public func run_ArrayValueProp3(_ N: Int) {
8989
var res = 123
9090
for _ in 1...10000*N {
9191
res += addLiteralArray3()
@@ -95,7 +95,7 @@ public func run_ArrayValueProp3(N: Int) {
9595
}
9696

9797
@inline(never)
98-
public func run_ArrayValueProp4(N: Int) {
98+
public func run_ArrayValueProp4(_ N: Int) {
9999
var res = 123
100100
for _ in 1...10000*N {
101101
res += addLiteralArray4()

benchmark/single-source/ArrayOfGenericPOD.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func genStructArray() {
5858
}
5959

6060
@inline(never)
61-
public func run_ArrayOfGenericPOD(N: Int) {
61+
public func run_ArrayOfGenericPOD(_ N: Int) {
6262
for _ in 0...N {
6363
genEnumArray()
6464
genIOUArray()

benchmark/single-source/ArrayOfGenericRef.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func genRefStructArray() {
8686
}
8787

8888
@inline(never)
89-
public func run_ArrayOfGenericRef(N: Int) {
89+
public func run_ArrayOfGenericRef(_ N: Int) {
9090
for _ in 0...N {
9191
genPODRefArray()
9292
genCommonRefArray()

benchmark/single-source/ArrayOfPOD.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func genStructArray() {
5353
}
5454

5555
@inline(never)
56-
public func run_ArrayOfPOD(N: Int) {
56+
public func run_ArrayOfPOD(_ N: Int) {
5757
for _ in 0...N {
5858
genIntArray()
5959
genEnumArray()

benchmark/single-source/ArrayOfRef.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func genRefStructArray() {
9797
}
9898

9999
@inline(never)
100-
public func run_ArrayOfRef(N: Int) {
100+
public func run_ArrayOfRef(_ N: Int) {
101101
for _ in 0...N {
102102
genPODRefArray()
103103
genCommonRefArray()

benchmark/single-source/ArraySubscript.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
import TestsUtils
1515

1616
@inline(never)
17-
public func run_ArraySubscript(N: Int) {
17+
public func run_ArraySubscript(_ N: Int) {
1818
SRand()
1919

2020
let numArrays = 200*N
2121
let numArrayElements = 100
2222

23-
func bound(x: Int) -> Int { return min(x, numArrayElements-1) }
23+
func bound(_ x: Int) -> Int { return min(x, numArrayElements-1) }
2424

2525
var arrays = [[Int]](repeating: [], count: numArrays)
2626
for i in 0..<numArrays {

benchmark/single-source/BitCount.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import Foundation
1717
import TestsUtils
1818

19-
func countBitSet(num: Int) -> Int {
19+
func countBitSet(_ num: Int) -> Int {
2020
let bits = sizeof(Int) * 8
2121
var cnt : Int = 0
2222
var mask: Int = 1
@@ -30,7 +30,7 @@ func countBitSet(num: Int) -> Int {
3030
}
3131

3232
@inline(never)
33-
public func run_BitCount(N: Int) {
33+
public func run_BitCount(_ N: Int) {
3434
for _ in 1...100*N {
3535
// Check some results.
3636
CheckResults(countBitSet(1) == 1, "Incorrect results in BitCount.")

benchmark/single-source/ByteSwap.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Foundation
1717
import TestsUtils
1818

1919
// a naive O(n) implementation of byteswap.
20-
func byteswap_n(a: UInt64) -> UInt64 {
20+
func byteswap_n(_ a: UInt64) -> UInt64 {
2121
return ((a & 0x00000000000000FF) << 56) |
2222
((a & 0x000000000000FF00) << 40) |
2323
((a & 0x0000000000FF0000) << 24) |
@@ -29,7 +29,7 @@ func byteswap_n(a: UInt64) -> UInt64 {
2929
}
3030

3131
// a O(logn) implementation of byteswap.
32-
func byteswap_logn(a: UInt64) -> UInt64 {
32+
func byteswap_logn(_ a: UInt64) -> UInt64 {
3333
var a = a
3434
a = (a & 0x00000000FFFFFFFF) << 32 | (a & 0xFFFFFFFF00000000) >> 32
3535
a = (a & 0x0000FFFF0000FFFF) << 16 | (a & 0xFFFF0000FFFF0000) >> 16
@@ -38,7 +38,7 @@ func byteswap_logn(a: UInt64) -> UInt64 {
3838
}
3939

4040
@inline(never)
41-
public func run_ByteSwap(N: Int) {
41+
public func run_ByteSwap(_ N: Int) {
4242
for _ in 1...100*N {
4343
// Check some results.
4444
CheckResults(byteswap_logn(byteswap_n(2457)) == 2457, "Incorrect results in ByteSwap.")

benchmark/single-source/Calculator.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import TestsUtils
1414
import Foundation
1515

1616
@inline(never)
17-
func my_atoi_impl(input : String) -> Int {
17+
func my_atoi_impl(_ input : String) -> Int {
1818
switch input {
1919
case "0": return 0
2020
case "1": return 1
@@ -31,7 +31,7 @@ func my_atoi_impl(input : String) -> Int {
3131
}
3232

3333
@inline(never)
34-
public func run_Calculator(N: Int) {
34+
public func run_Calculator(_ N: Int) {
3535
var c = 0
3636
for _ in 1...N*5000 {
3737
c += my_atoi_impl("10")

benchmark/single-source/CaptureProp.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
func sum(x:Int, y:Int) -> Int {
13+
func sum(_ x:Int, y:Int) -> Int {
1414
return x + y
1515
}
1616

1717
@inline(never)
1818
func benchCaptureProp<S : Sequence
1919
>(
20-
s:S, _ f:(S.Iterator.Element, S.Iterator.Element)->S.Iterator.Element) -> S.Iterator.Element {
20+
_ s: S, _ f:(S.Iterator.Element, S.Iterator.Element)->S.Iterator.Element) -> S.Iterator.Element {
2121

2222
var it = s.makeIterator()
2323
let initial = it.next()!
2424
return IteratorSequence(it).reduce(initial, combine: f)
2525
}
2626

27-
public func run_CaptureProp(N: Int) {
27+
public func run_CaptureProp(_ N: Int) {
2828
let a = 1...10_000
2929
for _ in 1...100*N {
3030
benchCaptureProp(a, sum)

benchmark/single-source/Chars.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import TestsUtils
1515

1616
@inline(never)
17-
public func run_Chars(N: Int) {
17+
public func run_Chars(_ N: Int) {
1818
// Permute some characters.
1919
let alphabet: [Character] = [
2020
"A", "B", "C", "D", "E", "F", "G",

benchmark/single-source/ClassArrayGetter.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ class Box {
1616
}
1717

1818
@inline(never)
19-
func sumArray(a: [Box]) -> Int {
19+
func sumArray(_ a: [Box]) -> Int {
2020
var s = 0
2121
for i in 0..<a.count {
2222
s += a[i].v
2323
}
2424
return s
2525
}
2626

27-
public func run_ClassArrayGetter(N: Int) {
27+
public func run_ClassArrayGetter(_ N: Int) {
2828
let aSize = 10_000
2929
var a: [Box] = []
3030
a.reserveCapacity(aSize)

benchmark/single-source/DeadArray.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@
1414
import TestsUtils
1515

1616
@inline(__always)
17-
func debug(m:String) {}
17+
func debug(_ m:String) {}
1818

1919
private var Count = 0
2020

2121
@inline(never)
2222
func bar() { Count += 1 }
2323

2424
@inline(never)
25-
func runLoop(var1: Int, var2: Int) {
25+
func runLoop(_ var1: Int, var2: Int) {
2626
for _ in 0..<100_000 {
2727
debug("Var1: \(var1) Var2: \(var2)")
2828
bar()
2929
}
3030
}
3131

3232
@inline(never)
33-
public func run_DeadArray(N: Int) {
33+
public func run_DeadArray(_ N: Int) {
3434
for _ in 1...N {
3535
Count = 0
3636
runLoop(0, var2: 0)

benchmark/single-source/DictTest2.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import TestsUtils
1414

1515
@inline(never)
16-
public func run_Dictionary2(N: Int) {
16+
public func run_Dictionary2(_ N: Int) {
1717
let size = 500
1818
let ref_result = 199
1919
var res = 0
@@ -57,7 +57,7 @@ func ==<T: Equatable>(lhs: Box<T>, rhs: Box<T>) -> Bool {
5757
}
5858

5959
@inline(never)
60-
public func run_Dictionary2OfObjects(N: Int) {
60+
public func run_Dictionary2OfObjects(_ N: Int) {
6161
let size = 500
6262
let ref_result = 199
6363
var res = 0

benchmark/single-source/DictTest3.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import TestsUtils
1414

1515
@inline(never)
16-
public func run_Dictionary3(N: Int) {
16+
public func run_Dictionary3(_ N: Int) {
1717
let size1 = 100
1818
let reps = 20
1919
let ref_result = "1 99 20 1980"
@@ -64,7 +64,7 @@ func ==<T: Equatable>(lhs: Box<T>, rhs: Box<T>) -> Bool {
6464
}
6565

6666
@inline(never)
67-
public func run_Dictionary3OfObjects(N: Int) {
67+
public func run_Dictionary3OfObjects(_ N: Int) {
6868
let size1 = 100
6969
let reps = 20
7070
let ref_result = "1 99 20 1980"

benchmark/single-source/DictionaryBridge.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Stuff {
5252
}
5353

5454
@inline(never)
55-
public func run_DictionaryBridge(N: Int) {
55+
public func run_DictionaryBridge(_ N: Int) {
5656
for _ in 1...100*N {
5757
_ = Stuff()
5858
}

benchmark/single-source/DictionaryLiteral.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func makeDictionary() -> [Int: Int] {
2020
}
2121

2222
@inline(never)
23-
public func run_DictionaryLiteral(N: Int) {
23+
public func run_DictionaryLiteral(_ N: Int) {
2424
for _ in 1...10000*N {
2525
makeDictionary()
2626
}

0 commit comments

Comments
 (0)