Skip to content

Commit 742bd98

Browse files
committed
Sema: Remove ConformanceCheckOptions::SkipConditionalRequirements
All callers can trivially be refactored to use ModuleDecl::lookupConformance() instead. Since this was the last flag in ConformanceCheckOptions, we can remove that, too.
1 parent 86d557f commit 742bd98

28 files changed

+119
-176
lines changed

lib/Sema/CSApply.cpp

+17-20
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ Solution::computeSubstitutions(GenericSignature sig,
9090

9191
// FIXME: Retrieve the conformance from the solution itself.
9292
return TypeChecker::conformsToProtocol(replacement, protoType,
93-
getConstraintSystem().DC,
94-
None);
93+
getConstraintSystem().DC);
9594
};
9695

9796
return SubstitutionMap::get(sig,
@@ -447,7 +446,7 @@ namespace {
447446
// the protocol requirement with Self == the concrete type, and SILGen
448447
// (or later) can devirtualize as appropriate.
449448
auto conformance =
450-
TypeChecker::conformsToProtocol(baseTy, proto, cs.DC, None);
449+
TypeChecker::conformsToProtocol(baseTy, proto, cs.DC);
451450
if (conformance.isConcrete()) {
452451
if (auto witness = conformance.getConcrete()->getWitnessDecl(decl)) {
453452
bool isMemberOperator = witness->getDeclContext()->isTypeContext();
@@ -2082,8 +2081,7 @@ namespace {
20822081
auto bridgedToObjectiveCConformance
20832082
= TypeChecker::conformsToProtocol(valueType,
20842083
bridgedProto,
2085-
cs.DC,
2086-
None);
2084+
cs.DC);
20872085

20882086
FuncDecl *fn = nullptr;
20892087

@@ -2343,7 +2341,7 @@ namespace {
23432341
ProtocolDecl *protocol = TypeChecker::getProtocol(
23442342
ctx, expr->getLoc(), KnownProtocolKind::ExpressibleByStringLiteral);
23452343

2346-
if (!TypeChecker::conformsToProtocol(type, protocol, cs.DC, None)) {
2344+
if (!TypeChecker::conformsToProtocol(type, protocol, cs.DC)) {
23472345
// If the type does not conform to ExpressibleByStringLiteral, it should
23482346
// be ExpressibleByExtendedGraphemeClusterLiteral.
23492347
protocol = TypeChecker::getProtocol(
@@ -2352,7 +2350,7 @@ namespace {
23522350
isStringLiteral = false;
23532351
isGraphemeClusterLiteral = true;
23542352
}
2355-
if (!TypeChecker::conformsToProtocol(type, protocol, cs.DC, None)) {
2353+
if (!TypeChecker::conformsToProtocol(type, protocol, cs.DC)) {
23562354
// ... or it should be ExpressibleByUnicodeScalarLiteral.
23572355
protocol = TypeChecker::getProtocol(
23582356
cs.getASTContext(), expr->getLoc(),
@@ -2467,7 +2465,7 @@ namespace {
24672465
assert(proto && "Missing string interpolation protocol?");
24682466

24692467
auto conformance =
2470-
TypeChecker::conformsToProtocol(type, proto, cs.DC, None);
2468+
TypeChecker::conformsToProtocol(type, proto, cs.DC);
24712469
assert(conformance && "string interpolation type conforms to protocol");
24722470

24732471
DeclName constrName(ctx, DeclBaseName::createConstructor(), argLabels);
@@ -2573,7 +2571,7 @@ namespace {
25732571
auto proto = TypeChecker::getLiteralProtocol(cs.getASTContext(), expr);
25742572
assert(proto && "Missing object literal protocol?");
25752573
auto conformance =
2576-
TypeChecker::conformsToProtocol(conformingType, proto, cs.DC, None);
2574+
TypeChecker::conformsToProtocol(conformingType, proto, cs.DC);
25772575
assert(conformance && "object literal type conforms to protocol");
25782576

25792577
auto constrName = TypeChecker::getObjectLiteralConstructorName(ctx, expr);
@@ -3278,7 +3276,7 @@ namespace {
32783276
assert(arrayProto && "type-checked array literal w/o protocol?!");
32793277

32803278
auto conformance =
3281-
TypeChecker::conformsToProtocol(arrayTy, arrayProto, cs.DC, None);
3279+
TypeChecker::conformsToProtocol(arrayTy, arrayProto, cs.DC);
32823280
assert(conformance && "Type does not conform to protocol?");
32833281

32843282
DeclName name(ctx, DeclBaseName::createConstructor(),
@@ -3322,8 +3320,7 @@ namespace {
33223320
KnownProtocolKind::ExpressibleByDictionaryLiteral);
33233321

33243322
auto conformance =
3325-
TypeChecker::conformsToProtocol(dictionaryTy, dictionaryProto, cs.DC,
3326-
None);
3323+
TypeChecker::conformsToProtocol(dictionaryTy, dictionaryProto, cs.DC);
33273324
if (conformance.isInvalid())
33283325
return nullptr;
33293326

@@ -4062,7 +4059,7 @@ namespace {
40624059
// Special handle for literals conditional checked cast when they can
40634060
// be statically coerced to the cast type.
40644061
if (protocol && TypeChecker::conformsToProtocol(
4065-
toType, protocol, cs.DC, None)) {
4062+
toType, protocol, cs.DC)) {
40664063
ctx.Diags
40674064
.diagnose(expr->getLoc(),
40684065
diag::literal_conditional_downcast_to_coercion,
@@ -4939,7 +4936,7 @@ namespace {
49394936
// verified by the solver, we just need to get it again
49404937
// with all of the generic parameters resolved.
49414938
auto hashableConformance =
4942-
TypeChecker::conformsToProtocol(indexType, hashable, cs.DC, None);
4939+
TypeChecker::conformsToProtocol(indexType, hashable, cs.DC);
49434940
assert(hashableConformance);
49444941

49454942
conformances.push_back(hashableConformance);
@@ -5263,7 +5260,7 @@ collectExistentialConformances(Type fromType, Type toType,
52635260
SmallVector<ProtocolConformanceRef, 4> conformances;
52645261
for (auto proto : layout.getProtocols()) {
52655262
conformances.push_back(TypeChecker::containsProtocol(
5266-
fromType, proto->getDecl(), DC, None));
5263+
fromType, proto->getDecl(), DC));
52675264
}
52685265

52695266
return toType->getASTContext().AllocateCopy(conformances);
@@ -6430,7 +6427,7 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
64306427
auto hashable = ctx.getProtocol(KnownProtocolKind::Hashable);
64316428
auto conformance =
64326429
TypeChecker::conformsToProtocol(
6433-
cs.getType(expr), hashable, cs.DC, None);
6430+
cs.getType(expr), hashable, cs.DC);
64346431
assert(conformance && "must conform to Hashable");
64356432

64366433
return cs.cacheType(
@@ -6965,7 +6962,7 @@ Expr *ExprRewriter::convertLiteralInPlace(Expr *literal,
69656962
// initialize via the builtin protocol.
69666963
if (builtinProtocol) {
69676964
auto builtinConformance = TypeChecker::conformsToProtocol(
6968-
type, builtinProtocol, cs.DC, None);
6965+
type, builtinProtocol, cs.DC);
69696966
if (builtinConformance) {
69706967
// Find the witness that we'll use to initialize the type via a builtin
69716968
// literal.
@@ -6997,7 +6994,7 @@ Expr *ExprRewriter::convertLiteralInPlace(Expr *literal,
69976994

69986995
// This literal type must conform to the (non-builtin) protocol.
69996996
assert(protocol && "requirements should have stopped recursion");
7000-
auto conformance = TypeChecker::conformsToProtocol(type, protocol, cs.DC, None);
6997+
auto conformance = TypeChecker::conformsToProtocol(type, protocol, cs.DC);
70016998
assert(conformance && "must conform to literal protocol");
70026999

70037000
// Dig out the literal type and perform a builtin literal conversion to it.
@@ -7134,7 +7131,7 @@ ExprRewriter::buildDynamicCallable(ApplyExpr *apply, SelectedOverload selected,
71347131
auto dictLitProto =
71357132
ctx.getProtocol(KnownProtocolKind::ExpressibleByDictionaryLiteral);
71367133
auto conformance =
7137-
TypeChecker::conformsToProtocol(argumentType, dictLitProto, cs.DC, None);
7134+
TypeChecker::conformsToProtocol(argumentType, dictLitProto, cs.DC);
71387135
auto keyType = conformance.getTypeWitnessByName(argumentType, ctx.Id_Key);
71397136
auto valueType =
71407137
conformance.getTypeWitnessByName(argumentType, ctx.Id_Value);
@@ -8406,7 +8403,7 @@ ProtocolConformanceRef Solution::resolveConformance(
84068403
// itself rather than another conforms-to-protocol check.
84078404
Type substConformingType = simplifyType(conformingType);
84088405
return TypeChecker::conformsToProtocol(
8409-
substConformingType, proto, constraintSystem->DC, None);
8406+
substConformingType, proto, constraintSystem->DC);
84108407
}
84118408

84128409
return ProtocolConformanceRef::forInvalid();

lib/Sema/CSBindings.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,7 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) const {
766766

767767
do {
768768
// If the type conforms to this protocol, we're covered.
769-
if (TypeChecker::conformsToProtocol(
770-
testType, protocol, DC,
771-
ConformanceCheckFlags::SkipConditionalRequirements)) {
769+
if (DC->getParentModule()->lookupConformance(testType, protocol)) {
772770
coveredLiteralProtocols.insert(protocol);
773771
break;
774772
}

lib/Sema/CSDiagnostics.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -2451,7 +2451,7 @@ bool ContextualFailure::diagnoseThrowsTypeMismatch() const {
24512451
Ctx.getProtocol(KnownProtocolKind::ErrorCodeProtocol)) {
24522452
Type errorCodeType = getFromType();
24532453
auto conformance = TypeChecker::conformsToProtocol(
2454-
errorCodeType, errorCodeProtocol, getDC(), None);
2454+
errorCodeType, errorCodeProtocol, getDC());
24552455
if (conformance) {
24562456
Type errorType =
24572457
conformance
@@ -2781,8 +2781,7 @@ bool ContextualFailure::tryProtocolConformanceFixIt(
27812781
// Let's build a list of protocols that the context does not conform to.
27822782
SmallVector<std::string, 8> missingProtoTypeStrings;
27832783
for (auto protocol : layout.getProtocols()) {
2784-
if (!TypeChecker::conformsToProtocol(fromType, protocol->getDecl(), getDC(),
2785-
None)) {
2784+
if (!TypeChecker::conformsToProtocol(fromType, protocol->getDecl(), getDC())) {
27862785
missingProtoTypeStrings.push_back(protocol->getString());
27872786
}
27882787
}

lib/Sema/CSGen.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ namespace {
551551
if (otherArgTy && otherArgTy->getAnyNominal()) {
552552
if (otherArgTy->isEqual(paramTy) &&
553553
TypeChecker::conformsToProtocol(
554-
otherArgTy, literalProto, CS.DC, None)) {
554+
otherArgTy, literalProto, CS.DC)) {
555555
return true;
556556
}
557557
} else if (Type defaultType =

lib/Sema/CSRanking.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,7 @@ computeSelfTypeRelationship(DeclContext *dc, ValueDecl *decl1,
250250

251251
// If the model type does not conform to the protocol, the bases are
252252
// unrelated.
253-
auto conformance = TypeChecker::conformsToProtocol(
254-
modelTy, proto, dc,
255-
ConformanceCheckFlags::SkipConditionalRequirements);
253+
auto conformance = dc->getParentModule()->lookupConformance(modelTy, proto);
256254
if (conformance.isInvalid())
257255
return {SelfTypeRelationship::Unrelated, conformance};
258256

lib/Sema/CSSimplify.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -5179,18 +5179,16 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
51795179
switch (kind) {
51805180
case ConstraintKind::SelfObjectOfProtocol: {
51815181
auto conformance = TypeChecker::containsProtocol(
5182-
type, protocol, DC,
5183-
ConformanceCheckFlags::SkipConditionalRequirements);
5182+
type, protocol, DC, /*skipConditionalRequirements=*/true);
51845183
if (conformance) {
51855184
return recordConformance(conformance);
51865185
}
51875186
} break;
51885187
case ConstraintKind::ConformsTo:
51895188
case ConstraintKind::LiteralConformsTo: {
51905189
// Check whether this type conforms to the protocol.
5191-
auto conformance = TypeChecker::conformsToProtocol(
5192-
type, protocol, DC,
5193-
ConformanceCheckFlags::SkipConditionalRequirements);
5190+
auto conformance = DC->getParentModule()->lookupConformance(
5191+
type, protocol);
51945192
if (conformance) {
51955193
return recordConformance(conformance);
51965194
}
@@ -6869,9 +6867,8 @@ ConstraintSystem::simplifyValueWitnessConstraint(
68696867
// conformance already?
68706868
auto proto = requirement->getDeclContext()->getSelfProtocolDecl();
68716869
assert(proto && "Value witness constraint for a non-requirement");
6872-
auto conformance = TypeChecker::conformsToProtocol(
6873-
baseObjectType, proto, useDC,
6874-
ConformanceCheckFlags::SkipConditionalRequirements);
6870+
auto conformance = useDC->getParentModule()->lookupConformance(
6871+
baseObjectType, proto);
68756872
if (!conformance) {
68766873
// The conformance failed, so mark the member type as a "hole". We cannot
68776874
// do anything further here.

lib/Sema/CSSolver.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1726,10 +1726,10 @@ void ConstraintSystem::ArgumentInfoCollector::minimizeLiteralProtocols() {
17261726

17271727
auto first =
17281728
TypeChecker::conformsToProtocol(candidate.second, candidates[result].first,
1729-
CS.DC, None);
1729+
CS.DC);
17301730
auto second =
17311731
TypeChecker::conformsToProtocol(candidates[result].second, candidate.first,
1732-
CS.DC, None);
1732+
CS.DC);
17331733
if (first.isInvalid() == second.isInvalid())
17341734
return;
17351735

@@ -1955,7 +1955,7 @@ void ConstraintSystem::sortDesignatedTypes(
19551955
++nextType;
19561956
break;
19571957
} else if (auto *protoDecl = dyn_cast<ProtocolDecl>(nominalTypes[i])) {
1958-
if (TypeChecker::conformsToProtocol(argType, protoDecl, DC, None)) {
1958+
if (TypeChecker::conformsToProtocol(argType, protoDecl, DC)) {
19591959
std::swap(nominalTypes[nextType], nominalTypes[i]);
19601960
++nextType;
19611961
break;

lib/Sema/CodeSynthesis.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1130,10 +1130,8 @@ ResolveImplicitMemberRequest::evaluate(Evaluator &evaluator,
11301130
return false;
11311131

11321132
auto targetType = target->getDeclaredInterfaceType();
1133-
auto ref = TypeChecker::conformsToProtocol(
1134-
targetType, protocol, target,
1135-
ConformanceCheckFlags::SkipConditionalRequirements);
1136-
1133+
auto ref = target->getParentModule()->lookupConformance(
1134+
targetType, protocol);
11371135
if (ref.isInvalid()) {
11381136
return false;
11391137
}

lib/Sema/ConstraintSystem.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3595,7 +3595,7 @@ bool constraints::conformsToKnownProtocol(ConstraintSystem &cs, Type type,
35953595
KnownProtocolKind protocol) {
35963596
if (auto *proto =
35973597
TypeChecker::getProtocol(cs.getASTContext(), SourceLoc(), protocol))
3598-
return (bool)TypeChecker::conformsToProtocol(type, proto, cs.DC, None);
3598+
return (bool)TypeChecker::conformsToProtocol(type, proto, cs.DC);
35993599
return false;
36003600
}
36013601

@@ -3609,7 +3609,7 @@ Type constraints::isRawRepresentable(ConstraintSystem &cs, Type type) {
36093609
if (!rawReprType)
36103610
return Type();
36113611

3612-
auto conformance = TypeChecker::conformsToProtocol(type, rawReprType, DC, None);
3612+
auto conformance = TypeChecker::conformsToProtocol(type, rawReprType, DC);
36133613
if (conformance.isInvalid())
36143614
return Type();
36153615

lib/Sema/DerivedConformanceAdditiveArithmetic.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ bool DerivedConformance::canDeriveAdditiveArithmetic(NominalTypeDecl *nominal,
7676
if (v->getInterfaceType()->hasError())
7777
return false;
7878
auto varType = DC->mapTypeIntoContext(v->getValueInterfaceType());
79-
return (bool)TypeChecker::conformsToProtocol(varType, proto, DC, None);
79+
return (bool)TypeChecker::conformsToProtocol(varType, proto, DC);
8080
});
8181
}
8282

lib/Sema/DerivedConformanceCodable.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static CodableConformanceType typeConformsToCodable(DeclContext *context,
8888
false, proto);
8989
}
9090

91-
auto conf = TypeChecker::conformsToProtocol(target, proto, context, None);
91+
auto conf = TypeChecker::conformsToProtocol(target, proto, context);
9292
return conf.isInvalid() ? DoesNotConform : Conforms;
9393
}
9494

@@ -264,7 +264,7 @@ static CodingKeysValidity hasValidCodingKeysEnum(DerivedConformance &derived) {
264264
// Ensure that the type we found conforms to the CodingKey protocol.
265265
auto *codingKeyProto = C.getProtocol(KnownProtocolKind::CodingKey);
266266
if (!TypeChecker::conformsToProtocol(codingKeysType, codingKeyProto,
267-
derived.getConformanceContext(), None)) {
267+
derived.getConformanceContext())) {
268268
// If CodingKeys is a typealias which doesn't point to a valid nominal type,
269269
// codingKeysTypeDecl will be nullptr here. In that case, we need to warn on
270270
// the location of the usage, since there isn't an underlying type to
@@ -847,10 +847,8 @@ deriveBodyDecodable_init(AbstractFunctionDecl *initDecl, void *) {
847847
});
848848
auto *encodableProto = C.getProtocol(KnownProtocolKind::Encodable);
849849
bool conformsToEncodable =
850-
TypeChecker::conformsToProtocol(
851-
targetDecl->getDeclaredInterfaceType(), encodableProto,
852-
conformanceDC,
853-
ConformanceCheckFlags::SkipConditionalRequirements) != nullptr;
850+
conformanceDC->getParentModule()->lookupConformance(
851+
targetDecl->getDeclaredInterfaceType(), encodableProto) != nullptr;
854852

855853
// Strategy to use for CodingKeys enum diagnostic part - this is to
856854
// make the behaviour more explicit:
@@ -1091,8 +1089,7 @@ static bool canSynthesize(DerivedConformance &derived, ValueDecl *requirement) {
10911089
if (auto *superclassDecl = classDecl->getSuperclassDecl()) {
10921090
DeclName memberName;
10931091
auto superType = superclassDecl->getDeclaredInterfaceType();
1094-
if (TypeChecker::conformsToProtocol(superType, proto, superclassDecl,
1095-
None)) {
1092+
if (TypeChecker::conformsToProtocol(superType, proto, superclassDecl)) {
10961093
// super.init(from:) must be accessible.
10971094
memberName = cast<ConstructorDecl>(requirement)->getName();
10981095
} else {

0 commit comments

Comments
 (0)