Skip to content

Commit 8082205

Browse files
committed
[NFC] Remove Unused Module Parameter to Conformance Lookup
It's been quite a long time since this unused parameter was introduced. The intent is to produce the module as a root for the search - that is, computing the set of conformances visible from that module, not the set of conformances inside of that module. Callers have since been providing all manner of module-scoped contexts to it. Let's just get rid of it. When we want to teach protocol conformance lookup to do this, we can revert this commit as a starting point and try again.
1 parent 0580357 commit 8082205

20 files changed

+20
-37
lines changed

include/swift/AST/Decl.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3227,16 +3227,13 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
32273227
/// Look for conformances of this nominal type to the given
32283228
/// protocol.
32293229
///
3230-
/// \param module The module from which we initiate the search.
3231-
/// FIXME: This is currently unused.
3232-
///
32333230
/// \param protocol The protocol whose conformance is requested.
32343231
/// \param conformances Will be populated with the set of protocol
32353232
/// conformances found for this protocol.
32363233
///
32373234
/// \returns true if any conformances were found.
32383235
bool lookupConformance(
3239-
ModuleDecl *module, ProtocolDecl *protocol,
3236+
ProtocolDecl *protocol,
32403237
SmallVectorImpl<ProtocolConformance *> &conformances) const;
32413238

32423239
/// Retrieve all of the protocols that this nominal type conforms to.

lib/AST/ConformanceLookupTable.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,6 @@ void ConformanceLookupTable::registerProtocolConformance(
950950
}
951951

