Skip to content

Commit 243e33b

Browse files
committed
Whitespace cleanup
1 parent 7e767dc commit 243e33b

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

proposals/NNNN-lifetime-dependency.md

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ They cannot guarantee that `buff` will outlive the `array`, which means there is
4040
Library authors trying to support this kind of code pattern today have a few options, but none are entirely satisfactory:
4141

4242
* The client developer can manually insert `withExtendedLifetime` and similar annotations to control the lifetime of specific objects.
43-
This is awkward and error-prone.
44-
We would prefer a mechanism where the library author can declare the necessary semantics and have the compiler automatically enforce them.
43+
This is awkward and error-prone.
44+
We would prefer a mechanism where the library author can declare the necessary semantics and have the compiler automatically enforce them.
4545
* The library author can store a back-reference to the container as part of their "pointer" or "slice" object.
46-
However, this incurs reference counting overhead which sacrifices some of the performance gains that pointer-based designs are generally intended to provide.
47-
In addition, this approach is not possible in environments that lack support for dynamic allocation.
46+
However, this incurs reference counting overhead which sacrifices some of the performance gains that pointer-based designs are generally intended to provide.
47+
In addition, this approach is not possible in environments that lack support for dynamic allocation.
4848
* The library author can make the pointer information available only within a scoped function, but this is also unsafe, as demonstrated by well-meaning developers who extract the pointer out of such functions using code like that below.
49-
Even when used correctly, scoped functions can lead to a pyramid of deeply-indented code blocks.
49+
Even when used correctly, scoped functions can lead to a pyramid of deeply-indented code blocks.
5050

5151
```
5252
// 🛑 The following line of code is dangerous! DO NOT DO THIS!
@@ -90,7 +90,7 @@ Our proposal would allow you to declare an `array.bufferReference()` method as f
9090
```
9191
extension Array {
9292
borrowing func bufferReference() -> borrow(self) BufferReference<Element> {
93-
... construct a BufferReference ...
93+
... construct a BufferReference ...
9494
}
9595
}
9696
```
@@ -102,20 +102,20 @@ In essence, the `borrow(self)` annotation extends that borrowed access beyond th
102102
Specifically, the `borrow(self)` annotation informs the compiler that:
103103

104104
* The array must not be destroyed until after the `BufferReference<Element>` is destroyed.
105-
This ensures that use-after-free cannot occur.
105+
This ensures that use-after-free cannot occur.
106106
* The array must not be mutated while the `BufferReference<Element>` value exists.
107-
This enforces the usual Swift exclusivity rules.
107+
This enforces the usual Swift exclusivity rules.
108108

109109
In addition to `borrow(self)`, we also propose supporting three other lifetime dependency annotations:
110110

111111
#### `mutate(self)` or `mutate(arg)`
112112

113113
Let’s consider another hypothetical type: a `MutatingBufferReference<T>` type that could provide indirect mutating access to a block of memory.
114-
This would need to be exposed slightly differently, since it provides *write* access:
114+
This would need to be exposed slightly differently, since it provides *write* access:
115115

116116
```
117117
func mutatingBufferReference(to: inout Array) -> mutate(to) MutatingBufferReference<Element> {
118-
... construct a MutatingBufferReference ...
118+
... construct a MutatingBufferReference ...
119119
}
120120
```
121121

@@ -170,7 +170,7 @@ func complexView(data: Array<Item>, statistics: Array<Statistics>, other: Int)
170170
#### Allowed Lifetime Dependencies
171171

172172
Only certain types of lifetime dependencies make sense, depending on the type of argument.
173-
The syntax is somewhat different for functions and methods, though the basic rules are essentially the same.
173+
The syntax is somewhat different for functions and methods, though the basic rules are essentially the same.
174174

175175
**Functions:** A function with a lifetime dependency annotation generally takes this form:
176176

@@ -192,10 +192,10 @@ Further:
192192
* `copy` lifetime-type is only permitted with `borrowing` or `inout` parameter-convention
193193

194194
**Methods:** Similar rules apply to `self` lifetime dependencies on methods.
195-
Given a method of this form:
195+
Given a method of this form:
196196

197197
```
198-
<mutation-modifier> func method(... args ...) -> <lifetime-type>(self) ResultType
198+
<mutation-modifier> func method(... args ...) -> <lifetime-type>(self) ResultType
199199
```
200200

201201
We only permit
@@ -207,9 +207,8 @@ We only permit
207207

208208
The rules above apply regardless of whether the parameter-convention or mutation-modifier is explicitly written or is implicit.
209209

210-
**Initializers:** An initializer dependency annotation takes one of two forms.
211-
An initializer can define a lifetime dependency on one of its arguments.
212-
In this case, the rules are the same as for “Functions” above:
210+
**Initializers:** An initializer can define a lifetime dependency on one of its arguments.
211+
In this case, the rules are the same as for “Functions” above:
213212

214213
```
215214
init(arg: <parameter-convention> ArgType) -> <lifetime-type>(arg) Self
@@ -265,7 +264,7 @@ This modifies *function-result* in the Swift grammar as follows:
265264
266265
Here, the argument to the lifetime modifier must be one of the following:
267266

268-
* *external-parameter-name:* the external name of one of the function parameters,
267+
* *external-parameter-name:* the external name of one of the function parameters,
269268
* *parameter-index:* a numeric index of one of the parameters in the *parameter-clause* (the first parameter is number zero), or
270269
* the token **`self`**.
271270

@@ -413,7 +412,7 @@ For example:
413412
func f(arg1: Type1) -> borrow(arg1) NonEscapableType // 🛑 `arg1` must be marked `borrowing`
414413
415414
... Type ... {
416-
func f() -> borrow(self) Self // 🛑 method must be marked `borrowing`
415+
func f() -> borrow(self) Self // 🛑 method must be marked `borrowing`
417416
}
418417
```
419418

0 commit comments

Comments
 (0)