Skip to content

Commit bad2230

Browse files
technicatedToma91
authored andcommitted
Private constructor for tuple element kind keypath in AST
1 parent d7324b9 commit bad2230

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

include/swift/AST/Expr.h

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4861,22 +4861,28 @@ class KeyPathExpr : public Expr {
48614861
Expr *indexExpr,
48624862
ArrayRef<Identifier> subscriptLabels,
48634863
ArrayRef<ProtocolConformanceRef> indexHashables,
4864-
unsigned tupleIndex,
48654864
Kind kind,
48664865
Type type,
48674866
SourceLoc loc);
4867+
4868+
// Private constructor for tuple element kind
4869+
Component(unsigned tupleIndex, Type elementType, SourceLoc loc)
4870+
: Component(nullptr, {}, nullptr, {}, {}, Kind::TupleElement,
4871+
elementType, loc) {
4872+
TupleIndex = tupleIndex;
4873+
}
48684874

48694875
public:
48704876
Component()
4871-
: Component(nullptr, {}, nullptr, {}, {}, 0, Kind::Invalid,
4877+
: Component(nullptr, {}, nullptr, {}, {}, Kind::Invalid,
48724878
Type(), SourceLoc())
48734879
{}
48744880

48754881
/// Create an unresolved component for a property.
48764882
static Component forUnresolvedProperty(DeclName UnresolvedName,
48774883
SourceLoc Loc) {
48784884
return Component(nullptr,
4879-
UnresolvedName, nullptr, {}, {}, 0,
4885+
UnresolvedName, nullptr, {}, {},
48804886
Kind::UnresolvedProperty,
48814887
Type(),
48824888
Loc);
@@ -4902,22 +4908,22 @@ class KeyPathExpr : public Expr {
49024908
SourceLoc loc) {
49034909

49044910
return Component(&context,
4905-
{}, index, subscriptLabels, {}, 0,
4911+
{}, index, subscriptLabels, {},
49064912
Kind::UnresolvedSubscript,
49074913
Type(), loc);
49084914
}
49094915

49104916
/// Create an unresolved optional force `!` component.
49114917
static Component forUnresolvedOptionalForce(SourceLoc BangLoc) {
4912-
return Component(nullptr, {}, nullptr, {}, {}, 0,
4918+
return Component(nullptr, {}, nullptr, {}, {},
49134919
Kind::OptionalForce,
49144920
Type(),
49154921
BangLoc);
49164922
}
49174923

49184924
/// Create an unresolved optional chain `?` component.
49194925
static Component forUnresolvedOptionalChain(SourceLoc QuestionLoc) {
4920-
return Component(nullptr, {}, nullptr, {}, {}, 0,
4926+
return Component(nullptr, {}, nullptr, {}, {},
49214927
Kind::OptionalChain,
49224928
Type(),
49234929
QuestionLoc);
@@ -4927,7 +4933,7 @@ class KeyPathExpr : public Expr {
49274933
static Component forProperty(ConcreteDeclRef property,
49284934
Type propertyType,
49294935
SourceLoc loc) {
4930-
return Component(nullptr, property, nullptr, {}, {}, 0,
4936+
return Component(nullptr, property, nullptr, {}, {},
49314937
Kind::Property,
49324938
propertyType,
49334939
loc);
@@ -4956,15 +4962,15 @@ class KeyPathExpr : public Expr {
49564962

49574963
/// Create an optional-forcing `!` component.
49584964
static Component forOptionalForce(Type forcedType, SourceLoc bangLoc) {
4959-
return Component(nullptr, {}, nullptr, {}, {}, 0,
4965+
return Component(nullptr, {}, nullptr, {}, {},
49604966
Kind::OptionalForce, forcedType,
49614967
bangLoc);
49624968
}
49634969

49644970
/// Create an optional-chaining `?` component.
49654971
static Component forOptionalChain(Type unwrappedType,
49664972
SourceLoc questionLoc) {
4967-
return Component(nullptr, {}, nullptr, {}, {}, 0,
4973+
return Component(nullptr, {}, nullptr, {}, {},
49684974
Kind::OptionalChain, unwrappedType,
49694975
questionLoc);
49704976
}
@@ -4973,23 +4979,21 @@ class KeyPathExpr : public Expr {
49734979
/// syntax but may appear when the non-optional result of an optional chain
49744980
/// is implicitly wrapped.
49754981
static Component forOptionalWrap(Type wrappedType) {
4976-
return Component(nullptr, {}, nullptr, {}, {}, 0,
4982+
return Component(nullptr, {}, nullptr, {}, {},
49774983
Kind::OptionalWrap, wrappedType,
49784984
SourceLoc());
49794985
}
49804986

49814987
static Component forIdentity(SourceLoc selfLoc) {
4982-
return Component(nullptr, {}, nullptr, {}, {}, 0,
4988+
return Component(nullptr, {}, nullptr, {}, {},
49834989
Kind::Identity, Type(),
49844990
selfLoc);
49854991
}
49864992

49874993
static Component forTupleElement(unsigned fieldNumber,
49884994
Type elementType,
49894995
SourceLoc loc) {
4990-
return Component(nullptr, {}, nullptr, {}, {}, fieldNumber,
4991-
Kind::TupleElement, elementType,
4992-
loc);
4996+
return Component(fieldNumber, elementType, loc);
49934997
}
49944998

49954999

lib/AST/Expr.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,27 +2185,19 @@ KeyPathExpr::Component::Component(ASTContext *ctxForCopyingLabels,
21852185
Expr *indexExpr,
21862186
ArrayRef<Identifier> subscriptLabels,
21872187
ArrayRef<ProtocolConformanceRef> indexHashables,
2188-
unsigned tupleIndex,
21892188
Kind kind,
21902189
Type type,
21912190
SourceLoc loc)
21922191
: Decl(decl), SubscriptIndexExpr(indexExpr), KindValue(kind),
21932192
ComponentType(type), Loc(loc)
21942193
{
2194+
assert(kind != Kind::TupleElement || subscriptLabels.empty());
21952195
assert(subscriptLabels.size() == indexHashables.size()
21962196
|| indexHashables.empty());
21972197
SubscriptLabelsData = subscriptLabels.data();
21982198
SubscriptHashableConformancesData = indexHashables.empty()
21992199
? nullptr : indexHashables.data();
2200-
2201-
if (kind == Kind::TupleElement) {
2202-
assert(subscriptLabels.empty()
2203-
&& "subscript labels not empty for tuple element");
2204-
2205-
TupleIndex = tupleIndex;
2206-
} else {
2207-
SubscriptSize = subscriptLabels.size();
2208-
}
2200+
SubscriptSize = subscriptLabels.size();
22092201
}
22102202

22112203
KeyPathExpr::Component
@@ -2214,7 +2206,7 @@ KeyPathExpr::Component::forSubscriptWithPrebuiltIndexExpr(
22142206
Type elementType, SourceLoc loc,
22152207
ArrayRef<ProtocolConformanceRef> indexHashables) {
22162208
return Component(&elementType->getASTContext(),
2217-
subscript, index, labels, indexHashables, 0,
2209+
subscript, index, labels, indexHashables,
22182210
Kind::Subscript, elementType, loc);
22192211
}
22202212

0 commit comments

Comments
 (0)