952952
bool ConformanceLookupTable::lookupConformance(
953-
ModuleDecl *module,
954953
NominalTypeDecl *nominal,
955954
ProtocolDecl *protocol,
956955
SmallVectorImpl<ProtocolConformance *> &conformances) {

lib/AST/ConformanceLookupTable.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,7 @@ class ConformanceLookupTable {
445445
/// conformances found for this protocol and nominal type.
446446
///
447447
/// \returns true if any conformances were found.
448-
bool lookupConformance(ModuleDecl *module,
449-
NominalTypeDecl *nominal,
448+
bool lookupConformance(NominalTypeDecl *nominal,
450449
ProtocolDecl *protocol,
451450
SmallVectorImpl<ProtocolConformance *> &conformances);
452451

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3129,7 +3129,7 @@ bool ValueDecl::canInferObjCFromRequirement(ValueDecl *requirement) {
31293129
// If the nominal type doesn't conform to the protocol at all, we
31303130
// cannot infer @objc no matter what we do.
31313131
SmallVector<ProtocolConformance *, 1> conformances;
3132-
if (!nominal->lookupConformance(getModuleContext(), proto, conformances))
3132+
if (!nominal->lookupConformance(proto, conformances))
31333133
return false;
31343134

31353135
// If any of the conformances is attributed to the context in which

lib/AST/Module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ LookupConformanceInModuleRequest::evaluate(
11801180

11811181
// Find the (unspecialized) conformance.
11821182
SmallVector<ProtocolConformance *, 2> conformances;
1183-
if (!nominal->lookupConformance(mod, protocol, conformances)) {
1183+
if (!nominal->lookupConformance(protocol, conformances)) {
11841184
if (!protocol->isSpecificProtocol(KnownProtocolKind::Sendable))
11851185
return ProtocolConformanceRef::forInvalid();
11861186

lib/AST/ProtocolConformance.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,11 +1284,10 @@ void NominalTypeDecl::prepareConformanceTable() const {
12841284
}
12851285

12861286
bool NominalTypeDecl::lookupConformance(
1287-
ModuleDecl *module, ProtocolDecl *protocol,
1287+
ProtocolDecl *protocol,
12881288
SmallVectorImpl<ProtocolConformance *> &conformances) const {
12891289
prepareConformanceTable();
12901290
return ConformanceTable->lookupConformance(
1291-
module,
12921291
const_cast<NominalTypeDecl *>(this),
12931292
protocol,
12941293
conformances);

lib/AST/Type.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,9 +2638,7 @@ getForeignRepresentable(Type type, ForeignLanguage language,
26382638
if (auto objcBridgeable
26392639
= ctx.getProtocol(KnownProtocolKind::ObjectiveCBridgeable)) {
26402640
SmallVector<ProtocolConformance *, 1> conformances;
2641-
if (nominal->lookupConformance(dc->getParentModule(),
2642-
objcBridgeable,
2643-
conformances))
2641+
if (nominal->lookupConformance(objcBridgeable, conformances))
26442642
break;
26452643
}
26462644
}

lib/ClangImporter/ImportType.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,7 @@ namespace {
589589
auto nominal = element->getAnyNominal();
590590
auto simdscalar = Impl.SwiftContext.getProtocol(KnownProtocolKind::SIMDScalar);
591591
SmallVector<ProtocolConformance *, 2> conformances;
592-
if (simdscalar && nominal->lookupConformance(nominal->getParentModule(),
593-
simdscalar, conformances)) {
592+
if (simdscalar && nominal->lookupConformance(simdscalar, conformances)) {
594593
// Element type conforms to SIMDScalar. Get the SIMDn generic type
595594
// if it exists.
596595
SmallString<8> name("SIMD");
@@ -2807,8 +2806,7 @@ bool ClangImporter::Implementation::matchesHashableBound(Type type) {
28072806
auto hashable = SwiftContext.getProtocol(KnownProtocolKind::Hashable);
28082807
SmallVector<ProtocolConformance *, 2> conformances;
28092808
return hashable &&
2810-
nominal->lookupConformance(nominal->getParentModule(), hashable,
2811-
conformances);
2809+
nominal->lookupConformance(hashable, conformances);
28122810
}
28132811

28142812
return false;

lib/Frontend/ModuleInterfaceSupport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ class InheritedProtocolCollector {
502502
const NominalTypeDecl *nominal,
503503
ProtocolDecl *proto) {
504504
SmallVector<ProtocolConformance *, 4> conformances;
505-
nominal->lookupConformance(M, proto, conformances);
505+
nominal->lookupConformance(proto, conformances);
506506
return llvm::all_of(conformances,
507507
[M](const ProtocolConformance *conformance) -> bool {
508508
return M == conformance->getDeclContext()->getParentModule();

lib/IDE/CodeCompletion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4349,7 +4349,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
43494349
// Check for conformance to the literal protocol.
43504350
if (auto *NTD = T->getAnyNominal()) {
43514351
SmallVector<ProtocolConformance *, 2> conformances;
4352-
if (NTD->lookupConformance(CurrModule, P, conformances)) {
4352+
if (NTD->lookupConformance(P, conformances)) {
43534353
addTypeAnnotation(builder, T);
43544354
builder.setExpectedTypeRelation(typeRelation);
43554355
return;

lib/PrintAsObjC/DeclAndTypePrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,7 @@ class DeclAndTypePrinter::Implementation
13121312

13131313
// Determine whether this nominal type is _ObjectiveCBridgeable.
13141314
SmallVector<ProtocolConformance *, 2> conformances;
1315-
if (!nominal->lookupConformance(&owningPrinter.M, proto, conformances))
1315+
if (!nominal->lookupConformance(proto, conformances))
13161316
return nullptr;
13171317

13181318
// Dig out the Objective-C type.

lib/PrintAsObjC/ModuleContentsWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ class ModuleWriter {
449449

450450
SmallVector<ProtocolConformance *, 1> conformances;
451451
auto errorTypeProto = ctx.getProtocol(KnownProtocolKind::Error);
452-
if (ED->lookupConformance(&M, errorTypeProto, conformances)) {
452+
if (ED->lookupConformance(errorTypeProto, conformances)) {
453453
bool hasDomainCase = std::any_of(ED->getAllElements().begin(),
454454
ED->getAllElements().end(),
455455
[](const EnumElementDecl *elem) {

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7035,8 +7035,7 @@ allFromConditionalConformances(DeclContext *DC, Type baseTy,
70357035

70367036
if (auto *protocol = candidateDC->getSelfProtocolDecl()) {
70377037
SmallVector<ProtocolConformance *, 4> conformances;
7038-
if (!NTD->lookupConformance(DC->getParentModule(), protocol,
7039-
conformances))
7038+
if (!NTD->lookupConformance(protocol, conformances))
70407039
return false;
70417040

70427041
// This is opportunistic, there should be a way to narrow the

lib/Sema/ConstraintSystem.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5801,7 +5801,6 @@ bool TypeVarBindingProducer::requiresOptionalAdjustment(
58015801
if (auto *nominalBindingDecl = type->getAnyNominal()) {
58025802
SmallVector<ProtocolConformance *, 2> conformances;
58035803
conformsToExprByNilLiteral = nominalBindingDecl->lookupConformance(
5804-
CS.DC->getParentModule(),
58055804
CS.getASTContext().getProtocol(
58065805
KnownProtocolKind::ExpressibleByNilLiteral),
58075806
conformances);

lib/Sema/PreCheckExpr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,8 +2043,7 @@ Expr *PreCheckExpression::simplifyTypeConstructionWithLiteralArg(Expr *E) {
20432043
}
20442044

20452045
SmallVector<ProtocolConformance *, 2> conformances;
2046-
return castTy->getAnyNominal()->lookupConformance(DC->getParentModule(),
2047-
protocol, conformances)
2046+
return castTy->getAnyNominal()->lookupConformance(protocol, conformances)
20482047
? CoerceExpr::forLiteralInit(getASTContext(), argExpr,
20492048
call->getSourceRange(),
20502049
typeExpr->getTypeRepr())

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2910,7 +2910,7 @@ void AttributeChecker::visitImplementsAttr(ImplementsAttr *attr) {
29102910
// conforms to the specified protocol.
29112911
NominalTypeDecl *NTD = DC->getSelfNominalTypeDecl();
29122912
SmallVector<ProtocolConformance *, 2> conformances;
2913-
if (!NTD->lookupConformance(DC->getParentModule(), PD, conformances)) {
2913+
if (!NTD->lookupConformance(PD, conformances)) {
29142914
diagnose(attr->getLocation(),
29152915
diag::implements_attr_protocol_not_conformed_to,
29162916
NTD->getName(), PD->getName())

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6221,8 +6221,7 @@ swift::findWitnessedObjCRequirements(const ValueDecl *witness,
62216221
// Dig out the conformance.
62226222
if (!conformance.hasValue()) {
62236223
SmallVector<ProtocolConformance *, 2> conformances;
6224-
nominal->lookupConformance(dc->getParentModule(), proto,
6225-
conformances);
6224+
nominal->lookupConformance(proto, conformances);
62266225
if (conformances.size() == 1)
62276226
conformance = conformances.front();
62286227
else

lib/Sema/TypeCheckStmt.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ static void tryDiagnoseUnnecessaryCastOverOptionSet(ASTContext &Ctx,
229229
if (!optionSetType)
230230
return;
231231
SmallVector<ProtocolConformance *, 4> conformances;
232-
if (!(optionSetType &&
233-
NTD->lookupConformance(module, optionSetType, conformances)))
232+
if (!(optionSetType && NTD->lookupConformance(optionSetType, conformances)))
234233
return;
235234

236235
auto *CE = dyn_cast<CallExpr>(E);

lib/Sema/TypeCheckStorage.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ static void computeLoweredStoredProperties(NominalTypeDecl *decl) {
128128

129129
if (auto actorProto = ctx.getProtocol(KnownProtocolKind::Actor)) {
130130
SmallVector<ProtocolConformance *, 1> conformances;
131-
classDecl->lookupConformance(
132-
decl->getModuleContext(), actorProto, conformances);
131+
classDecl->lookupConformance(actorProto, conformances);
133132
for (auto conformance : conformances)
134133
TypeChecker::checkConformance(conformance->getRootNormalConformance());
135134
}
@@ -138,8 +137,7 @@ static void computeLoweredStoredProperties(NominalTypeDecl *decl) {
138137
if (classDecl->isDistributedActor()) {
139138
if (auto actorProto = ctx.getProtocol(KnownProtocolKind::DistributedActor)) {
140139
SmallVector<ProtocolConformance *, 1> conformances;
141-
classDecl->lookupConformance(
142-
decl->getModuleContext(), actorProto, conformances);
140+
classDecl->lookupConformance(actorProto, conformances);
143141
for (auto conformance : conformances)
144142
TypeChecker::checkConformance(conformance->getRootNormalConformance());
145143
}

lib/Serialization/Deserialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ ModuleFile::readConformanceChecked(llvm::BitstreamCursor &Cursor,
606606
module = getAssociatedModule();
607607

608608
SmallVector<ProtocolConformance *, 2> conformances;
609-
nominal->lookupConformance(module, proto, conformances);
609+
nominal->lookupConformance(proto, conformances);
610610
PrettyStackTraceModuleFile traceMsg(
611611
"If you're seeing a crash here, check that your SDK and dependencies "
612612
"are at least as new as the versions used to build", *this);

0 commit comments

Comments
 (0)