Skip to content

Commit b9427b0

Browse files
committed
[NFC] Strip RequirementRepr of its TypeLocs
Now that the previous commits have removed the data dependencies on TypeLoc, remove the TypeLoc and replace it with a TypeRepr. This makes RequirementRepr a purely syntactic object once again.
1 parent d197f9d commit b9427b0

File tree

2 files changed

+19
-79
lines changed

2 files changed

+19
-79
lines changed

include/swift/AST/Decl.h

Lines changed: 10 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,12 +1030,12 @@ class RequirementRepr {
10301030
SourceLoc SeparatorLoc;
10311031
RequirementReprKind Kind : 2;
10321032
bool Invalid : 1;
1033-
TypeLoc FirstType;
1033+
TypeRepr *FirstType;
10341034

10351035
/// The second element represents the right-hand side of the constraint.
10361036
/// It can be e.g. a type or a layout constraint.
10371037
union {
1038-
TypeLoc SecondType;
1038+
TypeRepr *SecondType;
10391039
LayoutConstraintLoc SecondLayout;
10401040
};
10411041

@@ -1064,9 +1064,9 @@ class RequirementRepr {
10641064
/// this requirement was implied.
10651065
/// \param Constraint The protocol or protocol composition to which the
10661066
/// subject must conform, or superclass from which the subject must inherit.
1067-
static RequirementRepr getTypeConstraint(TypeLoc Subject,
1067+
static RequirementRepr getTypeConstraint(TypeRepr *Subject,
10681068
SourceLoc ColonLoc,
1069-
TypeLoc Constraint) {
1069+
TypeRepr *Constraint) {
10701070
return { ColonLoc, RequirementReprKind::TypeConstraint, Subject, Constraint };
10711071
}
10721072

@@ -1076,9 +1076,9 @@ class RequirementRepr {
10761076
/// \param EqualLoc The location of the '==' in the same-type constraint, or
10771077
/// an invalid location if this requirement was implied.
10781078
/// \param SecondType The second type.
1079-
static RequirementRepr getSameType(TypeLoc FirstType,
1079+
static RequirementRepr getSameType(TypeRepr *FirstType,
10801080
SourceLoc EqualLoc,
1081-
TypeLoc SecondType) {
1081+
TypeRepr *SecondType) {
10821082
return { EqualLoc, RequirementReprKind::SameType, FirstType, SecondType };
10831083
}
10841084

@@ -1090,7 +1090,7 @@ class RequirementRepr {
10901090
/// this requirement was implied.
10911091
/// \param Layout The layout requirement to which the
10921092
/// subject must conform.
1093-
static RequirementRepr getLayoutConstraint(TypeLoc Subject,
1093+
static RequirementRepr getLayoutConstraint(TypeRepr *Subject,
10941094
SourceLoc ColonLoc,
10951095
LayoutConstraintLoc Layout) {
10961096
return {ColonLoc, RequirementReprKind::LayoutConstraint, Subject,
@@ -1108,48 +1108,15 @@ class RequirementRepr {
11081108

11091109
/// For a type-bound requirement, return the subject of the
11101110
/// conformance relationship.
1111-
Type getSubject() const {
1112-
assert(getKind() == RequirementReprKind::TypeConstraint ||
1113-
getKind() == RequirementReprKind::LayoutConstraint);
1114-
return FirstType.getType();
1115-
}
1116-
11171111
TypeRepr *getSubjectRepr() const {
1118-
assert(getKind() == RequirementReprKind::TypeConstraint ||
1119-
getKind() == RequirementReprKind::LayoutConstraint);
1120-
return FirstType.getTypeRepr();
1121-
}
1122-
1123-
TypeLoc &getSubjectLoc() {
1124-
assert(getKind() == RequirementReprKind::TypeConstraint ||
1125-
getKind() == RequirementReprKind::LayoutConstraint);
1126-
return FirstType;
1127-
}
1128-
1129-
const TypeLoc &getSubjectLoc() const {
11301112
assert(getKind() == RequirementReprKind::TypeConstraint ||
11311113
getKind() == RequirementReprKind::LayoutConstraint);
11321114
return FirstType;
11331115
}
11341116

11351117
/// For a type-bound requirement, return the protocol or to which
11361118
/// the subject conforms or superclass it inherits.
1137-
Type getConstraint() const {
1138-
assert(getKind() == RequirementReprKind::TypeConstraint);
1139-
return SecondType.getType();
1140-
}
1141-
11421119
TypeRepr *getConstraintRepr() const {
1143-
assert(getKind() == RequirementReprKind::TypeConstraint);
1144-
return SecondType.getTypeRepr();
1145-
}
1146-
1147-
TypeLoc &getConstraintLoc() {
1148-
assert(getKind() == RequirementReprKind::TypeConstraint);
1149-
return SecondType;
1150-
}
1151-
1152-
const TypeLoc &getConstraintLoc() const {
11531120
assert(getKind() == RequirementReprKind::TypeConstraint);
11541121
return SecondType;
11551122
}
@@ -1170,43 +1137,13 @@ class RequirementRepr {
11701137
}
11711138

11721139
/// Retrieve the first type of a same-type requirement.
1173-
Type getFirstType() const {
1174-
assert(getKind() == RequirementReprKind::SameType);
1175-
return FirstType.getType();
1176-
}
1177-
11781140
TypeRepr *getFirstTypeRepr() const {
1179-
assert(getKind() == RequirementReprKind::SameType);
1180-
return FirstType.getTypeRepr();
1181-
}
1182-
1183-
TypeLoc &getFirstTypeLoc() {
1184-
assert(getKind() == RequirementReprKind::SameType);
1185-
return FirstType;
1186-
}
1187-
1188-
const TypeLoc &getFirstTypeLoc() const {
11891141
assert(getKind() == RequirementReprKind::SameType);
11901142
return FirstType;
11911143
}
11921144

11931145
/// Retrieve the second type of a same-type requirement.
1194-
Type getSecondType() const {
1195-
assert(getKind() == RequirementReprKind::SameType);
1196-
return SecondType.getType();
1197-
}
1198-
11991146
TypeRepr *getSecondTypeRepr() const {
1200-
assert(getKind() == RequirementReprKind::SameType);
1201-
return SecondType.getTypeRepr();
1202-
}
1203-
1204-
TypeLoc &getSecondTypeLoc() {
1205-
assert(getKind() == RequirementReprKind::SameType);
1206-
return SecondType;
1207-
}
1208-
1209-
const TypeLoc &getSecondTypeLoc() const {
12101147
assert(getKind() == RequirementReprKind::SameType);
12111148
return SecondType;
12121149
}
@@ -1217,19 +1154,13 @@ class RequirementRepr {
12171154
return SeparatorLoc;
12181155
}
12191156

1220-
SourceRange getSourceRange() const {
1221-
if (getKind() == RequirementReprKind::LayoutConstraint)
1222-
return SourceRange(FirstType.getSourceRange().Start,
1223-
SecondLayout.getSourceRange().End);
1224-
return SourceRange(FirstType.getSourceRange().Start,
1225-
SecondType.getSourceRange().End);
1226-
}
1157+
SourceRange getSourceRange() const;
12271158

12281159
/// Retrieve the first or subject type representation from the \c repr,
12291160
/// or \c nullptr if \c repr is null.
12301161
static TypeRepr *getFirstTypeRepr(const RequirementRepr *repr) {
12311162
if (!repr) return nullptr;
1232-
return repr->FirstType.getTypeRepr();
1163+
return repr->FirstType;
12331164
}
12341165

12351166
/// Retrieve the second or constraint type representation from the \c repr,
@@ -1238,7 +1169,7 @@ class RequirementRepr {
12381169
if (!repr) return nullptr;
12391170
assert(repr->getKind() == RequirementReprKind::TypeConstraint ||
12401171
repr->getKind() == RequirementReprKind::SameType);
1241-
return repr->SecondType.getTypeRepr();
1172+
return repr->SecondType;
12421173
}
12431174

12441175
SWIFT_DEBUG_DUMP;

lib/AST/Decl.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,15 @@ bool Decl::isWeakImported(ModuleDecl *fromModule) const {
875875
return !fromContext.isContainedIn(containingContext);
876876
}
877877

878+
879+
SourceRange RequirementRepr::getSourceRange() const {
880+
if (getKind() == RequirementReprKind::LayoutConstraint)
881+
return SourceRange(FirstType->getSourceRange().Start,
882+
SecondLayout.getSourceRange().End);
883+
return SourceRange(FirstType->getSourceRange().Start,
884+
SecondType->getSourceRange().End);
885+
}
886+
878887
GenericParamList::GenericParamList(SourceLoc LAngleLoc,
879888
ArrayRef<GenericTypeParamDecl *> Params,
880889
SourceLoc WhereLoc,

0 commit comments

Comments
 (0)