Skip to content

Commit c6ea83d

Browse files
authored
Merge pull request #2469 from glessard/se-0426-amendment
[se-0426] omit stdlib deprecations, with explanation
2 parents b6daa9f + ea82628 commit c6ea83d

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

proposals/0426-bitwise-copyable.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public struct Coordinate3 {
189189
```
190190
to `BitwiseCopyable`.
191191

192-
### Suppressing inferred conformance<a name="suppression"/>
192+
### Suppressing inferred conformance<a name="suppression"></a>
193193

194194
To suppress the inference of `BitwiseCopyable`, `~BitwiseCopyable` can be added to the type's inheritance list.
195195

@@ -199,7 +199,7 @@ struct Coordinate4 : ~BitwiseCopyable {...}
199199

200200
Suppression must be declared on the type declaration itself, not on an extension.
201201

202-
### Transient and permanent notions<a name="transient-and-permanent"/>
202+
### Transient and permanent notions<a name="transient-and-permanent"></a>
203203

204204
The Swift runtime already describes[^4] whether a type is bitwise-copyable.
205205
It is surfaced, among other places, in the standard library function `_isPOD`[^5].
@@ -223,7 +223,7 @@ In other words returning true from `_isPOD` is a transient property, and conform
223223
For this reason, conformance to `BitwiseCopyable` is not inherent.
224224
Its declaration on a public type provides a guarantee that the compiler cannot infer.
225225

226-
### Limitations of BitwiseCopyable<a name="limitations"/>
226+
### Limitations of BitwiseCopyable<a name="limitations"></a>
227227

228228
Being declared with `@_marker`, `BitwiseCopyable` is a limited protocol.
229229
Its limited nature allows the protocol's runtime behavior to be defined later, as needed.
@@ -283,7 +283,7 @@ public func storeBytes<T : BitwiseCopyable>(
283283

284284
This allows for optimal code generation because `memcpy` instead of value witnesses can be used.
285285

286-
Additionally, we propose deprecating the original, unconstrained overloads of `loadUnaligned` and `storeBytes`.
286+
The existing methods that use a runtime assert instead of a type constraint will still be available (see [alternatives considered](#deprecation)).
287287

288288
## Effect on ABI stability
289289

@@ -341,7 +341,7 @@ For example, casting a type which suppressed a conformance to `BitwiseCopyable`
341341
If this approach were taken, such casting could be back-deployed as far as the oldest OS in which this runtime representation was added.
342342
Further back deployment would be possible by adding conformance records to back deployed binaries.
343343

344-
#### Duck typing for BitwiseCopyable<a name="casting-by-duck-typing"/>
344+
#### Duck typing for BitwiseCopyable<a name="casting-by-duck-typing"></a>
345345

346346
An alternative would be to dynamically treat any type that's bitwise-copyable as if it conformed to `BitwiseCopyable`.
347347

@@ -383,11 +383,17 @@ If, in a subsequent proposal, the protocol were redefined as a composition, symb
383383

384384
**Trivial** is widely used within the compiler and Swift evolution discussions to refer to the property of bitwise copyability. `BitwiseCopyable`, on the other hand, is more self-documenting.
385385

386+
### Deprecation of unconstrained functions dependent on `isPOD`<a name="deprecation"></a>
387+
388+
The standard library has a few pre-existing functions that receive a generic bitwise-copyable value as a parameter. These functions work with types for which the `_isPOD()` function returns true, even though they do not have a `BitwiseCopyable` conformance. If we were to deprecate these unconstrained versions, we would add unresolvable warnings to some of the codebases that use them. For example, they might use types that could be conditionally `BitwiseCopyable`, but come from a module whose types have not been conformed to `BitwiseCopyable` by their author. Furthermore, as explained [above](#transient-and-permanent), it is not necessarily the case that a transiently bitwise-copyable type can be permanently annotated as `BitwiseCopyable`.
389+
390+
At present, the unconstrained versions check that `_isPOD()` returns true in debug mode only. We may in the future consider changing them to check at all times, since in general their use in critical sections will have been updated to use the `BitwiseCopyable`-constrained overloads.
391+
386392
## Acknowledgments
387393

388394
This proposal has benefitted from discussions with John McCall, Joe Groff, Andrew Trick, Michael Gottesman, and Arnold Schwaigofer.
389395

390-
## Appendix: Standard library conformers<a name="all-stdlib-conformers"/>
396+
## Appendix: Standard library conformers<a name="all-stdlib-conformers"></a>
391397

392398
The following protocols in the standard library will gain the `BitwiseCopyable` constraint:
393399

@@ -436,7 +442,7 @@ The following types in the standard library will gain the `BitwiseCopyable` cons
436442
- `AtomicRepresentable.AtomicRepresentation`
437443
- `AtomicOptionalRepresentable.AtomicOptionalRepresentation`
438444

439-
## Appendix: Fluctuating bitwise-copyability<a name="fluctuating-bitwise-copyability"/>
445+
## Appendix: Fluctuating bitwise-copyability<a name="fluctuating-bitwise-copyability"></a>
440446

441447
Let's say the following type is defined in a framework built with library evolution.
442448

@@ -465,7 +471,7 @@ In the next version of the framework, to expose more information to its clients,
465471
public struct Dish {
466472
public let substrate: Noodle
467473
public let toppings: [Topping]
468-
public let isTopped: Bool { toppings.count > 0 }
474+
public var isTopped: Bool { toppings.count > 0 }
469475
}
470476
```
471477

@@ -480,7 +486,7 @@ public struct Dish {
480486
public let substrate: Noodle
481487
private let toppingOptions: Topping
482488
public let toppings: [Topping] { ... }
483-
public let isTopped: Bool { toppings.count > 0 }
489+
public var isTopped: Bool { toppings.count > 0 }
484490
}
485491
```
486492

0 commit comments

Comments
 (0)