Skip to content

[SE-0046] Implementation for consistent func labels #2047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@ Note: This is in reverse chronological order, so newer entries are added to the
Swift 3.0
-------

* [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.

Functions that were written and called as follows
```swift
func foo(x: Int, y: Int) {
}
foo(1, y: 2)

func bar(a a: Int, b: Int) {
}
bar(a: 3, b: 4)
```
will now be written as (to achieve the same behavior):
```swift
func foo(_ x: Int, y: Int) {}
foo(1, y: 2)
func bar(a: Int, b: Int) {}
bar(a: 3, b: 4)
```

* [SE-0037](https://github.com/apple/swift-evolution/blob/master/proposals/0037-clarify-comments-and-operators.md)
Comments are now treated as whitespace when determining whether an operator is
prefix, postfix, or binary. For example, these now work:
Expand Down
6 changes: 3 additions & 3 deletions benchmark/single-source/Ackermann.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
// for performance measuring.
import TestsUtils

func ackermann(M : Int, _ N : Int) -> Int {
func ackermann(_ M: Int, _ N : Int) -> Int {
if (M == 0) { return N + 1 }
if (N == 0) { return ackermann(M - 1, 1) }
return ackermann(M - 1, ackermann(M, N - 1))
}

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

@inline(never)
public func run_Ackermann(N: Int) {
public func run_Ackermann(_ N: Int) {
let (m, n) = (3, 9)
var result = 0
for _ in 1...N {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/single-source/AngryPhonebook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var words = [
"Bobby", "Dylan", "Johnny", "Phillip", "Craig"]

@inline(never)
public func run_AngryPhonebook(N: Int) {
public func run_AngryPhonebook(_ N: Int) {
// Permute the names.
for _ in 1...N {
for firstname in words {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/single-source/Array2D.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

@inline(never)
public func run_Array2D(N: Int) {
public func run_Array2D(_ N: Int) {
var A: [[Int]] = []
for _ in 0 ..< 1024 {
var B: [Int] = []
Expand Down
4 changes: 2 additions & 2 deletions benchmark/single-source/ArrayAppend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import TestsUtils

@inline(never)
public func run_ArrayAppend(N: Int) {
public func run_ArrayAppend(_ N: Int) {
for _ in 0..<N {
for _ in 0..<10 {
var nums = [Int]()
Expand All @@ -27,7 +27,7 @@ public func run_ArrayAppend(N: Int) {
}

@inline(never)
public func run_ArrayAppendReserved(N: Int) {
public func run_ArrayAppendReserved(_ N: Int) {
for _ in 0..<N {
for _ in 0..<10 {
var nums = [Int]()
Expand Down
4 changes: 2 additions & 2 deletions benchmark/single-source/ArrayInClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ArrayContainer {
arr = [Int] (repeating: 0, count: 100_000)
}

func runLoop(N: Int) {
func runLoop(_ N: Int) {
for _ in 0 ..< N {
for i in 0 ..< arr.count {
arr[i] = arr[i] + 1
Expand All @@ -32,7 +32,7 @@ func getArrayContainer() -> ArrayContainer {
}

@inline(never)
public func run_ArrayInClass(N: Int) {
public func run_ArrayInClass(_ N: Int) {
let a = getArrayContainer()
a.runLoop(N)
}
10 changes: 5 additions & 5 deletions benchmark/single-source/ArrayLiteral.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func makeArray() -> [Int] {
}

@inline(never)
public func run_ArrayLiteral(N: Int) {
public func run_ArrayLiteral(_ N: Int) {
for _ in 1...10000*N {
makeArray()
}
Expand All @@ -34,7 +34,7 @@ func addLiteralArray() -> Int {
}

@inline(never)
public func run_ArrayValueProp(N: Int) {
public func run_ArrayValueProp(_ N: Int) {
var res = 123
for _ in 1...10000*N {
res += addLiteralArray()
Expand Down Expand Up @@ -75,7 +75,7 @@ func addLiteralArray4() -> Int {
}

@inline(never)
public func run_ArrayValueProp2(N: Int) {
public func run_ArrayValueProp2(_ N: Int) {
var res = 123
for _ in 1...10000*N {
res += addLiteralArray2()
Expand All @@ -85,7 +85,7 @@ public func run_ArrayValueProp2(N: Int) {
}

@inline(never)
public func run_ArrayValueProp3(N: Int) {
public func run_ArrayValueProp3(_ N: Int) {
var res = 123
for _ in 1...10000*N {
res += addLiteralArray3()
Expand All @@ -95,7 +95,7 @@ public func run_ArrayValueProp3(N: Int) {
}

@inline(never)
public func run_ArrayValueProp4(N: Int) {
public func run_ArrayValueProp4(_ N: Int) {
var res = 123
for _ in 1...10000*N {
res += addLiteralArray4()
Expand Down
2 changes: 1 addition & 1 deletion benchmark/single-source/ArrayOfGenericPOD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func genStructArray() {
}

@inline(never)
public func run_ArrayOfGenericPOD(N: Int) {
public func run_ArrayOfGenericPOD(_ N: Int) {
for _ in 0...N {
genEnumArray()
genIOUArray()
Expand Down
2 changes: 1 addition & 1 deletion benchmark/single-source/ArrayOfGenericRef.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func genRefStructArray() {
}

@inline(never)
public func run_ArrayOfGenericRef(N: Int) {
public func run_ArrayOfGenericRef(_ N: Int) {
for _ in 0...N {
genPODRefArray()
genCommonRefArray()
Expand Down
2 changes: 1 addition & 1 deletion benchmark/single-source/ArrayOfPOD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func genStructArray() {
}

@inline(never)
public func run_ArrayOfPOD(N: Int) {
public func run_ArrayOfPOD(_ N: Int) {
for _ in 0...N {
genIntArray()
genEnumArray()
Expand Down
2 changes: 1 addition & 1 deletion benchmark/single-source/ArrayOfRef.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func genRefStructArray() {
}

@inline(never)
public func run_ArrayOfRef(N: Int) {
public func run_ArrayOfRef(_ N: Int) {
for _ in 0...N {
genPODRefArray()
genCommonRefArray()
Expand Down
4 changes: 2 additions & 2 deletions benchmark/single-source/ArraySubscript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import TestsUtils

@inline(never)
public func run_ArraySubscript(N: Int) {
public func run_ArraySubscript(_ N: Int) {
SRand()

let numArrays = 200*N
let numArrayElements = 100

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

var arrays = [[Int]](repeating: [], count: numArrays)
for i in 0..<numArrays {
Expand Down
4 changes: 2 additions & 2 deletions benchmark/single-source/BitCount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import Foundation
import TestsUtils

func countBitSet(num: Int) -> Int {
func countBitSet(_ num: Int) -> Int {
let bits = sizeof(Int) * 8
var cnt : Int = 0
var mask: Int = 1
Expand All @@ -30,7 +30,7 @@ func countBitSet(num: Int) -> Int {
}

@inline(never)
public func run_BitCount(N: Int) {
public func run_BitCount(_ N: Int) {
for _ in 1...100*N {
// Check some results.
CheckResults(countBitSet(1) == 1, "Incorrect results in BitCount.")
Expand Down
6 changes: 3 additions & 3 deletions benchmark/single-source/ByteSwap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Foundation
import TestsUtils

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

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

@inline(never)
public func run_ByteSwap(N: Int) {
public func run_ByteSwap(_ N: Int) {
for _ in 1...100*N {
// Check some results.
CheckResults(byteswap_logn(byteswap_n(2457)) == 2457, "Incorrect results in ByteSwap.")
Expand Down
4 changes: 2 additions & 2 deletions benchmark/single-source/Calculator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import TestsUtils
import Foundation

@inline(never)
func my_atoi_impl(input : String) -> Int {
func my_atoi_impl(_ input : String) -> Int {
switch input {
case "0": return 0
case "1": return 1
Expand All @@ -31,7 +31,7 @@ func my_atoi_impl(input : String) -> Int {
}

@inline(never)
public func run_Calculator(N: Int) {
public func run_Calculator(_ N: Int) {
var c = 0
for _ in 1...N*5000 {
c += my_atoi_impl("10")
Expand Down
6 changes: 3 additions & 3 deletions benchmark/single-source/CaptureProp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
//
//===----------------------------------------------------------------------===//

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

@inline(never)
func benchCaptureProp<S : Sequence
>(
s:S, _ f:(S.Iterator.Element, S.Iterator.Element)->S.Iterator.Element) -> S.Iterator.Element {
_ s: S, _ f:(S.Iterator.Element, S.Iterator.Element)->S.Iterator.Element) -> S.Iterator.Element {

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

public func run_CaptureProp(N: Int) {
public func run_CaptureProp(_ N: Int) {
let a = 1...10_000
for _ in 1...100*N {
benchCaptureProp(a, sum)
Expand Down
2 changes: 1 addition & 1 deletion benchmark/single-source/Chars.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import TestsUtils

@inline(never)
public func run_Chars(N: Int) {
public func run_Chars(_ N: Int) {
// Permute some characters.
let alphabet: [Character] = [
"A", "B", "C", "D", "E", "F", "G",
Expand Down
4 changes: 2 additions & 2 deletions benchmark/single-source/ClassArrayGetter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class Box {
}

@inline(never)
func sumArray(a: [Box]) -> Int {
func sumArray(_ a: [Box]) -> Int {
var s = 0
for i in 0..<a.count {
s += a[i].v
}
return s
}

public func run_ClassArrayGetter(N: Int) {
public func run_ClassArrayGetter(_ N: Int) {
let aSize = 10_000
var a: [Box] = []
a.reserveCapacity(aSize)
Expand Down
6 changes: 3 additions & 3 deletions benchmark/single-source/DeadArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
import TestsUtils

@inline(__always)
func debug(m:String) {}
func debug(_ m:String) {}

private var Count = 0

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

@inline(never)
func runLoop(var1: Int, var2: Int) {
func runLoop(_ var1: Int, var2: Int) {
for _ in 0..<100_000 {
debug("Var1: \(var1) Var2: \(var2)")
bar()
}
}

@inline(never)
public func run_DeadArray(N: Int) {
public func run_DeadArray(_ N: Int) {
for _ in 1...N {
Count = 0
runLoop(0, var2: 0)
Expand Down
4 changes: 2 additions & 2 deletions benchmark/single-source/DictTest2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import TestsUtils

@inline(never)
public func run_Dictionary2(N: Int) {
public func run_Dictionary2(_ N: Int) {
let size = 500
let ref_result = 199
var res = 0
Expand Down Expand Up @@ -57,7 +57,7 @@ func ==<T: Equatable>(lhs: Box<T>, rhs: Box<T>) -> Bool {
}

@inline(never)
public func run_Dictionary2OfObjects(N: Int) {
public func run_Dictionary2OfObjects(_ N: Int) {
let size = 500
let ref_result = 199
var res = 0
Expand Down
4 changes: 2 additions & 2 deletions benchmark/single-source/DictTest3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import TestsUtils

@inline(never)
public func run_Dictionary3(N: Int) {
public func run_Dictionary3(_ N: Int) {
let size1 = 100
let reps = 20
let ref_result = "1 99 20 1980"
Expand Down Expand Up @@ -64,7 +64,7 @@ func ==<T: Equatable>(lhs: Box<T>, rhs: Box<T>) -> Bool {
}

@inline(never)
public func run_Dictionary3OfObjects(N: Int) {
public func run_Dictionary3OfObjects(_ N: Int) {
let size1 = 100
let reps = 20
let ref_result = "1 99 20 1980"
Expand Down
2 changes: 1 addition & 1 deletion benchmark/single-source/DictionaryBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Stuff {
}

@inline(never)
public func run_DictionaryBridge(N: Int) {
public func run_DictionaryBridge(_ N: Int) {
for _ in 1...100*N {
_ = Stuff()
}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/single-source/DictionaryLiteral.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func makeDictionary() -> [Int: Int] {
}

@inline(never)
public func run_DictionaryLiteral(N: Int) {
public func run_DictionaryLiteral(_ N: Int) {
for _ in 1...10000*N {
makeDictionary()
}
Expand Down
Loading