Skip to content

Commit fc3244b

Browse files
committed
Sema: Remove some redundant conformance lookup callbacks
Now we have LookUpConformanceInModule and LookUpConformanceInSubstitutionMap.
1 parent 7c6877c commit fc3244b

File tree

4 files changed

+10
-39
lines changed

4 files changed

+10
-39
lines changed

lib/AST/GenericEnvironment.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -332,15 +332,10 @@ Type GenericEnvironment::getSugaredType(Type type) const {
332332

333333
ArrayRef<Substitution>
334334
GenericEnvironment::getForwardingSubstitutions() const {
335-
auto lookupConformanceFn =
336-
[&](CanType original, Type replacement, ProtocolType *protoType)
337-
-> Optional<ProtocolConformanceRef> {
338-
return ProtocolConformanceRef(protoType->getDecl());
339-
};
340-
341335
SmallVector<Substitution, 4> result;
342336
getGenericSignature()->getSubstitutions(QueryInterfaceTypeSubstitutions(this),
343-
lookupConformanceFn, result);
337+
MakeAbstractConformanceForGenericType(),
338+
result);
344339
return getGenericSignature()->getASTContext().AllocateCopy(result);
345340
}
346341

lib/AST/GenericSignature.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -409,13 +409,9 @@ getSubstitutions(TypeSubstitutionFn subs,
409409
void GenericSignature::
410410
getSubstitutions(const SubstitutionMap &subMap,
411411
SmallVectorImpl<Substitution> &result) const {
412-
auto lookupConformanceFn =
413-
[&](CanType original, Type replacement, ProtocolType *protoType)
414-
-> Optional<ProtocolConformanceRef> {
415-
return subMap.lookupConformance(original, protoType->getDecl());
416-
};
417-
418-
getSubstitutions(subMap.getMap(), lookupConformanceFn, result);
412+
getSubstitutions(subMap.getMap(),
413+
LookUpConformanceInSubstitutionMap(subMap),
414+
result);
419415
}
420416

421417
bool GenericSignature::requiresClass(Type type, ModuleDecl &mod) {

lib/AST/Module.cpp

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -634,31 +634,9 @@ TypeBase::gatherAllSubstitutions(ModuleDecl *module,
634634
}
635635
}
636636

637-
auto lookupConformanceFn =
638-
[&](CanType original, Type replacement, ProtocolType *protoType)
639-
-> Optional<ProtocolConformanceRef> {
640-
auto *proto = protoType->getDecl();
641-
642-
// If the type is a type variable or is dependent, just fill in empty
643-
// conformances.
644-
if (replacement->isTypeVariableOrMember() ||
645-
replacement->isTypeParameter())
646-
return ProtocolConformanceRef(proto);
647-
648-
// Otherwise, try to find the conformance.
649-
auto conforms = module->lookupConformance(replacement, proto, resolver);
650-
if (conforms)
651-
return *conforms;
652-
653-
// FIXME: Should we ever end up here?
654-
// We should return None and let getSubstitutions handle the error
655-
// if we do.
656-
return ProtocolConformanceRef(proto);
657-
};
658-
659637
SmallVector<Substitution, 4> result;
660638
genericSig->getSubstitutions(substitutions,
661-
lookupConformanceFn,
639+
LookUpConformanceInModule(module),
662640
result);
663641

664642
// Before recording substitutions, make sure we didn't end up doing it
@@ -762,9 +740,8 @@ ModuleDecl::lookupConformance(Type type, ProtocolDecl *protocol,
762740
}
763741

764742
// Type variables have trivial conformances.
765-
if (type->isTypeVariableOrMember()) {
743+
if (type->isTypeVariableOrMember())
766744
return ProtocolConformanceRef(protocol);
767-
}
768745

769746
// UnresolvedType is a placeholder for an unknown type used when generating
770747
// diagnostics. We consider it to conform to all protocols, since the

lib/AST/Type.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,6 +2949,9 @@ Optional<ProtocolConformanceRef>
29492949
LookUpConformanceInModule::operator()(CanType dependentType,
29502950
Type conformingReplacementType,
29512951
ProtocolType *conformedProtocol) const {
2952+
if (conformingReplacementType->isTypeParameter())
2953+
return ProtocolConformanceRef(conformedProtocol->getDecl());
2954+
29522955
return M->lookupConformance(conformingReplacementType,
29532956
conformedProtocol->getDecl(),
29542957
conformingReplacementType->getASTContext().getLazyResolver());

0 commit comments

Comments
 (0)