Skip to content

Commit 08ba88f

Browse files
committed
Sema: Remove deriveConformanceForInvertible()
1 parent 6657882 commit 08ba88f

File tree

6 files changed

+15
-86
lines changed

6 files changed

+15
-86
lines changed

lib/AST/ConformanceLookup.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -677,31 +677,17 @@ LookupConformanceInModuleRequest::evaluate(
677677
} else {
678678
return ProtocolConformanceRef::forMissingOrInvalid(type, protocol);
679679
}
680-
} else if (protocol->isSpecificProtocol(KnownProtocolKind::Copyable)
681-
|| protocol->isSpecificProtocol(KnownProtocolKind::Escapable)) {
682-
const auto kp = protocol->getKnownProtocolKind().value();
683-
684-
if (!ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)
685-
&& kp == KnownProtocolKind::Copyable) {
680+
} else if (protocol->isSpecificProtocol(KnownProtocolKind::Copyable)) {
681+
if (!ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
686682
// Return an abstract conformance to maintain legacy compatability.
687683
// We only need to do this until we are properly dealing with or
688684
// omitting Copyable conformances in modules/interfaces.
689685

690686
if (nominal->canBeCopyable())
691687
return ProtocolConformanceRef(protocol);
692-
else
693-
return ProtocolConformanceRef::forMissingOrInvalid(type, protocol);
694688
}
695689

696-
// Try to infer the conformance.
697-
ImplicitKnownProtocolConformanceRequest cvRequest{nominal, kp};
698-
if (auto conformance = evaluateOrDefault(
699-
ctx.evaluator, cvRequest, nullptr)) {
700-
conformances.clear();
701-
conformances.push_back(conformance);
702-
} else {
703-
return ProtocolConformanceRef::forMissingOrInvalid(type, protocol);
704-
}
690+
return ProtocolConformanceRef::forMissingOrInvalid(type, protocol);
705691
} else if (protocol->isSpecificProtocol(
706692
KnownProtocolKind::BitwiseCopyable)) {
707693
// Try to infer BitwiseCopyable conformance.

lib/AST/ProtocolConformance.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,8 @@ void NominalTypeDecl::prepareConformanceTable() const {
10721072
auto *file = cast<FileUnit>(getModuleScopeContext());
10731073
if (file->getKind() != FileUnitKind::Source &&
10741074
file->getKind() != FileUnitKind::ClangModule &&
1075-
file->getKind() != FileUnitKind::DWARFModule) {
1075+
file->getKind() != FileUnitKind::DWARFModule &&
1076+
file->getKind() != FileUnitKind::Synthesized) {
10761077
return;
10771078
}
10781079

@@ -1089,7 +1090,6 @@ void NominalTypeDecl::prepareConformanceTable() const {
10891090
};
10901091

10911092
// Synthesize the unconditional conformances to invertible protocols.
1092-
// For conditional ones, see findSynthesizedConformances .
10931093
if (ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
10941094
// Classes get their conformances during ModuleDecl::lookupConformance.
10951095
if (!isa<ClassDecl>(this)) {
@@ -1101,14 +1101,19 @@ void NominalTypeDecl::prepareConformanceTable() const {
11011101
missingOne = true;
11021102
}
11031103

1104-
// FIXME: rdar://122289155 (NCGenerics: convert Equatable, Hashable, and RawRepresentable to ~Copyable.)
1104+
// Non-copyable and non-escaping types do not implicitly conform to
1105+
// any other protocols.
11051106
if (missingOne)
11061107
return;
11071108
}
11081109
} else if (!canBeCopyable()) {
11091110
return; // No synthesized conformances for move-only nominals.
11101111
}
11111112

1113+
// Don't do any more for synthesized FileUnits.
1114+
if (file->getKind() == FileUnitKind::Synthesized)
1115+
return;
1116+
11121117
// Add protocols for any synthesized protocol attributes.
11131118
for (auto attr : getAttrs().getAttributes<SynthesizedProtocolAttr>()) {
11141119
addSynthesized(attr->getProtocol());

lib/Sema/TypeCheckDecl.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3088,9 +3088,6 @@ ImplicitKnownProtocolConformanceRequest::evaluate(Evaluator &evaluator,
30883088
return deriveImplicitSendableConformance(evaluator, nominal);
30893089
case KnownProtocolKind::BitwiseCopyable:
30903090
return deriveImplicitBitwiseCopyableConformance(nominal);
3091-
case KnownProtocolKind::Escapable:
3092-
case KnownProtocolKind::Copyable:
3093-
return deriveConformanceForInvertible(evaluator, nominal, kp);
30943091
default:
30953092
llvm_unreachable("non-implicitly derived KnownProtocol");
30963093
}

lib/Sema/TypeCheckInvertible.cpp

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "swift/AST/InverseMarking.h"
2323
#include "TypeChecker.h"
2424

25-
namespace swift {
25+
using namespace swift;
2626

2727
/// MARK: diagnostic utilities
2828

@@ -267,12 +267,12 @@ static bool checkInvertibleConformanceCommon(ProtocolConformance *conformance,
267267
return conforms;
268268
}
269269

270-
bool checkEscapableConformance(ProtocolConformance *conformance) {
270+
bool swift::checkEscapableConformance(ProtocolConformance *conformance) {
271271
return checkInvertibleConformanceCommon(conformance,
272272
InvertibleProtocolKind::Escapable);
273273
}
274274

275-
bool checkCopyableConformance(ProtocolConformance *conformance) {
275+
bool swift::checkCopyableConformance(ProtocolConformance *conformance) {
276276
return checkInvertibleConformanceCommon(conformance,
277277
InvertibleProtocolKind::Copyable);
278278
}
@@ -313,57 +313,3 @@ bool StorageVisitor::visit(NominalTypeDecl *nominal, DeclContext *dc) {
313313
assert(!isa<ProtocolDecl>(nominal) || !isa<BuiltinTupleDecl>(nominal));
314314
return false;
315315
}
316-
317-
/// Produces implicit ProtocolConformances for known protocols. Does _not_ check
318-
/// whether the conformance is valid. Nor does it recursively check whether
319-
/// stored properties implicitly conform, so there is no risk of a
320-
/// request-evaluator cycle.
321-
///
322-
/// (the conformance is checked in `TypeChecker::checkConformancesInContext`).
323-
ProtocolConformance *deriveConformanceForInvertible(Evaluator &evaluator,
324-
NominalTypeDecl *nominal,
325-
KnownProtocolKind kp) {
326-
auto &ctx = nominal->getASTContext();
327-
auto *proto = ctx.getProtocol(kp);
328-
auto ip = getInvertibleProtocolKind(kp);
329-
if (!ip)
330-
llvm_unreachable("not an invertible protocol");
331-
332-
assert(!isa<ClassDecl>(nominal) && "classes aren't handled here");
333-
334-
// Generates a conformance for the nominal to the protocol.
335-
// The conformanceDC specifies THE decl context to use for the conformance.
336-
auto generateConformance =
337-
[&](DeclContext *conformanceDC) -> ProtocolConformance * {
338-
// Form a conformance.
339-
auto conformance = ctx.getNormalConformance(
340-
nominal->getDeclaredInterfaceType(), proto, nominal->getLoc(),
341-
conformanceDC, ProtocolConformanceState::Complete,
342-
/*isUnchecked=*/false, /*isPreconcurrency=*/false);
343-
conformance->setSourceKindAndImplyingConformance(
344-
ConformanceEntryKind::Synthesized, nullptr);
345-
346-
nominal->registerProtocolConformance(conformance, /*synthesized=*/true);
347-
return conformance;
348-
};
349-
350-
// Check what kind of inverse-marking we have to determine whether to generate
351-
// a conformance for IP.
352-
switch (nominal->hasInverseMarking(*ip).getKind()) {
353-
case InverseMarking::Kind::LegacyExplicit:
354-
case InverseMarking::Kind::Explicit:
355-
return nullptr; // No positive IP conformance will be inferred.
356-
357-
case InverseMarking::Kind::None:
358-
// All types already start with conformances to the invertible protocols in
359-
// this case, within `NominalTypeDecl::prepareConformanceTable`.
360-
//
361-
// There are various other kinds of SourceFiles, like SIL, which instead
362-
// get their conformances here instead.
363-
//
364-
// If there's no inverse, we infer a positive IP conformance.
365-
return generateConformance(nominal);
366-
}
367-
}
368-
369-
}

lib/Sema/TypeCheckInvertible.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ bool checkCopyableConformance(ProtocolConformance *conformance);
3636

3737
/// \returns true if the conformance to Escapable was successfully validated.
3838
bool checkEscapableConformance(ProtocolConformance *conformance);
39-
40-
/// You should be using `ImplicitKnownProtocolConformanceRequest` instead
41-
ProtocolConformance *deriveConformanceForInvertible(Evaluator &evaluator,
42-
NominalTypeDecl *nominal,
43-
KnownProtocolKind kp);
4439
}
4540

4641

test/decl/import/import.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: echo "public struct X {}; public var x = X()" | %target-swift-frontend -module-name import_builtin -parse-stdlib -emit-module -o %t -
2+
// RUN: echo "import Swift; public struct X {}; public var x = X()" | %target-swift-frontend -module-name import_builtin -parse-stdlib -emit-module -o %t -
33
// RUN: echo "public func foo() -> Int { return false }" > %t/import_text.swift
44
// RUN: echo "public func phoûx() -> Int { return false }" > %t/français.swift
55
// RUN: %target-swift-frontend -typecheck %s -I %t -I %S/../../Inputs/ -sdk "" -enable-source-import -module-name main -verify -show-diagnostics-after-fatal -verify-ignore-unknown

0 commit comments

Comments
 (0)