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
Types exported from modules built with library evolution may be trivial
during one build and subsequently cease to be trivial. That means the
compiler must not infer the conformance for types exported from
resilient modules. To avoid dialecticization based on whether a module
is built in that way, require the annotation for all exported types.
Copy file name to clipboardExpand all lines: proposals/nnnn-bitwise-copyable.md
+9-7Lines changed: 9 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ We propose a new marker protocol `BitwiseCopyable` that can be conformed to by t
19
19
When compiling generic code with such constraints, the compiler can emit these efficient operations directly, only requiring minimal overhead to look up the size of the value at runtime.
20
20
Alternatively, developers can use this constraint to selectively provide high-performance variations of specific operations, such as bulk copying of a container.
21
21
22
-
[^1]: The term "trivial" is used in [SE-138](0138-unsaferawbufferpointer.md) and [SE-0370](0370-pointer-family-initialization-improvements.md) to refer to types with the property above. The discussion below will explain why certain generic or resilient types that are trivial will not in fact be `BitwiseCopyable`.
22
+
[^1]: The term "trivial" is used in [SE-138](0138-unsaferawbufferpointer.md) and [SE-0370](0370-pointer-family-initialization-improvements.md) to refer to types with the property above. The discussion below will explain why certain generic or exported types that are trivial will not in fact be `BitwiseCopyable`.
23
23
24
24
## Motivation
25
25
@@ -58,7 +58,7 @@ Many basic types in the standard library will conformed to this protocol.
58
58
Developer's own types may be conformed to the protocol, as well.
59
59
The compiler will check any such conformance and emit a diagnostic if the type contains elements that are not `BitwiseCopyable`.
60
60
61
-
Furthermore, when building a module, the compiler will infer conformance to `BitwiseCopyable` for any non-resilient struct or enum defined within the module whose stored members are all `BitwiseCopyable`.
61
+
Furthermore, when building a module, the compiler will infer conformance to `BitwiseCopyable` for any non-exported struct or enum defined within the module whose stored members are all `BitwiseCopyable`.
62
62
63
63
Developers cannot conform types defined in other modules to the protocol.
64
64
@@ -146,14 +146,16 @@ For generic types, a conformance will only be inferred if its fields uncondition
146
146
In the `RegularBox` example above, a conditional conformance will not be inferred.
147
147
If this is desired, the developer can explicitly write the conditional conformance.
148
148
149
-
### Inference for types in evolving libraries
149
+
### Inference for exported types
150
150
151
-
This does not apply to public (or `@usableFromInline`) types defined within a module built with library evolution.
152
-
While all the type's fields may be `BitwiseCopyable` at the moment, the compiler can't predict that they will always be.
151
+
This does not apply to exported (`public`, `package`, or `@usableFromInline`) types.
152
+
In the case of a library built with library evolution, while all the type's fields may be `BitwiseCopyable` at the moment, the compiler can't predict that they will always be.
153
153
If this is the developer's intent, they can explicitly conform the type.
154
+
To avoid having semantics that vary based on library evolution, the same applies to all exported (`public`, `package`, or `@usableFromInline`) types.
155
+
156
+
For `@frozen` types, however, `BitwiseCopyable` conformance will be inferred.
157
+
That's allowed, even in the case of a library built with library evolution, because the compiler can see that the type's fields are all `BitwiseCopyable` and knows that they will remain that way.
154
158
155
-
For `@frozen` types, however, `BitwiseCopyable` conformance will be inferred even when in a module built with library evolution.
156
-
That's because the compiler can see that the type's fields are all `BitwiseCopyable` and knows that they will remain that way.
157
159
For example, the compiler will infer a conformance of the following struct
0 commit comments