Skip to content

Commit 3058718

Browse files
authored
Merge pull request #75789 from slavapestov/global-conformance-lookup-part-2
Move global conformance lookup entry points to ConformanceLookup.h
2 parents bfe72b4 + b2ff3c9 commit 3058718

File tree

89 files changed

+477
-477
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+477
-477
lines changed

include/swift/AST/ConformanceLookup.h

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
//===--- ConformanceLookup.h - Global conformance lookup --------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_AST_CONFORMANCELOOKUP_H
14+
#define SWIFT_AST_CONFORMANCELOOKUP_H
15+
16+
#include "llvm/ADT/ArrayRef.h"
17+
#include <optional>
18+
19+
namespace swift {
20+
21+
class CanType;
22+
class Type;
23+
class ProtocolConformanceRef;
24+
class ProtocolDecl;
25+
26+
/// Global conformance lookup, does not check conditional requirements.
27+
///
28+
/// \param type The type for which we are computing conformance.
29+
///
30+
/// \param protocol The protocol to which we are computing conformance.
31+
///
32+
/// \param allowMissing When \c true, the resulting conformance reference
33+
/// might include "missing" conformances, which are synthesized for some
34+
/// protocols as an error recovery mechanism.
35+
///
36+
/// \returns An invalid conformance if the search failed, otherwise an
37+
/// abstract, concrete or pack conformance, depending on the lookup type.
38+
ProtocolConformanceRef lookupConformance(Type type, ProtocolDecl *protocol,
39+
bool allowMissing = false);
40+
41+
/// Global conformance lookup, checks conditional requirements.
42+
/// Requires a contextualized type.
43+
///
44+
/// \param type The type for which we are computing conformance. Must not
45+
/// contain type parameters.
46+
///
47+
/// \param protocol The protocol to which we are computing conformance.
48+
///
49+
/// \param allowMissing When \c true, the resulting conformance reference
50+
/// might include "missing" conformances, which are synthesized for some
51+
/// protocols as an error recovery mechanism.
52+
///
53+
/// \returns An invalid conformance if the search failed, otherwise an
54+
/// abstract, concrete or pack conformance, depending on the lookup type.
55+
ProtocolConformanceRef checkConformance(Type type, ProtocolDecl *protocol,
56+
// Note: different default from
57+
// lookupConformance
58+
bool allowMissing = true);
59+
60+
/// Global conformance lookup, checks conditional requirements.
61+
/// Accepts interface types without context. If the conformance cannot be
62+
/// definitively established without the missing context, returns \c nullopt.
63+
///
64+
/// \param type The type for which we are computing conformance. Must not
65+
/// contain type parameters.
66+
///
67+
/// \param protocol The protocol to which we are computing conformance.
68+
///
69+
/// \param allowMissing When \c true, the resulting conformance reference
70+
/// might include "missing" conformances, which are synthesized for some
71+
/// protocols as an error recovery mechanism.
72+
///
73+
/// \returns An invalid conformance if the search definitively failed. An
74+
/// abstract, concrete or pack conformance, depending on the lookup type,
75+
/// if the search succeeded. `std::nullopt` if the type could have
76+
/// conditionally conformed depending on the context of the interface types.
77+
std::optional<ProtocolConformanceRef>
78+
checkConformanceWithoutContext(Type type,
79+
ProtocolDecl *protocol,
80+
// Note: different default from
81+
// lookupConformance
82+
bool allowMissing = true);
83+
84+
85+
/// Look for the conformance of the given existential type to the given
86+
/// protocol.
87+
ProtocolConformanceRef lookupExistentialConformance(Type type,
88+
ProtocolDecl *protocol);
89+
90+
/// Collect the conformances of \c fromType to each of the protocols of an
91+
/// existential type's layout.
92+
llvm::ArrayRef<ProtocolConformanceRef>
93+
collectExistentialConformances(CanType fromType, CanType existential,
94+
bool allowMissing = false);
95+
96+
}
97+
98+
#endif // SWIFT_AST_CONFORMANCELOOKUP_H

include/swift/AST/Module.h

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -884,76 +884,6 @@ class ModuleDecl
884884
DeclName name,
885885
SmallVectorImpl<ValueDecl*> &results) const;
886886

