Skip to content

Commit 521ae13

Browse files
committed
slight tweak to how implicit conformance of nominals is generated
Also, only generate those conformances when the move-only feature is on, for now.
1 parent acfdf83 commit 521ae13

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/AST/Module.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,15 @@ LookupConformanceInModuleRequest::evaluate(
16591659
} else {
16601660
return ProtocolConformanceRef::forMissingOrInvalid(type, protocol);
16611661
}
1662+
} else if (protocol->isSpecificProtocol(KnownProtocolKind::Copyable)) {
1663+
// Only move-only nominals are not Copyable
1664+
if (nominal->isMoveOnly()) {
1665+
return ProtocolConformanceRef::forInvalid();
1666+
} else {
1667+
// FIXME: this should probably follow the Sendable case in that
1668+
// we should synthesize and append a ProtocolConformance to the `conformances` list.
1669+
return ProtocolConformanceRef(protocol);
1670+
}
16621671
} else {
16631672
// Was unable to infer the missing conformance.
16641673
return ProtocolConformanceRef::forMissingOrInvalid(type, protocol);

lib/AST/ProtocolConformance.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,11 +1097,6 @@ void NominalTypeDecl::prepareConformanceTable() const {
10971097
if (mutableThis->getAttrs().hasAttribute<GlobalActorAttr>()) {
10981098
addSynthesized(ctx.getProtocol(KnownProtocolKind::GlobalActor));
10991099
}
1100-
1101-
// All nominal types that are not move-only conform to Copyable.
1102-
if (!mutableThis->isMoveOnly()) {
1103-
addSynthesized(ctx.getProtocol(KnownProtocolKind::Copyable));
1104-
}
11051100
}
11061101

11071102
bool NominalTypeDecl::lookupConformance(
@@ -1239,7 +1234,11 @@ static SmallVector<ProtocolConformance *, 2> findSynthesizedConformances(
12391234
// Concrete types may synthesize some conformances
12401235
if (!isa<ProtocolDecl>(nominal)) {
12411236
trySynthesize(KnownProtocolKind::Sendable);
1242-
trySynthesize(KnownProtocolKind::Copyable);
1237+
1238+
// FIXME(kavon): make sure this conformance doesn't show up in swiftinterfaces
1239+
// before do this synthesis unconditionally.
1240+
if (dc->getASTContext().LangOpts.hasFeature(Feature::MoveOnly))
1241+
trySynthesize(KnownProtocolKind::Copyable);
12431242
}
12441243

12451244
/// Distributed actors can synthesize Encodable/Decodable, so look for those

0 commit comments

Comments
 (0)