@@ -218,7 +218,7 @@ we mean a specific instance of a semantic, user-language value.
218
218
219
219
For example, consider the following Swift code:
220
220
221
- ```
221
+ ``` swift
222
222
var x = [1 ,2 ,3 ]
223
223
var y = x
224
224
```
@@ -418,7 +418,7 @@ discussed in the introduction. For example, suppose that
418
418
the callee loads a value from its argument, then calls
419
419
a function which the optimizer cannot reason about:
420
420
421
- ```
421
+ ``` swift
422
422
extension Array {
423
423
mutating func organize (_ predicate : (Element ) -> Bool ) {
424
424
let first = self [0 ]
@@ -916,7 +916,7 @@ semantically necessary when working with non-copyable types.
916
916
917
917
We propose to remove this limitation in a straightforward way:
918
918
919
- ```
919
+ ``` swift
920
920
inout root = & tree.root
921
921
922
922
shared elements = self .queue
@@ -946,7 +946,7 @@ cases to be spelled explicitly:
946
946
947
947
- A function argument can be explicitly declared ` owned ` :
948
948
949
- ```
949
+ ``` swift
950
950
func append (_ values : owned [Element ]) {
951
951
...
952
952
}
@@ -960,7 +960,7 @@ cases to be spelled explicitly:
960
960
961
961
- A function argument can be explicitly declared ` shared ` .
962
962
963
- ```
963
+ ``` swift
964
964
func == (left : shared String , right : shared String ) -> Bool {
965
965
...
966
966
}
@@ -994,7 +994,7 @@ cases to be spelled explicitly:
994
994
995
995
- A method can be explicitly declared ` consuming ` .
996
996
997
- ```
997
+ ``` swift
998
998
consuming func moveElements (into collection : inout [Element ]) {
999
999
...
1000
1000
}
@@ -1060,7 +1060,7 @@ sequence cannot be iterated multiple times, this is a
1060
1060
This can be explicitly requested by declaring the iteration
1061
1061
variable ` owned ` :
1062
1062
1063
- ```
1063
+ ``` swift
1064
1064
for owned employee in company.employees {
1065
1065
newCompany.employees .append (employee)
1066
1066
}
@@ -1083,7 +1083,7 @@ operation on `Collection`.
1083
1083
This can be explicitly requested by declaring the iteration
1084
1084
variable ` shared ` :
1085
1085
1086
- ```
1086
+ ``` swift
1087
1087
for shared employee in company.employees {
1088
1088
if ! employee.respected { throw CatastrophicHRFailure () }
1089
1089
}
@@ -1093,7 +1093,7 @@ It is also used by default when the sequence type is known to
1093
1093
conform to ` Collection ` , since this is the optimal way of
1094
1094
iterating over a collection.
1095
1095
1096
- ```
1096
+ ``` swift
1097
1097
for employee in company.employees {
1098
1098
if ! employee.respected { throw CatastrophicHRFailure () }
1099
1099
}
@@ -1117,7 +1117,7 @@ operation on `MutableCollection`.
1117
1117
This must be explicitly requested by declaring the
1118
1118
iteration variable ` inout ` :
1119
1119
1120
- ```
1120
+ ``` swift
1121
1121
for inout employee in company.employees {
1122
1122
employee.respected = true
1123
1123
}
@@ -1145,7 +1145,7 @@ languages to conveniently implement iteration. In Swift,
1145
1145
to follow this pattern, we would need to allow the definition
1146
1146
of generator functions, e.g.:
1147
1147
1148
- ```
1148
+ ``` swift
1149
1149
mutating generator iterateMutable () -> inout Element {
1150
1150
var i = startIndex, e = endIndex
1151
1151
while i != e {
@@ -1193,7 +1193,7 @@ to invoke one because these would only be used in accessors.
1193
1193
The idea is that, instead of defining ` get ` and ` set ` ,
1194
1194
a storage declaration could define ` read ` and ` modify ` :
1195
1195
1196
- ```
1196
+ ``` swift
1197
1197
var x: String
1198
1198
var y: String
1199
1199
var first: String {
@@ -1231,7 +1231,7 @@ For this reason, we propose the `move` function. Conceptually,
1231
1231
` move ` is simply a top-level function in the Swift standard
1232
1232
library:
1233
1233
1234
- ```
1234
+ ``` swift
1235
1235
func move <T >(_ value : T) -> T {
1236
1236
return value
1237
1237
}
@@ -1270,7 +1270,7 @@ variables are initialized before use.
1270
1270
1271
1271
` copy ` is a top-level function in the Swift standard library:
1272
1272
1273
- ```
1273
+ ``` swift
1274
1274
func copy <T >(_ value : T) -> T {
1275
1275
return value
1276
1276
}
@@ -1294,7 +1294,7 @@ value is returned. This is useful for several reasons:
1294
1294
1295
1295
` endScope ` is a top-level function in the Swift standard library:
1296
1296
1297
- ```
1297
+ ``` swift
1298
1298
func endScope <T >(_ value : T) -> () {}
1299
1299
```
1300
1300
@@ -1326,7 +1326,7 @@ every component is statically resolvable to a storage declaration.
1326
1326
There is some recurring interest in the community in allowing programs
1327
1327
to abstract over storage, so that you might say:
1328
1328
1329
- ```
1329
+ ``` swift
1330
1330
let prop = Widget.weight
1331
1331
```
1332
1332
@@ -1408,7 +1408,7 @@ a `moveonly` context are also implicitly `moveonly`.
1408
1408
1409
1409
A type can be a ` moveonly ` context:
1410
1410
1411
- ```
1411
+ ``` swift
1412
1412
moveonly struct Array <Element > {
1413
1413
// Element and Array<Element> are not assumed to be copyable here
1414
1414
}
@@ -1420,7 +1420,7 @@ hierarchies of associated types.
1420
1420
1421
1421
An extension can be a ` moveonly ` context:
1422
1422
1423
- ```
1423
+ ``` swift
1424
1424
moveonly extension Array {
1425
1425
// Element and Array<Element> are not assumed to be copyable here
1426
1426
}
@@ -1429,7 +1429,7 @@ moveonly extension Array {
1429
1429
A type can declare conditional copyability using a conditional
1430
1430
conformance:
1431
1431
1432
- ```
1432
+ ``` swift
1433
1433
moveonly extension Array : Copyable where Element : Copyable {
1434
1434
...
1435
1435
}
@@ -1450,7 +1450,7 @@ it a non-`moveonly` extension is an error.
1450
1450
1451
1451
A function can be a ` moveonly ` context:
1452
1452
1453
- ```
1453
+ ``` swift
1454
1454
extension Array {
1455
1455
moveonly func report <U >(_ u : U)
1456
1456
}
@@ -1483,7 +1483,7 @@ used to express the unique ownership of resources. For
1483
1483
example, here is a simple file-handle type that ensures
1484
1484
that the handle is closed when the value is destroyed:
1485
1485
1486
- ```
1486
+ ``` swift
1487
1487
moveonly struct File {
1488
1488
var descriptor: Int32
1489
1489
0 commit comments