Skip to content

Commit ae74c36

Browse files
committed
Merge pull request #1930 from manavgabhawala/master
[CHANGELOG][Docs] Update CHANGELOG and Docs to reflect new parsing of function parameter attributes like 'var', 'let' and 'inout' for SE-0003, SE-0031 and SE-0053
2 parents 6edac6a + ae929ee commit ae74c36

13 files changed

+53
-26
lines changed

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,31 @@ Note: This is in reverse chronological order, so newer entries are added to the
33
Swift 3.0
44
-------
55

6+
* [SE-0031](https://github.com/apple/swift-evolution/blob/master/proposals/0031-adjusting-inout-declarations.md) The location of the inout attribtue has been moved to after the `:` and before the parameter type.
7+
```swift
8+
func foo(inout x: Int) {
9+
}
10+
```
11+
will now be written as:
12+
```swift
13+
func foo(x: inout Int) {
14+
}
15+
```
16+
17+
* [SE-0053](https://github.com/apple/swift-evolution/blob/master/proposals/0053-remove-let-from-function-parameters.md) `let` is no longer accepted as a parameter attribute for functions. The compiler provides a fixit to remove it from the function declaration.
18+
19+
* [SE-0003](https://github.com/apple/swift-evolution/blob/master/proposals/0003-remove-var-parameters.md) `var` is no longer accepted as a parameter attribute for functions. The compiler provides a fixit to create a shadow copy in the function body.
20+
```swift
21+
func foo(var x: Int) {
22+
}
23+
```
24+
will now be written as:
25+
```swift
26+
func foo(x: Int) {
27+
var x = x
28+
}
29+
```
30+
631
* The "none" members of imported NS_OPTIONS option sets are marked as unavailable
732
when they are imported. Use [] to make an empty option set, instead of a None member.
833

docs/MutationModel.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ unless the method is attributed with ``mutating``:
252252

253253
.. parsed-literal::
254254
255-
func f(x: Int, inout y: Int) {
255+
func f(x: Int, y: inout Int) {
256256
y = x // ok, y is an inout parameter
257257
x = y // **Error:** function parameter 'x' is immutable
258258
}

docs/OptimizationTips.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ through the usage of ``inout`` parameters:
253253

254254
::
255255

256-
func append_one_in_place(inout a: [Int]) {
256+
func append_one_in_place(a: inout [Int]) {
257257
a.append(1)
258258
}
259259

docs/SIL.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ has the following lowered type::
315315
@callee_owned () -> @owned @callee_owned (@in (Int,Int)) -> @out Float.
316316

317317
As another example, suppose that ``h`` has type
318-
``Generator<(Int, @inout Int) -> Float>``. Neither ``(Int, @inout Int)``
319-
nor ``@inout Int`` are potential results of substitution because they
318+
``Generator<(Int, inout Int) -> Float>``. Neither ``(Int, inout Int)``
319+
nor ``inout Int`` are potential results of substitution because they
320320
aren't materializable, so ``h.fn`` has the following lowered type::
321321

322322
@callee_owned () -> @owned @callee_owned (@in Int, @inout Int) -> @out Float
@@ -1447,7 +1447,7 @@ getter prior to calling the function and to write back to the property
14471447
on return by loading from the buffer and invoking the setter with the final
14481448
value. This Swift function::
14491449

1450-
func inout(x:@inout Int) {
1450+
func inout(x: inout Int) {
14511451
x = 1
14521452
}
14531453

docs/StdlibAPIGuidelines.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ Acceptable Short or Non-Descriptive Names
183183

184184
.. parsed-literal::
185185
186-
func swap<**T**>(inout lhs: T, inout rhs: T)
186+
func swap<**T**>(lhs: inout T, rhs: inout T)
187187
188188
* `lhs` and `rhs` are acceptable names for binary operator or
189189
symmetric binary function parameters:
@@ -192,7 +192,7 @@ Acceptable Short or Non-Descriptive Names
192192
193193
func + (**lhs**: Int, **rhs**: Int) -> Int
194194
195-
func swap<T>(inout **lhs**: T, inout **rhs**: T)
195+
func swap<T>(**lhs**: inout T, **rhs**: inout T)
196196
197197
* `body` is an acceptable name for a trailing closure argument when
198198
the resulting construct is supposed to act like a language extension

docs/archive/LangRef.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ <h4 id="attribute-inout"><tt>inout</tt> Attribute</h4>
803803
For example, the following code:
804804

805805
<pre class=example>
806-
func foo(inout x: Int) -> () -> Int {
806+
func foo(x: inout Int) -> () -> Int {
807807
func bar() -> Int {
808808
x += 1
809809
return x

docs/proposals/Accessors.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ completing the operation. This can present the opportunity for
434434
corruption if the interleaved code modifies the original value.
435435
Consider the following code::
436436

437-
func operate(inout value: Int, count: Int) { ... }
437+
func operate(value: inout Int, count: Int) { ... }
438438

439439
var array: [Int] = [1,2,3,4]
440440
operate(&array[0], { array = []; return 0 }())
@@ -454,7 +454,7 @@ Nor can this be fixed with a purely local analysis; consider::
454454
class C { var array: [Int] }
455455
let global_C = C()
456456

457-
func assign(inout value: Int) {
457+
func assign(value: inout Int) {
458458
C.array = []
459459
value = 0
460460
}
@@ -706,7 +706,7 @@ that was technically copied beforehand. For example::
706706
// This function copies array before modifying it, but because that
707707
// copy is of a value undergoing modification, the copy will use
708708
// the same buffer and therefore observe updates to the element.
709-
func foo(inout element: Int) {
709+
func foo(element: inout Int) {
710710
oldArray = array
711711
element = 4
712712
}
@@ -781,7 +781,7 @@ depend on how the l-value is used:
781781

782782
Example::
783783

784-
func swap<T>(inout lhs: T, inout rhs: T) {}
784+
func swap<T>(lhs: inout T, rhs: inout T) {}
785785

786786
// object is a variable of class type
787787
swap(&leftObject.array, &rightObject.array)

docs/proposals/CPointerArgumentInterop.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,15 @@ An example of a conformance for ``ObjCInOut``::
316316
typealias WritebackType = Builtin.RawPointer
317317

318318
@_transparent
319-
static func _createWriteback(inout ref: T!)
319+
static func _createWriteback(ref: inout T!)
320320
-> Builtin.RawPointer {
321321
// The initial object reference is passed into the callee effectively
322322
// __unsafe_unretained, so pass it as a RawPointer.
323323
return unsafeBitCast(ref, Builtin.RawPointer.self)
324324
}
325325

326326
@_transparent
327-
static func _commitWriteback(inout ref: T!,
327+
static func _commitWriteback(ref: inout T!,
328328
value: Builtin.RawPointer) {
329329
// The reference is autoreleased on return from the caller, so retain it
330330
// by loading it back as a T?.

docs/proposals/Inplace.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ We see at least four problems with this kind of API:
9292
mutating version of ``op(x: T, y: U) -> T`` can always be defined
9393
as ::
9494

95-
func opInPlace(inout x: T, y: U) {
95+
func opInPlace(x: inout T, y: U) {
9696
x = op(x, y)
9797
}
9898

@@ -361,15 +361,15 @@ An assignment operator for an immutable class ``X`` always has the form:
361361

362362
.. parsed-literal::
363363
364-
func *op*\ **=** (**inout** lhs: X, rhs: Y) {
364+
func *op*\ **=** (lhs: **inout** X, rhs: Y) {
365365
lhs = *expression creating a new X object*
366366
}
367367
368368
or, with COW optimization:
369369

370370
.. parsed-literal::
371371
372-
func *op*\ **=** (**inout** lhs: X, rhs: Y) {
372+
func *op*\ **=** (lhs: **inout** X, rhs: Y) {
373373
if isUniquelyReferenced(&lhs) {
374374
lhs.\ *mutateInPlace*\ (rhs)
375375
}

docs/proposals/OptimizerEffects.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ Example:::
400400

401401
When the optimizer optimizes a loop:::
402402

403-
func memset(inout A: [Int], value: Int) {
403+
func memset(A: inout [Int], value: Int) {
404404
for i in 0 .. A.size {
405405
A[i] = value
406406
f()
@@ -409,7 +409,7 @@ When the optimizer optimizes a loop:::
409409

410410
It will see the following calls because methods with attributes are not inlined.::
411411

412-
func memset(inout A: [Int], value: Int) {
412+
func memset(A: inout [Int], value: Int) {
413413
for i in 0 .. A.size {
414414
makeUnique(&A)
415415
addr = getElementAddr(i, &A)
@@ -768,7 +768,8 @@ after the mutating function. This lets the second ``getElement`` function get
768768
another array parameter which prevents CSE of the two ``getElement`` calls.
769769
Shown in this swift-SIL pseudo code::
770770

771-
func add(var arr: Array<Int>, i: Int) -> Int {
771+
func add(arr: Array<Int>, i: Int) -> Int {
772+
var arr = arr
772773
let e1 = getElement(i, arr)
773774
store arr to stack_array
774775
setElement(i, 0, &stack_array)
@@ -782,7 +783,8 @@ which directly access the storage, are not inlined during high-level SIL.
782783
Optimizations like code motion could move a store to the storage over a
783784
``readnone getElement``.::
784785

785-
func add(var arr: Array<Int>, i: Int) -> Int {
786+
func add(arr: Array<Int>, i: Int) -> Int {
787+
var arr = arr
786788
let e1 = getElement(i, arr)
787789
store arr to stack_array
788790
stack_array.storage[i] = 0 // (1)

docs/proposals/OptionSets.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ protocol::
9999
protocol OptionSet : Equatable {
100100
// Set intersection
101101
@infix func &(_:Self, _:Self) -> Self
102-
@infix func &=(@inout _:Self, _:Self)
102+
@infix func &=(_: inout Self, _:Self)
103103

104104
// Set union
105105
@infix func |(_:Self, _:Self) -> Self
106-
@infix func |=(@inout _:Self, _:Self)
106+
@infix func |=(_: inout Self, _:Self)
107107

108108
// Set xor
109109
@infix func ^(_:Self, _:Self) -> Self
110-
@infix func ^=(@inout _:Self, _:Self)
110+
@infix func ^=(_: inout Self, _:Self)
111111

112112
// Set negation
113113
@prefix func ~(_:Self) -> Self

docs/proposals/ValueSemantics.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ clonable classes:
234234
func cycle_length<State>(
235235
s : State,
236236
**next : (x : State) -> State,**
237-
**equal : ([inout] x : State, [inout] y : State) -> Bool**
237+
**equal : (x : [inout] State, y : [inout] State) -> Bool**
238238
) -> Int
239239
requires State : EqualityComparable
240240
{

docs/proposals/archive/UnifiedFunctionSyntax.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ Swift method name for that Objective-C API. For example, by default,
193193
the ``NSURL`` method ``+bookmarkDataWithContentsOfURL:error:`` will
194194
come into Swift as::
195195

196-
class func bookmarkDataWithContents(ofURL bookmarkFileURL: NSURL, inout error: NSError) -> NSData
196+
class func bookmarkDataWithContents(ofURL bookmarkFileURL: NSURL, error: inout NSError) -> NSData
197197

198198
However, one can provide a different mapping with the ``method_name``
199199
attribute::

0 commit comments

Comments
 (0)