Skip to content

Commit ab0ffe3

Browse files
authored
Merge pull request swiftlang#74998 from slavapestov/global-conformance-lookup
AST: Stop pretending that conformance lookup takes the module into account
2 parents b9149e9 + ca9c09f commit ab0ffe3

File tree

161 files changed

+724
-1024
lines changed

Some content is hidden

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

161 files changed

+724
-1024
lines changed

include/swift/AST/DistributedDecl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ getDistributedActorAsActorConformanceRef(ASTContext &C);
118118
/// the DistributedActor-as-Actor conformance.
119119
ExtensionDecl *
120120
findDistributedActorAsActorExtension(
121-
ProtocolDecl *distributedActorProto, ModuleDecl *module);
121+
ProtocolDecl *distributedActorProto);
122122

123123
bool isDistributedActorAsLocalActorComputedProperty(VarDecl *var);
124124

include/swift/AST/GenericSignature.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,6 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
322322
SmallVector<Requirement, 2> &reqs,
323323
SmallVector<InverseRequirement, 2> &inverses) const;
324324

325-
/// Look up a stored conformance in the generic signature. These are formed
326-
/// from same-type constraints placed on associated types of generic
327-
/// parameters which have conformance constraints on them.
328-
ProtocolConformanceRef lookupConformance(CanType depTy,
329-
ProtocolDecl *proto) const;
330-
331325
/// Iterate over all generic parameters, passing a flag to the callback
332326
/// indicating if the generic parameter is canonical or not.
333327
void forEachParam(

include/swift/AST/Module.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,8 @@ class ModuleDecl
886886
///
887887
/// \returns An invalid conformance if the search failed, otherwise an
888888
/// abstract, concrete or pack conformance, depending on the lookup type.
889-
ProtocolConformanceRef lookupConformance(Type type, ProtocolDecl *protocol,
890-
bool allowMissing = false);
889+
static ProtocolConformanceRef lookupConformance(Type type, ProtocolDecl *protocol,
890+
bool allowMissing = false);
891891

892892
/// Global conformance lookup, checks conditional requirements.
893893
/// Requires a contextualized type.
@@ -903,9 +903,10 @@ class ModuleDecl
903903
///
904904
/// \returns An invalid conformance if the search failed, otherwise an
905905
/// abstract, concrete or pack conformance, depending on the lookup type.
906-
ProtocolConformanceRef checkConformance(Type type, ProtocolDecl *protocol,
907-
// Note: different default from lookupConformance
908-
bool allowMissing = true);
906+
static ProtocolConformanceRef checkConformance(Type type, ProtocolDecl *protocol,
907+
// Note: different default from
908+
// lookupConformance
909+
bool allowMissing = true);
909910

910911
/// Global conformance lookup, checks conditional requirements.
911912
/// Accepts interface types without context. If the conformance cannot be
@@ -925,22 +926,23 @@ class ModuleDecl
925926
/// if the search succeeded. `std::nullopt` if the type could have
926927
/// conditionally conformed depending on the context of the interface types.
927928
std::optional<ProtocolConformanceRef>
928-
checkConformanceWithoutContext(Type type,
929-
ProtocolDecl *protocol,
930-
// Note: different default from lookupConformance
931-
bool allowMissing = true);
929+
static checkConformanceWithoutContext(Type type,
930+
ProtocolDecl *protocol,
931+
// Note: different default from
932+
// lookupConformance
933+
bool allowMissing = true);
932934

933935

934936
/// Look for the conformance of the given existential type to the given
935937
/// protocol.
936-
ProtocolConformanceRef lookupExistentialConformance(Type type,
937-
ProtocolDecl *protocol);
938+
static ProtocolConformanceRef lookupExistentialConformance(Type type,
939+
ProtocolDecl *protocol);
938940

939941
/// Collect the conformances of \c fromType to each of the protocols of an
940942
/// existential type's layout.
941943
ArrayRef<ProtocolConformanceRef>
942-
collectExistentialConformances(CanType fromType, CanType existential,
943-
bool allowMissing = false);
944+
static collectExistentialConformances(CanType fromType, CanType existential,
945+
bool allowMissing = false);
944946

945947
/// Find a member named \p name in \p container that was declared in this
946948
/// module.

include/swift/AST/NameLookupRequests.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -732,21 +732,18 @@ class DirectPrecedenceGroupLookupRequest
732732

733733
class LookupConformanceDescriptor final {
734734
public:
735-
ModuleDecl *Mod;
736735
Type Ty;
737736
ProtocolDecl *PD;
738737

739-
LookupConformanceDescriptor(ModuleDecl *Mod, Type Ty, ProtocolDecl *PD)
740-
: Mod(Mod), Ty(Ty), PD(PD) {}
738+
LookupConformanceDescriptor(Type Ty, ProtocolDecl *PD) : Ty(Ty), PD(PD) {}
741739

742740
friend llvm::hash_code hash_value(const LookupConformanceDescriptor &desc) {
743-
return llvm::hash_combine(desc.Mod, desc.Ty.getPointer(), desc.PD);
741+
return llvm::hash_combine(desc.Ty.getPointer(), desc.PD);
744742
}
745743

746744
friend bool operator==(const LookupConformanceDescriptor &lhs,
747745
const LookupConformanceDescriptor &rhs) {
748-
return lhs.Mod == rhs.Mod && lhs.Ty.getPointer() == rhs.Ty.getPointer() &&
749-
lhs.PD == rhs.PD;
746+
return lhs.Ty.getPointer() == rhs.Ty.getPointer() && lhs.PD == rhs.PD;
750747
}
751748

752749
friend bool operator!=(const LookupConformanceDescriptor &lhs,

include/swift/AST/Requirement.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,7 @@ checkRequirementsWithoutContext(ArrayRef<Requirement> requirements);
241241
/// Check if each requirement is satisfied after applying the given
242242
/// substitutions. The substitutions must replace all type parameters that
243243
/// appear in the requirement with concrete types or archetypes.
244-
CheckRequirementsResult checkRequirements(ModuleDecl *module,
245-
ArrayRef<Requirement> requirements,
244+
CheckRequirementsResult checkRequirements(ArrayRef<Requirement> requirements,
246245
TypeSubstitutionFn substitutions,
247246
SubstOptions options = std::nullopt);
248247

include/swift/AST/Type.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,8 @@ using LookupConformanceFn = llvm::function_ref<GenericFunction>;
9797
/// Functor class suitable for use as a \c LookupConformanceFn to look up a
9898
/// conformance through a module.
9999
class LookUpConformanceInModule {
100-
ModuleDecl *M;
101100
public:
102-
explicit LookUpConformanceInModule(ModuleDecl *M)
103-
: M(M) {}
101+
explicit LookUpConformanceInModule() {}
104102

105103
ProtocolConformanceRef operator()(CanType dependentType,
106104
Type conformingReplacementType,
@@ -116,21 +114,6 @@ class MakeAbstractConformanceForGenericType {
116114
Type conformingReplacementType,
117115
ProtocolDecl *conformedProtocol) const;
118116
};
119-
120-
/// Functor class suitable for use as a \c LookupConformanceFn that fetches
121-
/// conformances from a generic signature.
122-
class LookUpConformanceInSignature {
123-
const GenericSignatureImpl *Sig;
124-
public:
125-
LookUpConformanceInSignature(const GenericSignatureImpl *Sig)
126-
: Sig(Sig) {
127-
assert(Sig && "Cannot lookup conformance in null signature!");
128-
}
129-
130-
ProtocolConformanceRef operator()(CanType dependentType,
131-
Type conformingReplacementType,
132-
ProtocolDecl *conformedProtocol) const;
133-
};
134117

135118
/// Flags that can be passed when substituting into a type.
136119
enum class SubstFlags {

include/swift/AST/Types.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,8 +1309,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
13091309
/// \param genericEnv If non-null and the type is nested inside of a
13101310
/// generic function, generic parameters of the outer context are
13111311
/// mapped to context archetypes of this generic environment.
1312-
SubstitutionMap getContextSubstitutionMap(ModuleDecl *module,
1313-
const DeclContext *dc,
1312+
SubstitutionMap getContextSubstitutionMap(const DeclContext *dc,
13141313
GenericEnvironment *genericEnv=nullptr);
13151314

13161315
/// Deprecated version of the above.
@@ -1322,8 +1321,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
13221321
///
13231322
/// \param genericEnv If non-null, generic parameters of the member are
13241323
/// mapped to context archetypes of this generic environment.
1325-
SubstitutionMap getMemberSubstitutionMap(ModuleDecl *module,
1326-
const ValueDecl *member,
1324+
SubstitutionMap getMemberSubstitutionMap(const ValueDecl *member,
13271325
GenericEnvironment *genericEnv=nullptr);
13281326

13291327
/// Deprecated version of the above.
@@ -1340,7 +1338,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
13401338
/// \param member The property whose type we are substituting.
13411339
///
13421340
/// \returns The resulting property type.
1343-
Type getTypeOfMember(ModuleDecl *module, const VarDecl *member);
1341+
Type getTypeOfMember(const VarDecl *member);
13441342

13451343
/// Retrieve the type of the given member as seen through the given base
13461344
/// type, substituting generic arguments where necessary.
@@ -1371,8 +1369,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
13711369
/// method's generic parameters.
13721370
///
13731371
/// \returns The resulting member type.
1374-
Type getTypeOfMember(ModuleDecl *module, const ValueDecl *member,
1375-
Type memberType);
1372+
Type getTypeOfMember(const ValueDecl *member, Type memberType);
13761373

13771374
/// Get the type of a superclass member as seen from the subclass,
13781375
/// substituting generic parameters, dynamic Self return, and the
@@ -7075,7 +7072,7 @@ class DependentMemberType : public TypeBase {
70757072
/// Substitute the base type, looking up our associated type in it if it is
70767073
/// non-dependent. Returns null if the member could not be found in the new
70777074
/// base.
7078-
Type substBaseType(ModuleDecl *M, Type base);
7075+
Type substBaseType(Type base);
70797076

70807077
/// Substitute the base type, looking up our associated type in it if it is
70817078
/// non-dependent. Returns null if the member could not be found in the new

include/swift/SIL/DynamicCasts.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ void emitIndirectConditionalCastWithScalar(
109109
ProfileCounter FalseCount = ProfileCounter());
110110

111111
/// Does the type conform to the _ObjectiveCBridgeable protocol.
112-
bool isObjectiveCBridgeable(ModuleDecl *M, CanType Ty);
112+
bool isObjectiveCBridgeable(CanType Ty);
113113

114114
/// Get the bridged NS class of a CF class if it exists. Returns
115115
/// an empty CanType if such class does not exist.
116-
CanType getNSBridgedClassOfCFClass(ModuleDecl *M, CanType type);
116+
CanType getNSBridgedClassOfCFClass(CanType type);
117117

118118
/// Does the type conform to Error.
119-
bool isError(ModuleDecl *M, CanType Ty);
119+
bool isError(CanType Ty);
120120

121121
struct SILDynamicCastKind {
122122
enum innerty : std::underlying_type<SILInstructionKind>::type {

include/swift/SIL/SILCloner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct SubstitutionMapWithLocalArchetypes {
5050
Type substType,
5151
ProtocolDecl *proto) {
5252
if (isa<LocalArchetypeType>(origType))
53-
return proto->getParentModule()->lookupConformance(substType, proto);
53+
return ModuleDecl::lookupConformance(substType, proto);
5454
if (SubsMap)
5555
return SubsMap->lookupConformance(origType, proto);
5656

include/swift/SIL/TypeSubstCloner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class TypeSubstCloner : public SILClonerWithScopes<ImplClass> {
331331
remappedOrigFnType->getDifferentiabilityResultIndices(),
332332
dfei->getDerivativeFunctionKind(),
333333
getBuilder().getModule().Types,
334-
LookUpConformanceInModule(SwiftMod))
334+
LookUpConformanceInModule())
335335
->getWithoutDifferentiability();
336336
SILType remappedDerivativeFnType = getOpType(dfei->getType());
337337
// If remapped derivative type and derivative remapped type are equal, do

0 commit comments

Comments
 (0)