Skip to content

Commit dd75809

Browse files
committed
Sema: Remove TypeChecker::LookUpConformance in favor of LookUpConformanceInModule
Calling TypeChecker::conformsToProtocol() with SkipConditionalRequirements and an invalid SourceLoc() is now the same as calling ModuleDecl::lookupConformance(), so we can replace all usages of TypeChecker::LookUpConformance with LookUpConformanceInModule.
1 parent 0b8bce8 commit dd75809

File tree

6 files changed

+17
-52
lines changed

6 files changed

+17
-52
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ namespace {
414414

415415
return SubstitutionMap::get(sig,
416416
QueryTypeSubstitutionMap{subs},
417-
TypeChecker::LookUpConformance(cs.DC));
417+
LookUpConformanceInModule(cs.DC->getParentModule()));
418418
}
419419

420420
public:

lib/Sema/TypeCheckAttr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,15 +2687,15 @@ TypeEraserHasViableInitRequest::evaluate(Evaluator &evaluator,
26872687

26882688
return getSubstitution(type);
26892689
},
2690-
TypeChecker::LookUpConformance(dc));
2690+
LookUpConformanceInModule(dc->getParentModule()));
26912691

26922692
// Use invalid 'SourceLoc's to suppress diagnostics.
26932693
auto result = TypeChecker::checkGenericArguments(
26942694
protocol, SourceLoc(), SourceLoc(), typeEraser,
26952695
genericSignature->getGenericParams(),
26962696
genericSignature->getRequirements(),
26972697
QuerySubstitutionMap{subMap},
2698-
TypeChecker::LookUpConformance(dc));
2698+
LookUpConformanceInModule(dc->getParentModule()));
26992699

