Skip to content

Commit e8dc19a

Browse files
committed
Sema: Stop calling getAllConformances() on protocols
1 parent b254dc2 commit e8dc19a

File tree

5 files changed

+26
-26
lines changed

5 files changed

+26
-26
lines changed

lib/Sema/CSSimplify.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -8093,16 +8093,12 @@ allFromConditionalConformances(DeclContext *DC, Type baseTy,
80938093
}
80948094

80958095
if (auto *protocol = candidateDC->getSelfProtocolDecl()) {
8096-
SmallVector<ProtocolConformance *, 4> conformances;
8097-
if (!NTD->lookupConformance(protocol, conformances))
8096+
auto conformance = DC->getParentModule()->lookupConformance(
8097+
baseTy, protocol);
8098+
if (!conformance.isConcrete())
80988099
return false;
80998100

8100-
// This is opportunistic, there should be a way to narrow the
8101-
// list down to a particular declaration member comes from.
8102-
return llvm::any_of(
8103-
conformances, [](const ProtocolConformance *conformance) {
8104-
return !conformance->getConditionalRequirements().empty();
8105-
});
8101+
return !conformance.getConcrete()->getConditionalRequirements().empty();
81068102
}
81078103

81088104
return false;

lib/Sema/ConstraintSystem.cpp

+4-9
Original file line numberDiff line numberDiff line change
@@ -6947,15 +6947,10 @@ bool TypeVarBindingProducer::requiresOptionalAdjustment(
69476947
// produce an optional of that type as a potential binding. We
69486948
// overwrite the binding in place because the non-optional type
69496949
// will fail to type-check against the nil-literal conformance.
6950-
bool conformsToExprByNilLiteral = false;
6951-
if (auto *nominalBindingDecl = type->getAnyNominal()) {
6952-
SmallVector<ProtocolConformance *, 2> conformances;
6953-
conformsToExprByNilLiteral = nominalBindingDecl->lookupConformance(
6954-
CS.getASTContext().getProtocol(
6955-
KnownProtocolKind::ExpressibleByNilLiteral),
6956-
conformances);
6957-
}
6958-
return !conformsToExprByNilLiteral;
6950+
auto *proto = CS.getASTContext().getProtocol(
6951+
KnownProtocolKind::ExpressibleByNilLiteral);
6952+
6953+
return !proto->getParentModule()->lookupConformance(type, proto);
69596954
} else if (binding.isDefaultableBinding() && binding.BindingType->isAny()) {
69606955
return true;
69616956
}

lib/Sema/TypeCheckAttr.cpp

+15-7
Original file line numberDiff line numberDiff line change
@@ -3306,14 +3306,22 @@ void AttributeChecker::visitImplementsAttr(ImplementsAttr *attr) {
33063306
// Check that the decl we're decorating is a member of a type that actually
33073307
// conforms to the specified protocol.
33083308
NominalTypeDecl *NTD = DC->getSelfNominalTypeDecl();
3309-
SmallVector<ProtocolConformance *, 2> conformances;
3310-
if (!NTD->lookupConformance(PD, conformances)) {
3311-
diagnose(attr->getLocation(),
3312-
diag::implements_attr_protocol_not_conformed_to,
3313-
NTD->getName(), PD->getName())
3314-
.highlight(attr->getProtocolTypeRepr()->getSourceRange());
3309+
if (auto *OtherPD = dyn_cast<ProtocolDecl>(NTD)) {
3310+
if (!OtherPD->inheritsFrom(PD)) {
3311+
diagnose(attr->getLocation(),
3312+
diag::implements_attr_protocol_not_conformed_to,
3313+
NTD->getName(), PD->getName())
3314+
.highlight(attr->getProtocolTypeRepr()->getSourceRange());
3315+
}
3316+
} else {
3317+
SmallVector<ProtocolConformance *, 2> conformances;
3318+
if (!NTD->lookupConformance(PD, conformances)) {
3319+
diagnose(attr->getLocation(),
3320+
diag::implements_attr_protocol_not_conformed_to,
3321+
NTD->getName(), PD->getName())
3322+
.highlight(attr->getProtocolTypeRepr()->getSourceRange());
3323+
}
33153324
}
3316-
33173325
} else {
33183326
diagnose(attr->getLocation(), diag::implements_attr_non_protocol_type)
33193327
.highlight(attr->getProtocolTypeRepr()->getSourceRange());

lib/Sema/TypeCheckProtocol.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -6762,7 +6762,9 @@ swift::findWitnessedObjCRequirements(const ValueDecl *witness,
67626762

67636763
auto dc = witness->getDeclContext();
67646764
auto nominal = dc->getSelfNominalTypeDecl();
6765+
67656766
if (!nominal) return result;
6767+
if (isa<ProtocolDecl>(nominal)) return result;
67666768

67676769
DeclName name = witness->getName();
67686770
Optional<AccessorKind> accessorKind;

lib/Sema/TypeCheckStmt.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ static void tryDiagnoseUnnecessaryCastOverOptionSet(ASTContext &Ctx,
229229
auto optionSetType = dyn_cast_or_null<ProtocolDecl>(Ctx.getOptionSetDecl());
230230
if (!optionSetType)
231231
return;
232-
SmallVector<ProtocolConformance *, 4> conformances;
233-
if (!(optionSetType && NTD->lookupConformance(optionSetType, conformances)))
232+
if (!module->lookupConformance(ResultType, optionSetType))
234233
return;
235234

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

0 commit comments

Comments
 (0)