887-
/// Global conformance lookup, does not check conditional requirements.
888-
///
889-
/// \param type The type for which we are computing conformance.
890-
///
891-
/// \param protocol The protocol to which we are computing conformance.
892-
///
893-
/// \param allowMissing When \c true, the resulting conformance reference
894-
/// might include "missing" conformances, which are synthesized for some
895-
/// protocols as an error recovery mechanism.
896-
///
897-
/// \returns An invalid conformance if the search failed, otherwise an
898-
/// abstract, concrete or pack conformance, depending on the lookup type.
899-
static ProtocolConformanceRef lookupConformance(Type type, ProtocolDecl *protocol,
900-
bool allowMissing = false);
901-
902-
/// Global conformance lookup, checks conditional requirements.
903-
/// Requires a contextualized type.
904-
///
905-
/// \param type The type for which we are computing conformance. Must not
906-
/// contain type parameters.
907-
///
908-
/// \param protocol The protocol to which we are computing conformance.
909-
///
910-
/// \param allowMissing When \c true, the resulting conformance reference
911-
/// might include "missing" conformances, which are synthesized for some
912-
/// protocols as an error recovery mechanism.
913-
///
914-
/// \returns An invalid conformance if the search failed, otherwise an
915-
/// abstract, concrete or pack conformance, depending on the lookup type.
916-
static ProtocolConformanceRef checkConformance(Type type, ProtocolDecl *protocol,
917-
// Note: different default from
918-
// lookupConformance
919-
bool allowMissing = true);
920-
921-
/// Global conformance lookup, checks conditional requirements.
922-
/// Accepts interface types without context. If the conformance cannot be
923-
/// definitively established without the missing context, returns \c nullopt.
924-
///
925-
/// \param type The type for which we are computing conformance. Must not
926-
/// contain type parameters.
927-
///
928-
/// \param protocol The protocol to which we are computing conformance.
929-
///
930-
/// \param allowMissing When \c true, the resulting conformance reference
931-
/// might include "missing" conformances, which are synthesized for some
932-
/// protocols as an error recovery mechanism.
933-
///
934-
/// \returns An invalid conformance if the search definitively failed. An
935-
/// abstract, concrete or pack conformance, depending on the lookup type,
936-
/// if the search succeeded. `std::nullopt` if the type could have
937-
/// conditionally conformed depending on the context of the interface types.
938-
std::optional<ProtocolConformanceRef>
939-
static checkConformanceWithoutContext(Type type,
940-
ProtocolDecl *protocol,
941-
// Note: different default from
942-
// lookupConformance
943-
bool allowMissing = true);
944-
945-
946-
/// Look for the conformance of the given existential type to the given
947-
/// protocol.
948-
static ProtocolConformanceRef lookupExistentialConformance(Type type,
949-
ProtocolDecl *protocol);
950-
951-
/// Collect the conformances of \c fromType to each of the protocols of an
952-
/// existential type's layout.
953-
ArrayRef<ProtocolConformanceRef>
954-
static collectExistentialConformances(CanType fromType, CanType existential,
955-
bool allowMissing = false);
956-
957887
/// Find a member named \p name in \p container that was declared in this
958888
/// module.
959889
///

include/swift/SIL/SILCloner.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef SWIFT_SIL_SILCLONER_H
1818
#define SWIFT_SIL_SILCLONER_H
1919

20+
#include "swift/AST/ConformanceLookup.h"
2021
#include "swift/AST/GenericEnvironment.h"
2122
#include "swift/AST/ProtocolConformance.h"
2223
#include "swift/SIL/BasicBlockUtils.h"
@@ -50,7 +51,7 @@ struct SubstitutionMapWithLocalArchetypes {
5051
Type substType,
5152
ProtocolDecl *proto) {
5253
if (isa<LocalArchetypeType>(origType))
53-
return ModuleDecl::lookupConformance(substType, proto);
54+
return swift::lookupConformance(substType, proto);
5455
if (SubsMap)
5556
return SubsMap->lookupConformance(origType, proto);
5657

lib/AST/ASTContext.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "swift/ABI/MetadataValues.h"
2222
#include "swift/AST/ClangModuleLoader.h"
2323
#include "swift/AST/ConcreteDeclRef.h"
24+
#include "swift/AST/ConformanceLookup.h"
2425
#include "swift/AST/DiagnosticEngine.h"
2526
#include "swift/AST/DiagnosticsFrontend.h"
2627
#include "swift/AST/DiagnosticsSema.h"
@@ -1613,8 +1614,7 @@ ASTContext::getBuiltinInitDecl(NominalTypeDecl *decl,
16131614

16141615
auto type = decl->getDeclaredInterfaceType();
16151616
auto builtinProtocol = getProtocol(builtinProtocolKind);
1616-
auto builtinConformance = ModuleDecl::lookupConformance(
1617-
type, builtinProtocol);
1617+
auto builtinConformance = lookupConformance(type, builtinProtocol);
16181618
if (builtinConformance.isInvalid()) {
16191619
assert(false && "Missing required conformance");
16201620
witness = ConcreteDeclRef();
@@ -5834,7 +5834,7 @@ ASTContext::getForeignRepresentationInfo(NominalTypeDecl *nominal,
58345834
if (nominal != dc->getASTContext().getOptionalDecl()) {
58355835
if (auto objcBridgeable
58365836
= getProtocol(KnownProtocolKind::ObjectiveCBridgeable)) {
5837-
auto conformance = ModuleDecl::lookupConformance(
5837+
auto conformance = lookupConformance(
58385838
nominal->getDeclaredInterfaceType(), objcBridgeable);
58395839
if (conformance) {
58405840
result =
@@ -5986,7 +5986,7 @@ Type ASTContext::getBridgedToObjC(const DeclContext *dc, Type type,
59865986
if (!proto)
59875987
return ProtocolConformanceRef::forInvalid();
59885988

5989-
return ModuleDecl::lookupConformance(type, proto);
5989+
return lookupConformance(type, proto);
59905990
};
59915991

59925992
// Do we conform to _ObjectiveCBridgeable?

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "swift/AST/Builtins.h"
2424
#include "swift/AST/ClangModuleLoader.h"
2525
#include "swift/AST/Comment.h"
26+
#include "swift/AST/ConformanceLookup.h"
2627
#include "swift/AST/Decl.h"
2728
#include "swift/AST/Expr.h"
2829
#include "swift/AST/FileUnit.h"
@@ -1799,7 +1800,7 @@ void PrintAST::printSingleDepthOfGenericSignature(
17991800
return type;
18001801
},
18011802
[&](CanType depType, Type substType, ProtocolDecl *proto) {
1802-
return ModuleDecl::lookupConformance(substType, proto);
1803+
return lookupConformance(substType, proto);
18031804
});
18041805
};
18051806

0 commit comments

Comments
 (0)