[BitwiseCopyable] Infer and check constraint.

When the BitwiseCopyable experimental feature is enabled, infer types to
conform to `_BitwiseCopyable`.  The `_BitwiseCopyable` inference broadly
follows the approach taken to infer `Sendable`.

(1) Special types are conformed:
- function types if trivial
- metatypes
- builtin types if trivial

(2) TheTupleType is conditionally conformed.

(3) Nominal types are conformed if:
- non-public or public+fixed-layout
- enum or struct (non-class)
- every field conforms to _BitwiseCopyable

Additionally, check that nominal types which are explicitly conformed to
`_BitwiseCopyable` satisfy the latter two conditions of (3).

For a public, non-fixed-layout type to conform to `_BitwiseCopyable`,
the user must conform the type explicitly.

Finally, verify that conformances correspond to TypeLowering's notion of
triviality to the appropriate extent:
- if a type isn't trivial, it doesn't conform to `_BitwiseCopyable`
  unless it's an archetype
- if a type is trivial, it conforms to `_BitwiseCopyable` unless some
  field in its layout doesn't conform to `_BitwiseCopyable`, which is
  only permitted under certain circumstances (the type has generic
  parameters, the type is public non-fixed-layout, the type is a
  reference but has ReferenceStorage::Unmanaged, the type is a
  ModuleType, etc.)
This commit is contained in:
Nate Chandler
2024-01-09 08:05:49 -08:00
parent b98679bfb6
commit bac9e94a1d
23 changed files with 1022 additions and 8 deletions

View File

@@ -1258,6 +1258,11 @@ static SmallVector<ProtocolConformance *, 2> findSynthesizedConformances(
trySynthesize(KnownProtocolKind::Copyable);
trySynthesize(KnownProtocolKind::Escapable);
}
if (nominal->getASTContext().LangOpts.hasFeature(
Feature::BitwiseCopyable)) {
trySynthesize(KnownProtocolKind::BitwiseCopyable);
}
}
/// Distributed actors can synthesize Encodable/Decodable, so look for those