You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suppression must be declared on the type declaration itself, not on an extension.
201
201
202
-
### Transient and permanent notions<aname="transient-and-permanent"/>
202
+
### Transient and permanent notions<aname="transient-and-permanent"></a>
203
203
204
204
The Swift runtime already describes[^4] whether a type is bitwise-copyable.
205
205
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
223
223
For this reason, conformance to `BitwiseCopyable` is not inherent.
224
224
Its declaration on a public type provides a guarantee that the compiler cannot infer.
225
225
226
-
### Limitations of BitwiseCopyable<aname="limitations"/>
226
+
### Limitations of BitwiseCopyable<aname="limitations"></a>
227
227
228
228
Being declared with `@_marker`, `BitwiseCopyable` is a limited protocol.
229
229
Its limited nature allows the protocol's runtime behavior to be defined later, as needed.
@@ -283,7 +283,7 @@ public func storeBytes<T : BitwiseCopyable>(
283
283
284
284
This allows for optimal code generation because `memcpy` instead of value witnesses can be used.
285
285
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)).
287
287
288
288
## Effect on ABI stability
289
289
@@ -341,7 +341,7 @@ For example, casting a type which suppressed a conformance to `BitwiseCopyable`
341
341
If this approach were taken, such casting could be back-deployed as far as the oldest OS in which this runtime representation was added.
342
342
Further back deployment would be possible by adding conformance records to back deployed binaries.
343
343
344
-
#### Duck typing for BitwiseCopyable<aname="casting-by-duck-typing"/>
344
+
#### Duck typing for BitwiseCopyable<aname="casting-by-duck-typing"></a>
345
345
346
346
An alternative would be to dynamically treat any type that's bitwise-copyable as if it conformed to `BitwiseCopyable`.
347
347
@@ -383,11 +383,17 @@ If, in a subsequent proposal, the protocol were redefined as a composition, symb
383
383
384
384
**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.
385
385
386
+
### Deprecation of unconstrained functions dependent on `isPOD`<aname="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
+
386
392
## Acknowledgments
387
393
388
394
This proposal has benefitted from discussions with John McCall, Joe Groff, Andrew Trick, Michael Gottesman, and Arnold Schwaigofer.
389
395
390
-
## Appendix: Standard library conformers<aname="all-stdlib-conformers"/>
396
+
## Appendix: Standard library conformers<aname="all-stdlib-conformers"></a>
391
397
392
398
The following protocols in the standard library will gain the `BitwiseCopyable` constraint:
393
399
@@ -436,7 +442,7 @@ The following types in the standard library will gain the `BitwiseCopyable` cons
0 commit comments