Skip to content

Commit 903255a

Browse files
committed
AST: ModuleDecl::lookupConformance() is a static method
1 parent b9a80d5 commit 903255a

Some content is hidden

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

54 files changed

+184
-259
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/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

lib/AST/ASTContext.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,7 @@ ASTContext::getBuiltinInitDecl(NominalTypeDecl *decl,
15311531

15321532
auto type = decl->getDeclaredInterfaceType();
15331533
auto builtinProtocol = getProtocol(builtinProtocolKind);
1534-
auto builtinConformance = getStdlibModule()->lookupConformance(
1534+
auto builtinConformance = ModuleDecl::lookupConformance(
15351535
type, builtinProtocol);
15361536
if (builtinConformance.isInvalid()) {
15371537
assert(false && "Missing required conformance");
@@ -5671,7 +5671,7 @@ ASTContext::getForeignRepresentationInfo(NominalTypeDecl *nominal,
56715671
if (nominal != dc->getASTContext().getOptionalDecl()) {
56725672
if (auto objcBridgeable
56735673
= getProtocol(KnownProtocolKind::ObjectiveCBridgeable)) {
5674-
auto conformance = dc->getParentModule()->lookupConformance(
5674+
auto conformance = ModuleDecl::lookupConformance(
56755675
nominal->getDeclaredInterfaceType(), objcBridgeable);
56765676
if (conformance) {
56775677
result =
@@ -5823,7 +5823,7 @@ Type ASTContext::getBridgedToObjC(const DeclContext *dc, Type type,
58235823
if (!proto)
58245824
return ProtocolConformanceRef::forInvalid();
58255825

5826-
return dc->getParentModule()->lookupConformance(type, proto);
5826+
return ModuleDecl::lookupConformance(type, proto);
58275827
};
58285828

58295829
// Do we conform to _ObjectiveCBridgeable?

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,7 @@ void PrintAST::printSingleDepthOfGenericSignature(
18311831

18321832
unsigned typeContextDepth = 0;
18331833
SubstitutionMap subMap;
1834-
ModuleDecl *M = nullptr;
1834+
18351835
if (CurrentType && Current) {
18361836
if (!CurrentType->isExistentialType()) {
18371837
auto *DC = Current->getInnermostDeclContext()->getInnermostTypeContext();
@@ -1851,7 +1851,7 @@ void PrintAST::printSingleDepthOfGenericSignature(
18511851
return type;
18521852
},
18531853
[&](CanType depType, Type substType, ProtocolDecl *proto) {
1854-
return M->lookupConformance(substType, proto);
1854+
return ModuleDecl::lookupConformance(substType, proto);
18551855
});
18561856
};
18571857

lib/AST/ConformanceLookupTable.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -873,12 +873,11 @@ DeclContext *ConformanceLookupTable::getConformingContext(
873873
// FIXME: This is a hack because the inherited conformances aren't
874874
// getting updated properly.
875875
Type classTy = nominal->getDeclaredInterfaceType();
876-
ModuleDecl *module = nominal->getParentModule();
877876
do {
878877
Type superclassTy = classTy->getSuperclassForDecl(superclassDecl);
879878
if (superclassTy->is<ErrorType>())
880879
return nullptr;
881-
auto inheritedConformance = module->lookupConformance(
880+
auto inheritedConformance = ModuleDecl::lookupConformance(
882881
superclassTy, protocol, /*allowMissing=*/false);
883882
if (inheritedConformance.hasUnavailableConformance())
884883
inheritedConformance = ProtocolConformanceRef::forInvalid();
@@ -956,8 +955,7 @@ ConformanceLookupTable::getConformance(NominalTypeDecl *nominal,
956955
return nullptr;
957956

958957
// Look up the inherited conformance.
959-
ModuleDecl *module = entry->getDeclContext()->getParentModule();
960-
auto inheritedConformance = module->lookupConformance(
958+
auto inheritedConformance = ModuleDecl::lookupConformance(
961959
superclassTy, protocol, /*allowMissing=*/true);
962960

963961
// Form the inherited conformance.

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5128,7 +5128,7 @@ NominalTypeDecl::canConformTo(InvertibleProtocolKind ip) const {
51285128
Type selfTy = getDeclaredInterfaceType();
51295129
assert(selfTy);
51305130

5131-
auto conformance = getModuleContext()->lookupConformance(selfTy, proto,
5131+
auto conformance = ModuleDecl::lookupConformance(selfTy, proto,
51325132
/*allowMissing=*/false);
51335133

51345134
if (conformance.isInvalid())

lib/AST/DistributedDecl.cpp

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ bool swift::canSynthesizeDistributedActorCodableConformance(NominalTypeDecl *act
7979

8080
ExtensionDecl *
8181
swift::findDistributedActorAsActorExtension(
82-
ProtocolDecl *distributedActorProto, ModuleDecl *module) {
82+
ProtocolDecl *distributedActorProto) {
8383
ASTContext &C = distributedActorProto->getASTContext();
8484
auto name = C.getIdentifier("__actorUnownedExecutor");
8585
auto results = distributedActorProto->lookupDirect(
@@ -106,7 +106,7 @@ VarDecl *
106106
swift::getDistributedActorAsLocalActorComputedProperty(ModuleDecl *module) {
107107
auto &C = module->getASTContext();
108108
auto DA = C.getDistributedActorDecl();
109-
auto extension = findDistributedActorAsActorExtension(DA, module);
109+
auto extension = findDistributedActorAsActorExtension(DA);
110110

111111
if (!extension)
112112
return nullptr;
@@ -199,9 +199,8 @@ Type swift::getDistributedActorSystemType(NominalTypeDecl *actor) {
199199
return ErrorType::get(C); // FIXME(distributed): just use Type()
200200

201201
// Dig out the actor system type.
202-
auto module = actor->getParentModule();
203202
Type selfType = actor->getSelfInterfaceType();
204-
auto conformance = module->lookupConformance(selfType, DA);
203+
auto conformance = ModuleDecl::lookupConformance(selfType, DA);
205204
return conformance.getTypeWitnessByName(selfType, C.Id_ActorSystem);
206205
}
207206

@@ -215,9 +214,8 @@ static Type getTypeWitnessByName(NominalTypeDecl *type, ProtocolDecl *protocol,
215214
if (!protocol)
216215
return ErrorType::get(type->getASTContext());
217216

218-
auto module = type->getParentModule();
219217
Type selfType = type->getSelfInterfaceType();
220-
auto conformance = module->lookupConformance(selfType, protocol);
218+
auto conformance = ModuleDecl::lookupConformance(selfType, protocol);
221219
if (!conformance || conformance.isInvalid())
222220
return Type();
223221
return conformance.getTypeWitnessByName(selfType, member);
@@ -296,9 +294,8 @@ Type swift::getDistributedSerializationRequirementType(
296294
return Type();
297295

298296
// Dig out the serialization requirement type.
299-
auto module = nominal->getParentModule();
300297
Type selfType = nominal->getSelfInterfaceType();
301-
auto conformance = module->lookupConformance(selfType, protocol);
298+
auto conformance = ModuleDecl::lookupConformance(selfType, protocol);
302299
if (conformance.isInvalid())
303300
return Type();
304301

@@ -364,7 +361,7 @@ Type swift::getAssociatedTypeOfDistributedSystemOfActor(
364361
return memberTy->getReducedType(sig);
365362

366363
auto actorConformance =
367-
actorOrExtension->getParentModule()->lookupConformance(
364+
ModuleDecl::lookupConformance(
368365
actorType->getDeclaredInterfaceType(), actorProtocol);
369366
if (!actorConformance || actorConformance.isInvalid())
370367
return Type();
@@ -477,7 +474,6 @@ AbstractFunctionDecl::getDistributedMethodWitnessedProtocolRequirements() const
477474

478475
bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn) const {
479476
auto &C = getASTContext();
480-
auto module = getParentModule();
481477
auto *DC = getDeclContext();
482478

483479
if (!DC->isTypeContext() || !isGeneric())
@@ -494,7 +490,7 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
494490
C.getDistributedActorSystemDecl();
495491

496492
auto systemNominal = DC->getSelfNominalTypeDecl();
497-
auto distSystemConformance = module->lookupConformance(
493+
auto distSystemConformance = ModuleDecl::lookupConformance(
498494
systemNominal->getDeclaredInterfaceType(), systemProto);
499495

500496
if (distSystemConformance.isInvalid()) {
@@ -598,7 +594,7 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
598594
// --- Check: Act: DistributedActor,
599595
// Act.ID == Self.ActorID
600596
GenericTypeParamDecl *ActParam = genericParams->getParams()[0];
601-
auto ActConformance = module->lookupConformance(
597+
auto ActConformance = ModuleDecl::lookupConformance(
602598
mapTypeIntoContext(ActParam->getDeclaredInterfaceType()),
603599
C.getProtocol(KnownProtocolKind::DistributedActor));
604600
if (ActConformance.isInvalid()) {
@@ -607,7 +603,7 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
607603

608604
// --- Check: Err: Error
609605
GenericTypeParamDecl *ErrParam = genericParams->getParams()[1];
610-
auto ErrConformance = module->lookupConformance(
606+
auto ErrConformance = ModuleDecl::lookupConformance(
611607
mapTypeIntoContext(ErrParam->getDeclaredInterfaceType()),
612608
C.getProtocol(KnownProtocolKind::Error));
613609
if (ErrConformance.isInvalid()) {
@@ -681,7 +677,7 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
681677
}
682678

683679
for (auto requirementProto : requirementProtos) {
684-
auto conformance = module->lookupConformance(resultType, requirementProto);
680+
auto conformance = ModuleDecl::lookupConformance(resultType, requirementProto);
685681
if (conformance.isInvalid()) {
686682
return false;
687683
}
@@ -707,8 +703,6 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
707703
bool
708704
AbstractFunctionDecl::isDistributedActorSystemMakeInvocationEncoder() const {
709705
auto &C = getASTContext();
710-
auto module = getParentModule();
711-
712706
if (getBaseIdentifier() != C.Id_makeInvocationEncoder) {
713707
return false;
714708
}
@@ -728,7 +722,7 @@ AbstractFunctionDecl::isDistributedActorSystemMakeInvocationEncoder() const {
728722
}
729723

730724
auto returnTy = func->getResultInterfaceType();
731-
auto conformance = module->lookupConformance(
725+
auto conformance = ModuleDecl::lookupConformance(
732726
returnTy, C.getDistributedTargetInvocationEncoderDecl());
733727
if (conformance.isInvalid()) {
734728
return false;
@@ -784,7 +778,6 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordGenericSubstitut
784778
bool
785779
AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordArgument() const {
786780
auto &C = getASTContext();
787-
auto module = getParentModule();
788781

789782
auto func = dyn_cast<FuncDecl>(this);
790783
if (!func) {
@@ -801,7 +794,7 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordArgument() const
801794
C.getProtocol(KnownProtocolKind::DistributedTargetInvocationEncoder);
802795

803796
auto encoderNominal = getDeclContext()->getSelfNominalTypeDecl();
804-
auto protocolConformance = module->lookupConformance(
797+
auto protocolConformance = ModuleDecl::lookupConformance(
805798
encoderNominal->getDeclaredInterfaceType(), encoderProto);
806799

807800
if (protocolConformance.isInvalid()) {
@@ -916,7 +909,6 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordArgument() const
916909
bool
917910
AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordReturnType() const {
918911
auto &C = getASTContext();
919-
auto module = getParentModule();
920912

921913
auto func = dyn_cast<FuncDecl>(this);
922914
if (!func) {
@@ -933,7 +925,7 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordReturnType() con
933925
C.getProtocol(KnownProtocolKind::DistributedTargetInvocationEncoder);
934926

935927
auto encoderNominal = getDeclContext()->getSelfNominalTypeDecl();
936-
auto protocolConformance = module->lookupConformance(
928+
auto protocolConformance = ModuleDecl::lookupConformance(
937929
encoderNominal->getDeclaredInterfaceType(), encoderProto);
938930

939931
if (protocolConformance.isInvalid()) {
@@ -1026,7 +1018,7 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordReturnType() con
10261018
}
10271019

10281020
for (auto requirementProto : requirementProtos) {
1029-
auto conformance = module->lookupConformance(resultType, requirementProto);
1021+
auto conformance = ModuleDecl::lookupConformance(resultType, requirementProto);
10301022
if (conformance.isInvalid()) {
10311023
return false;
10321024
}
@@ -1043,7 +1035,6 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordReturnType() con
10431035
bool
10441036
AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordErrorType() const {
10451037
auto &C = getASTContext();
1046-
auto module = getParentModule();
10471038

10481039
auto func = dyn_cast<FuncDecl>(this);
10491040
if (!func) {
@@ -1060,7 +1051,7 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordErrorType() cons
10601051
C.getProtocol(KnownProtocolKind::DistributedTargetInvocationEncoder);
10611052

10621053
auto encoderNominal = getDeclContext()->getSelfNominalTypeDecl();
1063-
auto protocolConformance = module->lookupConformance(
1054+
auto protocolConformance = ModuleDecl::lookupConformance(
10641055
encoderNominal->getDeclaredInterfaceType(), encoderProto);
10651056

10661057
if (protocolConformance.isInvalid()) {
@@ -1124,7 +1115,7 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordErrorType() cons
11241115
// === Check generic parameters in detail
11251116
// --- Check: Err: Error
11261117
GenericTypeParamDecl *ErrParam = genericParams->getParams()[0];
1127-
auto ErrConformance = module->lookupConformance(
1118+
auto ErrConformance = ModuleDecl::lookupConformance(
11281119
mapTypeIntoContext(ErrParam->getDeclaredInterfaceType()),
11291120
C.getProtocol(KnownProtocolKind::Error));
11301121
if (ErrConformance.isInvalid()) {
@@ -1151,7 +1142,6 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordErrorType() cons
11511142
bool
11521143
AbstractFunctionDecl::isDistributedTargetInvocationDecoderDecodeNextArgument() const {
11531144
auto &C = getASTContext();
1154-
auto module = getParentModule();
11551145

11561146
auto func = dyn_cast<FuncDecl>(this);
11571147
if (!func) {
@@ -1168,7 +1158,7 @@ AbstractFunctionDecl::isDistributedTargetInvocationDecoderDecodeNextArgument() c
11681158
C.getProtocol(KnownProtocolKind::DistributedTargetInvocationDecoder);
11691159

11701160
auto decoderNominal = getDeclContext()->getSelfNominalTypeDecl();
1171-
auto protocolConformance = module->lookupConformance(
1161+
auto protocolConformance = ModuleDecl::lookupConformance(
11721162
decoderNominal->getDeclaredInterfaceType(), decoderProto);
11731163

11741164
if (protocolConformance.isInvalid()) {
@@ -1233,7 +1223,7 @@ AbstractFunctionDecl::isDistributedTargetInvocationDecoderDecodeNextArgument() c
12331223

12341224
for (auto requirementProto : requirementProtos) {
12351225
auto conformance =
1236-
module->lookupConformance(resultType, requirementProto);
1226+
ModuleDecl::lookupConformance(resultType, requirementProto);
12371227
if (conformance.isInvalid()) {
12381228
return false;
12391229
}
@@ -1245,7 +1235,6 @@ AbstractFunctionDecl::isDistributedTargetInvocationDecoderDecodeNextArgument() c
12451235
bool
12461236
AbstractFunctionDecl::isDistributedTargetInvocationResultHandlerOnReturn() const {
12471237
auto &C = getASTContext();
1248-
auto module = getParentModule();
12491238

12501239
auto func = dyn_cast<FuncDecl>(this);
12511240
if (!func) {
@@ -1262,7 +1251,7 @@ AbstractFunctionDecl::isDistributedTargetInvocationResultHandlerOnReturn() const
12621251
C.getProtocol(KnownProtocolKind::DistributedTargetInvocationResultHandler);
12631252

12641253
auto decoderNominal = getDeclContext()->getSelfNominalTypeDecl();
1265-
auto protocolConformance = module->lookupConformance(
1254+
auto protocolConformance = ModuleDecl::lookupConformance(
12661255
decoderNominal->getDeclaredInterfaceType(), decoderProto);
12671256

12681257
if (protocolConformance.isInvalid()) {
@@ -1331,7 +1320,7 @@ AbstractFunctionDecl::isDistributedTargetInvocationResultHandlerOnReturn() const
13311320

13321321
for (auto requirementProto : requirementProtos) {
13331322
auto conformance =
1334-
module->lookupConformance(argumentType, requirementProto);
1323+
ModuleDecl::lookupConformance(argumentType, requirementProto);
13351324
if (conformance.isInvalid()) {
13361325
return false;
13371326
}

lib/AST/ProtocolConformance.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,8 +1282,7 @@ findSynthesizedConformance(
12821282
if (!cvProto)
12831283
return nullptr;
12841284

1285-
auto module = dc->getParentModule();
1286-
auto conformance = module->lookupConformance(
1285+
auto conformance = ModuleDecl::lookupConformance(
12871286
nominal->getDeclaredInterfaceType(), cvProto);
12881287
if (!conformance || !conformance.isConcrete())
12891288
return nullptr;

lib/AST/Requirement.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ CheckRequirementResult Requirement::checkRequirement(
112112
}
113113

114114
auto *proto = getProtocolDecl();
115-
auto *module = proto->getParentModule();
116-
auto conformance = module->lookupConformance(
115+
auto conformance = ModuleDecl::lookupConformance(
117116
firstType, proto, allowMissing);
118117
if (!conformance)
119118
return CheckRequirementResult::RequirementFailure;

0 commit comments

Comments
 (0)