Skip to content

Commit 42dc4ca

Browse files
committed
[GSB] Remove getColonLoc() and getEqualLoc() in favour of getSeparatorLoc()
Most callers aren't concerned about the difference between the two (and those that are are already exercising the appropriate assertions with e.g the use of `getFirstType()`).
1 parent 819a13e commit 42dc4ca

File tree

4 files changed

+13
-39
lines changed

4 files changed

+13
-39
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,14 +1149,6 @@ class RequirementRepr {
11491149
return SecondLayout;
11501150
}
11511151

1152-
/// \brief Retrieve the location of the ':' in an explicitly-written
1153-
/// conformance requirement.
1154-
SourceLoc getColonLoc() const {
1155-
assert(getKind() == RequirementReprKind::TypeConstraint ||
1156-
getKind() == RequirementReprKind::LayoutConstraint);
1157-
return SeparatorLoc;
1158-
}
1159-
11601152
/// \brief Retrieve the first type of a same-type requirement.
11611153
Type getFirstType() const {
11621154
assert(getKind() == RequirementReprKind::SameType);
@@ -1199,10 +1191,9 @@ class RequirementRepr {
11991191
return SecondType;
12001192
}
12011193

1202-
/// \brief Retrieve the location of the '==' in an explicitly-written
1203-
/// same-type requirement.
1204-
SourceLoc getEqualLoc() const {
1205-
assert(getKind() == RequirementReprKind::SameType);
1194+
/// \brief Retrieve the location of the ':' or '==' in an explicitly-written
1195+
/// conformance or same-type requirement respectively.
1196+
SourceLoc getSeparatorLoc() const {
12061197
return SeparatorLoc;
12071198
}
12081199

lib/AST/Decl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ GenericParamList::clone(DeclContext *dc) const {
614614
auto second = reqt.getConstraintLoc();
615615
reqt = RequirementRepr::getTypeConstraint(
616616
first.clone(ctx),
617-
reqt.getColonLoc(),
617+
reqt.getSeparatorLoc(),
618618
second.clone(ctx));
619619
break;
620620
}
@@ -623,7 +623,7 @@ GenericParamList::clone(DeclContext *dc) const {
623623
auto second = reqt.getSecondTypeLoc();
624624
reqt = RequirementRepr::getSameType(
625625
first.clone(ctx),
626-
reqt.getEqualLoc(),
626+
reqt.getSeparatorLoc(),
627627
second.clone(ctx));
628628
break;
629629
}
@@ -632,7 +632,7 @@ GenericParamList::clone(DeclContext *dc) const {
632632
auto layout = reqt.getLayoutConstraintLoc();
633633
reqt = RequirementRepr::getLayoutConstraint(
634634
first.clone(ctx),
635-
reqt.getColonLoc(),
635+
reqt.getSeparatorLoc(),
636636
layout);
637637
break;
638638
}

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,16 +1451,9 @@ SourceLoc RequirementSource::getLoc() const {
14511451
if (auto typeRepr = getTypeRepr())
14521452
return typeRepr->getStartLoc();
14531453

1454-
if (auto requirementRepr = getRequirementRepr()) {
1455-
switch (requirementRepr->getKind()) {
1456-
case RequirementReprKind::LayoutConstraint:
1457-
case RequirementReprKind::TypeConstraint:
1458-
return requirementRepr->getColonLoc();
1454+
if (auto requirementRepr = getRequirementRepr())
1455+
return requirementRepr->getSeparatorLoc();
14591456

1460-
case RequirementReprKind::SameType:
1461-
return requirementRepr->getEqualLoc();
1462-
}
1463-
}
14641457
if (parent)
14651458
return parent->getLoc();
14661459

@@ -1678,24 +1671,14 @@ const RequirementSource *FloatingRequirementSource::getSource(
16781671
}
16791672

16801673
SourceLoc FloatingRequirementSource::getLoc() const {
1681-
auto getSeparatorLoc = [](const RequirementRepr *req) -> SourceLoc {
1682-
switch (req->getKind()) {
1683-
case RequirementReprKind::LayoutConstraint:
1684-
case RequirementReprKind::TypeConstraint:
1685-
return req->getColonLoc();
1686-
case RequirementReprKind::SameType:
1687-
return req->getEqualLoc();
1688-
}
1689-
};
1690-
16911674
// For an explicit abstract protocol source, we can get a more accurate source
16921675
// location from the written protocol requirement.
16931676
if (kind == Kind::AbstractProtocol && isExplicit()) {
16941677
auto written = protocolReq.written;
16951678
if (auto typeRepr = written.dyn_cast<const TypeRepr *>())
16961679
return typeRepr->getLoc();
16971680
if (auto requirementRepr = written.dyn_cast<const RequirementRepr *>())
1698-
return getSeparatorLoc(requirementRepr);
1681+
return requirementRepr->getSeparatorLoc();
16991682
}
17001683

17011684
if (auto source = storage.dyn_cast<const RequirementSource *>())
@@ -1705,7 +1688,7 @@ SourceLoc FloatingRequirementSource::getLoc() const {
17051688
return typeRepr->getLoc();
17061689

17071690
if (auto requirementRepr = storage.dyn_cast<const RequirementRepr *>())
1708-
return getSeparatorLoc(requirementRepr);
1691+
return requirementRepr->getSeparatorLoc();
17091692

17101693
return SourceLoc();
17111694
}
@@ -5357,7 +5340,7 @@ GenericSignatureBuilder::addRequirement(const Requirement &req,
53575340
!req.getSecondType()->hasTypeParameter() &&
53585341
!req.getFirstType()->hasError() &&
53595342
!req.getSecondType()->hasError()) {
5360-
Diags.diagnose(reqRepr->getEqualLoc(),
5343+
Diags.diagnose(reqRepr->getSeparatorLoc(),
53615344
diag::requires_no_same_type_archetype,
53625345
req.getFirstType(), req.getSecondType())
53635346
.highlight(reqRepr->getFirstTypeLoc().getSourceRange())

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,11 +2674,11 @@ void ConformanceChecker::checkNonFinalClassWitness(ValueDecl *requirement,
26742674
emitDeclaredHereIfNeeded(diags, diagLoc, witness);
26752675

26762676
if (auto requirementRepr = *constraint) {
2677-
diags.diagnose(requirementRepr->getEqualLoc(),
2677+
diags.diagnose(requirementRepr->getSeparatorLoc(),
26782678
diag::witness_self_weaken_same_type,
26792679
requirementRepr->getFirstType(),
26802680
requirementRepr->getSecondType())
2681-
.fixItReplace(requirementRepr->getEqualLoc(), ":");
2681+
.fixItReplace(requirementRepr->getSeparatorLoc(), ":");
26822682
}
26832683
}
26842684
}

0 commit comments

Comments
 (0)