Skip to content

Commit a53b2dd

Browse files
committed
AST: Unconditionally synthesize Copyable/Escapable conformances
1 parent 7804ac7 commit a53b2dd

File tree

3 files changed

+29
-62
lines changed

3 files changed

+29
-62
lines changed

lib/AST/ConformanceLookup.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -640,17 +640,6 @@ LookupConformanceInModuleRequest::evaluate(
640640
} else {
641641
return ProtocolConformanceRef::forMissingOrInvalid(type, protocol);
642642
}
643-
} else if (protocol->isSpecificProtocol(KnownProtocolKind::Copyable)) {
644-
if (!ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
645-
// Return an abstract conformance to maintain legacy compatability.
646-
// We only need to do this until we are properly dealing with or
647-
// omitting Copyable conformances in modules/interfaces.
648-
649-
if (nominal->canBeCopyable())
650-
return ProtocolConformanceRef(protocol);
651-
}
652-
653-
return ProtocolConformanceRef::forMissingOrInvalid(type, protocol);
654643
} else if (protocol->isSpecificProtocol(
655644
KnownProtocolKind::BitwiseCopyable)) {
656645
// Try to infer BitwiseCopyable conformance.

lib/AST/Decl.cpp

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4920,20 +4920,13 @@ GenericParameterReferenceInfo ValueDecl::findExistentialSelfReferences(
49204920
}
49214921

49224922
static TypeDecl::CanBeInvertible::Result
4923-
conformanceExists(TypeDecl const *decl, InvertibleProtocolKind ip) {
4923+
conformanceExists(const NominalTypeDecl *decl, InvertibleProtocolKind ip) {
4924+
assert(isa<StructDecl>(decl) || isa<EnumDecl>(decl) || isa<ClassDecl>(decl));
4925+
49244926
auto *proto = decl->getASTContext().getProtocol(getKnownProtocolKind(ip));
49254927
assert(proto && "missing Copyable/Escapable from stdlib!");
49264928

4927-
// Handle protocols specially, without building a GenericSignature.
4928-
if (auto *protoDecl = dyn_cast<ProtocolDecl>(decl)) {
4929-
return protoDecl->inheritsFrom(proto)
4930-
? TypeDecl::CanBeInvertible::Always
4931-
: TypeDecl::CanBeInvertible::Never;
4932-
}
4933-
49344929
Type selfTy = decl->getDeclaredInterfaceType();
4935-
assert(selfTy);
4936-
49374930
auto conformance = decl->getModuleContext()->lookupConformance(selfTy, proto,
49384931
/*allowMissing=*/false);
49394932

@@ -4947,22 +4940,10 @@ conformanceExists(TypeDecl const *decl, InvertibleProtocolKind ip) {
49474940
}
49484941

49494942
TypeDecl::CanBeInvertible::Result NominalTypeDecl::canBeCopyable() const {
4950-
if (!getASTContext().LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
4951-
return !hasInverseMarking(InvertibleProtocolKind::Copyable)
4952-
? CanBeInvertible::Always
4953-
: CanBeInvertible::Never;
4954-
}
4955-
49564943
return conformanceExists(this, InvertibleProtocolKind::Copyable);
49574944
}
49584945

49594946
TypeDecl::CanBeInvertible::Result NominalTypeDecl::canBeEscapable() const {
4960-
if (!getASTContext().LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
4961-
return !hasInverseMarking(InvertibleProtocolKind::Escapable)
4962-
? CanBeInvertible::Always
4963-
: CanBeInvertible::Never;
4964-
}
4965-
49664947
return conformanceExists(this, InvertibleProtocolKind::Escapable);
49674948
}
49684949

lib/AST/ProtocolConformance.cpp

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,38 +1090,35 @@ void NominalTypeDecl::prepareConformanceTable() const {
10901090
};
10911091

10921092
// Synthesize the unconditional conformances to invertible protocols.
1093-
if (ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
1094-
// FIXME: We should be able to only resolve the inheritance clause once,
1095-
// but we also do it in ConformanceLookupTable::updateLookupTable().
1096-
InvertibleProtocolSet inverses;
1097-
bool anyObject = false;
1098-
(void) getDirectlyInheritedNominalTypeDecls(this, inverses, anyObject);
1099-
1100-
// Handle deprecated attributes.
1101-
if (getAttrs().hasAttribute<MoveOnlyAttr>())
1102-
inverses.insert(InvertibleProtocolKind::Copyable);
1103-
if (getAttrs().hasAttribute<NonEscapableAttr>())
1104-
inverses.insert(InvertibleProtocolKind::Escapable);
1105-
1106-
bool hasSuppressedConformances = false;
1107-
for (auto ip : InvertibleProtocolSet::full()) {
1108-
if (!inverses.contains(ip) ||
1109-
(isa<ClassDecl>(this) &&
1110-
!ctx.LangOpts.hasFeature(Feature::MoveOnlyClasses))) {
1111-
addSynthesized(ctx.getProtocol(getKnownProtocolKind(ip)));
1112-
} else {
1113-
hasSuppressedConformances = true;
1114-
}
1115-
}
11161093

1117-
// Non-copyable and non-escaping types do not implicitly conform to
1118-
// any other protocols.
1119-
if (hasSuppressedConformances)
1120-
return;
1121-
} else if (!canBeCopyable()) {
1122-
return; // No synthesized conformances for move-only nominals.
1094+
// FIXME: We should be able to only resolve the inheritance clause once,
1095+
// but we also do it in ConformanceLookupTable::updateLookupTable().
1096+
InvertibleProtocolSet inverses;
1097+
bool anyObject = false;
1098+
(void) getDirectlyInheritedNominalTypeDecls(this, inverses, anyObject);
1099+
1100+
// Handle deprecated attributes.
1101+
if (getAttrs().hasAttribute<MoveOnlyAttr>())
1102+
inverses.insert(InvertibleProtocolKind::Copyable);
1103+
if (getAttrs().hasAttribute<NonEscapableAttr>())
1104+
inverses.insert(InvertibleProtocolKind::Escapable);
1105+
1106+
bool hasSuppressedConformances = false;
1107+
for (auto ip : InvertibleProtocolSet::full()) {
1108+
if (!inverses.contains(ip) ||
1109+
(isa<ClassDecl>(this) &&
1110+
!ctx.LangOpts.hasFeature(Feature::MoveOnlyClasses))) {
1111+
addSynthesized(ctx.getProtocol(getKnownProtocolKind(ip)));
1112+
} else {
1113+
hasSuppressedConformances = true;
1114+
}
11231115
}
11241116

1117+
// Non-copyable and non-escaping types do not implicitly conform to
1118+
// any other protocols.
1119+
if (hasSuppressedConformances)
1120+
return;
1121+
11251122
// Don't do any more for synthesized FileUnits.
11261123
if (file->getKind() == FileUnitKind::Synthesized)
11271124
return;

0 commit comments

Comments
 (0)