Skip to content

Commit 1c2dbf4

Browse files
committed
NCGenerics: avoid synthesizing Equatable, etc.
While certain kinds of enums synthesize Equatable, Hashable, and RawRepresentable conformances, we can't yet permit noncopyable types to synthesize those until we upgrade those protocols themselves to not require `Copyable` conformers. For example, Equatable needs to be changed in the stdlib to be `protocol Equatable: ~Copyable`, etc. I'm deferring upgrade work until a bit later.
1 parent 1795f7f commit 1c2dbf4

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lib/AST/ProtocolConformance.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,20 +1076,10 @@ void NominalTypeDecl::prepareConformanceTable() const {
10761076
}
10771077

10781078
SmallPtrSet<ProtocolDecl *, 2> protocols;
1079-
const bool haveNoncopyableGenerics =
1080-
ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics);
1081-
10821079
auto addSynthesized = [&](ProtocolDecl *proto) {
10831080
if (!proto)
10841081
return;
10851082

1086-
// No synthesized conformances for move-only nominals.
1087-
if (!haveNoncopyableGenerics && !canBeCopyable()) {
1088-
// assumption is Sendable gets synthesized elsewhere.
1089-
assert(!proto->isSpecificProtocol(KnownProtocolKind::Sendable));
1090-
return;
1091-
}
1092-
10931083
if (protocols.count(proto) == 0) {
10941084
ConformanceTable->addSynthesizedConformance(
10951085
mutableThis, proto, mutableThis);
@@ -1099,12 +1089,22 @@ void NominalTypeDecl::prepareConformanceTable() const {
10991089

11001090
// Synthesize the unconditional conformances to invertible protocols.
11011091
// For conditional ones, see findSynthesizedConformances .
1102-
if (haveNoncopyableGenerics) {
1092+
if (ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
1093+
bool missingOne = false;
11031094
for (auto ip : InvertibleProtocolSet::full()) {
11041095
auto invertible = getMarking(ip);
11051096
if (!invertible.getInverse() || bool(invertible.getPositive()))
11061097
addSynthesized(ctx.getProtocol(getKnownProtocolKind(ip)));
1098+
else
1099+
missingOne = true;
11071100
}
1101+
1102+
// FIXME: rdar://122289155 (NCGenerics: convert Equatable, Hashable, and RawRepresentable to ~Copyable.)
1103+
if (missingOne)
1104+
return;
1105+
1106+
} else if (!canBeCopyable()) {
1107+
return; // No synthesized conformances for move-only nominals.
11081108
}
11091109

11101110
// Add protocols for any synthesized protocol attributes.

0 commit comments

Comments
 (0)