27002700
if (result != RequirementCheckResult::Success) {
27012701
unviable.push_back(

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3956,7 +3956,7 @@ void ConformanceChecker::ensureRequirementsAreSatisfied() {
39563956
{ proto->getSelfInterfaceType() },
39573957
proto->getRequirementSignature(),
39583958
QuerySubstitutionMap{substitutions},
3959-
TypeChecker::LookUpConformance(DC),
3959+
LookUpConformanceInModule(DC->getParentModule()),
39603960
&listener);
39613961

39623962
switch (result) {
@@ -4435,7 +4435,7 @@ TypeChecker::conformsToProtocol(Type T, ProtocolDecl *Proto, DeclContext *DC,
44354435
DC, ComplainLoc, noteLoc, T,
44364436
{lookupResult.getRequirement()->getSelfInterfaceType()}, *condReqs,
44374437
[](SubstitutableType *dependentType) { return Type(dependentType); },
4438-
LookUpConformance(DC));
4438+
LookUpConformanceInModule(M));
44394439
switch (conditionalCheckResult) {
44404440
case RequirementCheckResult::Success:
44414441
break;
@@ -4449,38 +4449,14 @@ TypeChecker::conformsToProtocol(Type T, ProtocolDecl *Proto, DeclContext *DC,
44494449
return lookupResult;
44504450
}
44514451

4452-
// Exposes TypeChecker functionality for querying protocol conformance.
4453-
//
4454-
// Invoking TypeChecker::conformsToProtocol from the ModuleDecl bypasses
4455-
// certain functionality that only applies to the diagnostic type checker:
4456-
//
4457-
// - ConformanceCheckFlags skips dependence checking.
4458-
//
4459-
// - Passing an invalid SourceLoc skips diagnostics.
4460-
//
4461-
// - Type::subst will be a nop, because 'source' type is already fully
4462-
// substituted in SIL. Consequently, TypeChecker::LookUpConformance, which
4463-
// is only valid during type checking, will never be invoked.
4464-
//
4465-
// - mapTypeIntoContext will be a nop.
4452+
/// Exposes TypeChecker functionality for querying protocol conformance.
4453+
/// Returns a valid ProtocolConformanceRef only if all conditional
4454+
/// requirements are successfully resolved.
44664455
ProtocolConformanceRef
44674456
ModuleDecl::conformsToProtocol(Type sourceTy, ProtocolDecl *targetProtocol) {
44684457
return TypeChecker::conformsToProtocol(sourceTy, targetProtocol, this, None);
44694458
}
44704459

4471-
ProtocolConformanceRef TypeChecker::LookUpConformance::
4472-
operator()(CanType dependentType, Type conformingReplacementType,
4473-
ProtocolDecl *conformedProtocol) const {
4474-
if (conformingReplacementType->isTypeParameter())
4475-
return ProtocolConformanceRef(conformedProtocol);
4476-
4477-
return TypeChecker::conformsToProtocol(
4478-
conformingReplacementType,
4479-
conformedProtocol,
4480-
dc,
4481-
ConformanceCheckFlags::SkipConditionalRequirements);
4482-
}
4483-
44844460
void TypeChecker::checkConformance(NormalProtocolConformance *conformance) {
44854461
MultiConformanceChecker checker(conformance->getProtocol()->getASTContext());
44864462
checker.addConformance(conformance);

lib/Sema/TypeCheckProtocolInference.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ bool AssociatedTypeInference::checkCurrentTypeWitnesses(
10971097
{ proto->getSelfInterfaceType() },
10981098
sanitizedRequirements,
10991099
QuerySubstitutionMap{substitutions},
1100-
TypeChecker::LookUpConformance(dc),
1100+
LookUpConformanceInModule(dc->getParentModule()),
11011101
nullptr, options);
11021102
switch (result) {
11031103
case RequirementCheckResult::Failure:

lib/Sema/TypeCheckType.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ static Type checkContextualRequirements(Type type,
675675
genericSig->getGenericParams(),
676676
genericSig->getRequirements(),
677677
QueryTypeSubstitutionMap{subMap},
678-
TypeChecker::LookUpConformance(dc));
678+
LookUpConformanceInModule(dc->getParentModule()));
679679

680680
switch (result) {
681681
case RequirementCheckResult::Failure:
@@ -906,14 +906,16 @@ Type TypeChecker::applyUnboundGenericArguments(
906906
// Check the generic arguments against the requirements of the declaration's
907907
// generic signature.
908908
auto dc = resolution.getDeclContext();
909+
auto *module = dc->getParentModule();
910+
909911
if (!skipRequirementsCheck &&
910912
resolution.getStage() > TypeResolutionStage::Structural) {
911913
auto result =
912914
checkGenericArguments(dc, loc, noteLoc, unboundType,
913915
genericSig->getGenericParams(),
914916
genericSig->getRequirements(),
915917
QueryTypeSubstitutionMap{subs},
916-
LookUpConformance(dc));
918+
LookUpConformanceInModule(module));
917919

918920
switch (result) {
919921
case RequirementCheckResult::Failure:
@@ -933,15 +935,15 @@ Type TypeChecker::applyUnboundGenericArguments(
933935

934936
// Apply the substitution map to the interface type of the declaration.
935937
resultType = resultType.subst(QueryTypeSubstitutionMap{subs},
936-
LookUpConformance(dc));
938+
LookUpConformanceInModule(module));
937939

938940
// Form a sugared typealias reference.
939941
Type parentType = unboundType->getParent();
940942
if (typealias && (!parentType || !parentType->isAnyExistentialType())) {
941943
auto genericSig = typealias->getGenericSignature();
942944
auto subMap = SubstitutionMap::get(genericSig,
943945
QueryTypeSubstitutionMap{subs},
944-
LookUpConformance(dc));
946+
LookUpConformanceInModule(module));
945947
resultType = TypeAliasType::get(typealias, parentType,
946948
subMap, resultType);
947949
}
@@ -2858,7 +2860,7 @@ Type TypeResolver::resolveSILBoxType(SILBoxTypeRepr *repr,
28582860
subMap = SubstitutionMap::get(
28592861
genericSig,
28602862
QueryTypeSubstitutionMap{genericArgMap},
2861-
TypeChecker::LookUpConformance(DC));
2863+
LookUpConformanceInModule(DC->getParentModule()));
28622864
}
28632865

28642866
auto layout = SILLayout::get(Context, genericSig, fields);
@@ -2949,7 +2951,7 @@ Type TypeResolver::resolveSILFunctionType(FunctionTypeRepr *repr,
29492951
subsMap.insert({params[i], resolved->getCanonicalType()});
29502952
}
29512953
return SubstitutionMap::get(sig, QueryTypeSubstitutionMap{subsMap},
2952-
TypeChecker::LookUpConformance(DC))
2954+
LookUpConformanceInModule(DC->getParentModule()))
29532955
.getCanonical();
29542956
};
29552957

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -954,19 +954,6 @@ ProtocolConformanceRef conformsToProtocol(Type T, ProtocolDecl *Proto,
954954
ConformanceCheckOptions options,
955955
SourceLoc ComplainLoc = SourceLoc());
956956

957-
/// Functor class suitable for use as a \c LookupConformanceFn to look up a
958-
/// conformance through a particular declaration context.
959-
class LookUpConformance {
960-
DeclContext *dc;
961-
962-
public:
963-
explicit LookUpConformance(DeclContext *dc) : dc(dc) {}
964-
965-
ProtocolConformanceRef operator()(CanType dependentType,
966-
Type conformingReplacementType,
967-
ProtocolDecl *conformedProtocol) const;
968-
};
969-
970957
/// Completely check the given conformance.
971958
void checkConformance(NormalProtocolConformance *conformance);
972959

0 commit comments

Comments
 (0)