Skip to content

Commit 3fcda14

Browse files
committed
AST: ModuleDecl::checkConformance() is a static method
1 parent 1901862 commit 3fcda14

Some content is hidden

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

45 files changed

+148
-194
lines changed

lib/AST/ConformanceLookup.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ bool TypeBase::isSendableType() {
796796
if (auto *fas = getAs<AnyFunctionType>())
797797
return fas->isSendable();
798798

799-
auto conformance = proto->getParentModule()->checkConformance(
799+
auto conformance = ModuleDecl::checkConformance(
800800
this, proto, false /*allow missing*/);
801801
return conformance && !conformance.hasUnavailableConformance();
802802
}
@@ -849,7 +849,7 @@ static bool conformsToInvertible(CanType type, InvertibleProtocolKind ip) {
849849
SILTokenType>()));
850850

851851
const bool conforms =
852-
(bool) proto->getParentModule()->checkConformance(
852+
(bool) ModuleDecl::checkConformance(
853853
type, proto,
854854
/*allowMissing=*/false);
855855

lib/AST/Decl.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -11635,9 +11635,7 @@ ActorIsolation::forActorInstanceParameter(Expr *actor,
1163511635
auto baseType =
1163611636
memberRef->getBase()->getType()->getMetatypeInstanceType();
1163711637
if (auto globalActor = ctx.getProtocol(KnownProtocolKind::GlobalActor)) {
11638-
auto *dc = declRef.getDecl()->getDeclContext();
11639-
auto *module = dc->getParentModule();
11640-
auto conformance = module->checkConformance(baseType, globalActor);
11638+
auto conformance = ModuleDecl::checkConformance(baseType, globalActor);
1164111639
if (conformance &&
1164211640
conformance.getWitnessByName(baseType, ctx.Id_shared) == declRef) {
1164311641
return ActorIsolation::forGlobalActor(baseType);

lib/AST/LifetimeDependence.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,19 @@ static LifetimeDependenceKind getLifetimeDependenceKindFromDecl(
175175
: LifetimeDependenceKind::Inherit;
176176
}
177177

178-
static bool isBitwiseCopyable(Type type, ModuleDecl *mod, ASTContext &ctx) {
178+
static bool isBitwiseCopyable(Type type, ASTContext &ctx) {
179179
auto *bitwiseCopyableProtocol =
180180
ctx.getProtocol(KnownProtocolKind::BitwiseCopyable);
181181
if (!bitwiseCopyableProtocol) {
182182
return false;
183183
}
184-
return (bool)(mod->checkConformance(type, bitwiseCopyableProtocol));
184+
return (bool)(ModuleDecl::checkConformance(type, bitwiseCopyableProtocol));
185185
}
186186

187187
std::optional<LifetimeDependenceInfo>
188188
LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd) {
189189
auto *dc = afd->getDeclContext();
190190
auto &ctx = dc->getASTContext();
191-
auto *mod = afd->getModuleContext();
192191
auto &diags = ctx.Diags;
193192
auto capacity = afd->hasImplicitSelfDecl()
194193
? (afd->getParameters()->size() + 1)
@@ -216,7 +215,7 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd) {
216215
bool isCompatible = true;
217216
// Lifetime dependence always propagates through temporary BitwiseCopyable
218217
// values, even if the dependence is scoped.
219-
if (!isBitwiseCopyable(paramType, mod, ctx)) {
218+
if (!isBitwiseCopyable(paramType, ctx)) {
220219
isCompatible = isLifetimeDependenceCompatibleWithOwnership(
221220
lifetimeKind, ownership, afd);
222221
}
@@ -416,7 +415,6 @@ std::optional<LifetimeDependenceInfo>
416415
LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd) {
417416
auto *dc = afd->getDeclContext();
418417
auto &ctx = dc->getASTContext();
419-
auto *mod = afd->getModuleContext();
420418

421419
if (!ctx.LangOpts.hasFeature(Feature::NonescapableTypes)) {
422420
return std::nullopt;
@@ -450,7 +448,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd) {
450448
if (!cd && afd->hasImplicitSelfDecl()) {
451449
Type selfTypeInContext = dc->getSelfTypeInContext();
452450
if (selfTypeInContext->isEscapable()) {
453-
if (isBitwiseCopyable(selfTypeInContext, mod, ctx)) {
451+
if (isBitwiseCopyable(selfTypeInContext, ctx)) {
454452
diags.diagnose(
455453
returnLoc,
456454
diag::lifetime_dependence_method_escapable_bitwisecopyable_self);
@@ -483,7 +481,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd) {
483481
}
484482
auto paramOwnership = param->getValueOwnership();
485483
if (paramTypeInContext->isEscapable()) {
486-
if (isBitwiseCopyable(paramTypeInContext, mod, ctx)) {
484+
if (isBitwiseCopyable(paramTypeInContext, ctx)) {
487485
continue;
488486
}
489487
if (paramOwnership == ValueOwnership::Default) {

lib/IDE/ConformingMethodList.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void ConformingMethodListCallbacks::getMatchingMethods(
193193

194194
// The return type conforms to any of the requested protocols.
195195
for (auto Proto : ExpectedTypes) {
196-
if (CurModule->checkConformance(resultTy, Proto))
196+
if (ModuleDecl::checkConformance(resultTy, Proto))
197197
return true;
198198
}
199199

lib/IRGen/GenArchetype.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ const TypeInfo *TypeConverter::convertArchetypeType(ArchetypeType *archetype) {
415415
IGM.getSwiftModule()->getASTContext().getProtocol(
416416
KnownProtocolKind::BitwiseCopyable);
417417
// The protocol won't be present in swiftinterfaces from older SDKs.
418-
if (bitwiseCopyableProtocol && IGM.getSwiftModule()->checkConformance(
418+
if (bitwiseCopyableProtocol && ModuleDecl::checkConformance(
419419
archetype, bitwiseCopyableProtocol)) {
420420
return BitwiseCopyableTypeInfo::create(storageType, abiAccessible);
421421
}

lib/IRGen/GenEnum.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -7324,8 +7324,8 @@ ResilientEnumImplStrategy::completeEnumTypeLayout(TypeConverter &TC,
73247324
IGM.getSwiftModule()->getASTContext().getProtocol(
73257325
KnownProtocolKind::BitwiseCopyable);
73267326
if (bitwiseCopyableProtocol &&
7327-
IGM.getSwiftModule()->checkConformance(Type.getASTType(),
7328-
bitwiseCopyableProtocol)) {
7327+
ModuleDecl::checkConformance(Type.getASTType(),
7328+
bitwiseCopyableProtocol)) {
73297329
return BitwiseCopyableTypeInfo::create(enumTy, abiAccessible);
73307330
}
73317331
return registerEnumTypeInfo(

lib/IRGen/GenStruct.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ const TypeInfo *TypeConverter::convertStructType(TypeBase *key, CanType type,
16981698
IGM.getSwiftModule()->getASTContext().getProtocol(
16991699
KnownProtocolKind::BitwiseCopyable);
17001700
if (bitwiseCopyableProtocol &&
1701-
IGM.getSwiftModule()->checkConformance(type, bitwiseCopyableProtocol)) {
1701+
ModuleDecl::checkConformance(type, bitwiseCopyableProtocol)) {
17021702
return BitwiseCopyableTypeInfo::create(IGM.OpaqueTy, structAccessible);
17031703
}
17041704
return &getResilientStructTypeInfo(copyable, structAccessible);

lib/IRGen/GenTuple.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ const TypeInfo *TypeConverter::convertTupleType(TupleType *tuple) {
524524
auto *bitwiseCopyableProtocol =
525525
IGM.getSwiftModule()->getASTContext().getProtocol(
526526
KnownProtocolKind::BitwiseCopyable);
527-
if (bitwiseCopyableProtocol && IGM.getSwiftModule()->checkConformance(
527+
if (bitwiseCopyableProtocol && ModuleDecl::checkConformance(
528528
tuple, bitwiseCopyableProtocol)) {
529529
return BitwiseCopyableTypeInfo::create(IGM.OpaqueTy, IsABIAccessible);
530530
}

lib/Refactoring/Async/AsyncHandlerDesc.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ using namespace swift;
1717
using namespace swift::refactoring::asyncrefactorings;
1818

1919
/// Whether the given type is (or conforms to) the stdlib Error type
20-
static bool isErrorType(Type Ty, ModuleDecl *MD) {
20+
static bool isErrorType(Type Ty) {
2121
if (!Ty)
2222
return false;
23-
return !MD->checkConformance(Ty, Ty->getASTContext().getErrorDecl())
23+
return !ModuleDecl::checkConformance(Ty, Ty->getASTContext().getErrorDecl())
2424
.isInvalid();
2525
}
2626

@@ -70,8 +70,7 @@ AsyncHandlerDesc AsyncHandlerDesc::get(const ValueDecl *Handler,
7070
HandlerDesc.Type = HandlerType::PARAMS;
7171
if (!HandlerParams.empty()) {
7272
auto LastParamTy = HandlerParams.back().getParameterType();
73-
HandlerDesc.HasError = isErrorType(LastParamTy->getOptionalObjectType(),
74-
Handler->getModuleContext());
73+
HandlerDesc.HasError = isErrorType(LastParamTy->getOptionalObjectType());
7574
}
7675
}
7776

lib/SIL/IR/AbstractionPattern.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ bool AbstractionPattern::conformsToKnownProtocol(
291291
= substTy->getASTContext().getProtocol(protocolKind);
292292

293293
auto definitelyConforms = [&](CanType t) -> bool {
294-
auto result = suppressible->getParentModule()
295-
->checkConformanceWithoutContext(t, suppressible,
296-
/*allowMissing=*/false);
294+
auto result =
295+
ModuleDecl::checkConformanceWithoutContext(t, suppressible,
296+
/*allowMissing=*/false);
297297
return result.has_value() && !result.value().isInvalid();
298298
};
299299

lib/SIL/Utils/DynamicCasts.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static CanType unwrapExistential(CanType e) {
9292
/// into an existential type by performing a static check
9393
/// of protocol conformances if it is possible.
9494
static DynamicCastFeasibility
95-
classifyDynamicCastToProtocol(ModuleDecl *M, CanType source, CanType target,
95+
classifyDynamicCastToProtocol(CanType source, CanType target,
9696
bool isWholeModuleOpts) {
9797
assert(target.isExistentialType() &&
9898
"target should be an existential type");
@@ -114,7 +114,7 @@ classifyDynamicCastToProtocol(ModuleDecl *M, CanType source, CanType target,
114114

115115
// If checkConformance() returns a valid conformance, then all conditional
116116
// requirements were satisfied.
117-
if (M->checkConformance(source, TargetProtocol))
117+
if (ModuleDecl::checkConformance(source, TargetProtocol))
118118
return DynamicCastFeasibility::WillSucceed;
119119

120120
auto *SourceNominalTy = source.getAnyNominal();
@@ -152,7 +152,7 @@ classifyDynamicCastToProtocol(ModuleDecl *M, CanType source, CanType target,
152152
// the checkConformance interface needs to be reformulated as a query, and
153153
// the implementation, including checkGenericArguments, needs to be taught to
154154
// recognize that types with archetypes may potentially succeed.
155-
if (auto conformance = M->lookupConformance(source, TargetProtocol)) {
155+
if (auto conformance = ModuleDecl::lookupConformance(source, TargetProtocol)) {
156156
assert(!conformance.getConditionalRequirements().empty());
157157
return DynamicCastFeasibility::MaySucceed;
158158
}
@@ -508,7 +508,7 @@ swift::classifyDynamicCast(ModuleDecl *M,
508508
DynamicCastFeasibility::MaySucceed);
509509
if (target.isExistentialType()) {
510510
result = atWorst(result, classifyDynamicCastToProtocol(
511-
M, source, target, isWholeModuleOpts));
511+
source, target, isWholeModuleOpts));
512512
}
513513
return result;
514514
}
@@ -522,7 +522,7 @@ swift::classifyDynamicCast(ModuleDecl *M,
522522
// Check conversions from non-protocol types into protocol types.
523523
if (!source.isExistentialType() &&
524524
target.isExistentialType())
525-
return classifyDynamicCastToProtocol(M, source, target,
525+
return classifyDynamicCastToProtocol(source, target,
526526
isWholeModuleOpts);
527527

528528
// Check conversions from protocol types to non-protocol types.
@@ -552,7 +552,7 @@ swift::classifyDynamicCast(ModuleDecl *M,
552552
// Hashable is not actually a legal existential type right now, but
553553
// the check doesn't care about that.
554554
if (auto hashable = getHashableExistentialType(M)) {
555-
return classifyDynamicCastToProtocol(M, source, hashable,
555+
return classifyDynamicCastToProtocol(source, hashable,
556556
isWholeModuleOpts);
557557
}
558558
}
@@ -589,7 +589,7 @@ swift::classifyDynamicCast(ModuleDecl *M,
589589

590590
if (targetMetatype.isAnyExistentialType() && target->isExistentialType()) {
591591
auto Feasibility =
592-
classifyDynamicCastToProtocol(M, source, target, isWholeModuleOpts);
592+
classifyDynamicCastToProtocol(source, target, isWholeModuleOpts);
593593
// Cast from existential metatype to existential metatype may still
594594
// succeed, even if we cannot prove anything statically.
595595
if (Feasibility != DynamicCastFeasibility::WillFail ||

lib/SIL/Utils/GenericSpecializationMangler.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ static SubstitutionMap
147147
getSubstitutionMapForPrespecialization(GenericSignature genericSig,
148148
GenericSignature specSig) {
149149
auto CalleeGenericSig = genericSig;
150-
auto SpecializedGenericSig = specSig;
151150
auto SpecializedGenericEnv = specSig.getGenericEnvironment();
152151

153152
auto CalleeInterfaceToSpecializedInterfaceMap = SubstitutionMap::get(

lib/SILGen/SILGenApply.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5936,7 +5936,7 @@ SILValue SILGenFunction::emitApplyWithRethrow(SILLocation loc, SILValue fn,
59365936
assert(outerErrorType == SILType::getExceptionType(getASTContext()));
59375937

59385938
ProtocolConformanceRef conformances[1] = {
5939-
getModule().getSwiftModule()->checkConformance(
5939+
ModuleDecl::checkConformance(
59405940
innerError->getType().getASTType(),
59415941
getASTContext().getErrorDecl())
59425942
};

lib/SILGen/SILGenExpr.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -6142,15 +6142,15 @@ static void diagnoseImplicitRawConversion(Type sourceTy, Type pointerTy,
61426142
if (SGF.getLoweredType(eltTy).isTrivial(SGF.F))
61436143
return;
61446144

6145-
auto *SM = SGF.getModule().getSwiftModule();
6146-
if (auto *bitwiseCopyableDecl = SM->getASTContext().getProtocol(
6145+
auto &ctx = SGF.getASTContext();
6146+
if (auto *bitwiseCopyableDecl = ctx.getProtocol(
61476147
KnownProtocolKind::BitwiseCopyable)) {
6148-
if (SM->checkConformance(eltTy, bitwiseCopyableDecl))
6148+
if (ModuleDecl::checkConformance(eltTy, bitwiseCopyableDecl))
61496149
return;
61506150
}
6151-
if (auto *fixedWidthIntegerDecl = SM->getASTContext().getProtocol(
6151+
if (auto *fixedWidthIntegerDecl = ctx.getProtocol(
61526152
KnownProtocolKind::FixedWidthInteger)) {
6153-
if (SM->checkConformance(eltTy, fixedWidthIntegerDecl))
6153+
if (ModuleDecl::checkConformance(eltTy, fixedWidthIntegerDecl))
61546154
return;
61556155
}
61566156

lib/SILGen/SILGenStmt.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,7 @@ void SILGenFunction::emitThrow(SILLocation loc, ManagedValue exnMV,
16331633
assert(destErrorType == SILType::getExceptionType(getASTContext()));
16341634

16351635
ProtocolConformanceRef conformances[1] = {
1636-
getModule().getSwiftModule()->checkConformance(
1636+
ModuleDecl::checkConformance(
16371637
exn->getType().getASTType(), getASTContext().getErrorDecl())
16381638
};
16391639

lib/SILOptimizer/Utils/CastOptimizer.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,6 @@ static bool optimizeStaticallyKnownProtocolConformance(
14551455
if (TargetType->isAnyExistentialType() &&
14561456
!SourceType->isAnyExistentialType()) {
14571457
auto &Ctx = Mod.getASTContext();
1458-
auto *SM = Mod.getSwiftModule();
14591458

14601459
auto *Proto = dyn_cast_or_null<ProtocolDecl>(TargetType->getAnyNominal());
14611460
if (!Proto)
@@ -1471,7 +1470,7 @@ static bool optimizeStaticallyKnownProtocolConformance(
14711470
// `foo(0)` but not for `foo("string")`. There are many cases where
14721471
// everything is completely static (`X<Int>() as? P`), in which case a
14731472
// valid conformance will be returned.
1474-
auto Conformance = SM->checkConformance(SourceType, Proto);
1473+
auto Conformance = ModuleDecl::checkConformance(SourceType, Proto);
14751474
if (Conformance.isInvalid())
14761475
return false;
14771476

lib/SILOptimizer/Utils/Existential.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ ConcreteExistentialInfo::ConcreteExistentialInfo(SILValue existential,
390390

391391
// We have the open_existential; we still need the conformance.
392392
auto ConformanceRef =
393-
M->getSwiftModule()->checkConformance(ConcreteTypeCandidate, Protocol);
393+
ModuleDecl::checkConformance(ConcreteTypeCandidate, Protocol);
394394
if (ConformanceRef.isInvalid())
395395
return;
396396

lib/Sema/AssociatedTypeInference.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1385,10 +1385,9 @@ static bool isExtensionUsableForInference(const ExtensionDecl *extension,
13851385
// in the first place. Only check conformances on the `Self` type,
13861386
// because those have to be explicitly declared on the type somewhere
13871387
// so won't be affected by whatever answer inference comes up with.
1388-
auto *module = conformanceDC->getParentModule();
13891388
auto checkConformance = [&](ProtocolDecl *proto) {
13901389
auto typeInContext = conformanceDC->mapTypeIntoContext(conformance->getType());
1391-
auto otherConf = module->checkConformance(typeInContext, proto);
1390+
auto otherConf = ModuleDecl::checkConformance(typeInContext, proto);
13921391
return !otherConf.isInvalid();
13931392
};
13941393

0 commit comments

Comments
 (0)