Skip to content

Commit ae133bc

Browse files
committed
GSB: Use explicit requirement list when diagnosing redundant requirements
1 parent 1bc4a4f commit ae133bc

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6973,44 +6973,31 @@ void GenericSignatureBuilder::checkConformanceConstraints(
69736973
}
69746974

69756975
void GenericSignatureBuilder::diagnoseRedundantRequirements() const {
6976-
SmallVector<ExplicitRequirement, 2> redundantRequirements;
6977-
6978-
for (auto pair : Impl->RedundantRequirements) {
6979-
auto *source = pair.first.getSource();
6976+
for (const auto &req : Impl->ExplicitRequirements) {
6977+
auto *source = req.getSource();
6978+
auto loc = source->getLoc();
69806979

69816980
// Don't diagnose anything without a source location.
6982-
if (source->getLoc().isInvalid())
6981+
if (loc.isInvalid())
69836982
continue;
69846983

6985-
// Don't diagnose redundant inferred requirements.
6984+
// Don't diagnose inferred requirements.
69866985
if (source->isInferredRequirement())
69876986
continue;
69886987

6988+
// Check if its actually redundant.
6989+
auto found = Impl->RedundantRequirements.find(req);
6990+
if (found == Impl->RedundantRequirements.end())
6991+
continue;
6992+
69896993
// Don't diagnose explicit requirements that are implied by
69906994
// inferred requirements.
6991-
if (llvm::all_of(pair.second,
6995+
if (llvm::all_of(found->second,
69926996
[&](const ExplicitRequirement &otherReq) {
69936997
return otherReq.getSource()->isInferredRequirement();
69946998
}))
69956999
continue;
69967000

6997-
redundantRequirements.push_back(pair.first);
6998-
}
6999-
7000-
auto &SM = Context.SourceMgr;
7001-
7002-
std::sort(redundantRequirements.begin(), redundantRequirements.end(),
7003-
[&](ExplicitRequirement lhs, ExplicitRequirement rhs) {
7004-
return compareSourceLocs(SM,
7005-
lhs.getSource()->getLoc(),
7006-
rhs.getSource()->getLoc());
7007-
});
7008-
7009-
for (const auto &req : redundantRequirements) {
7010-
auto *source = req.getSource();
7011-
auto loc = source->getLoc();
7012-
assert(loc.isValid());
7013-
70147001
auto subjectType = getSugaredDependentType(source->getStoredType(),
70157002
getGenericParams());
70167003

@@ -7039,7 +7026,7 @@ void GenericSignatureBuilder::diagnoseRedundantRequirements() const {
70397026
Context.Diags.diagnose(loc, diag::redundant_conformance_constraint,
70407027
subjectType, proto);
70417028

7042-
for (auto otherReq : Impl->RedundantRequirements[req]) {
7029+
for (auto otherReq : found->second) {
70437030
auto *otherSource = otherReq.getSource();
70447031
auto otherLoc = otherSource->getLoc();
70457032
if (otherLoc.isInvalid())

0 commit comments

Comments
 (0)