@@ -4829,6 +4829,7 @@ class KeyPathExpr : public Expr {
4829
4829
OptionalChain,
4830
4830
OptionalWrap,
4831
4831
Identity,
4832
+ TupleElement,
4832
4833
};
4833
4834
4834
4835
private:
@@ -4845,7 +4846,12 @@ class KeyPathExpr : public Expr {
4845
4846
Expr *SubscriptIndexExpr;
4846
4847
const Identifier *SubscriptLabelsData;
4847
4848
const ProtocolConformanceRef *SubscriptHashableConformancesData;
4848
- unsigned SubscriptSize;
4849
+
4850
+ union {
4851
+ unsigned SubscriptSize;
4852
+ unsigned FieldNumber;
4853
+ } technicated;
4854
+
4849
4855
Kind KindValue;
4850
4856
Type ComponentType;
4851
4857
SourceLoc Loc;
@@ -4855,21 +4861,22 @@ class KeyPathExpr : public Expr {
4855
4861
Expr *indexExpr,
4856
4862
ArrayRef<Identifier> subscriptLabels,
4857
4863
ArrayRef<ProtocolConformanceRef> indexHashables,
4864
+ unsigned fieldNumber,
4858
4865
Kind kind,
4859
4866
Type type,
4860
4867
SourceLoc loc);
4861
4868
4862
4869
public:
4863
4870
Component ()
4864
- : Component(nullptr , {}, nullptr , {}, {}, Kind::Invalid,
4871
+ : Component(nullptr , {}, nullptr , {}, {}, 0 , Kind::Invalid,
4865
4872
Type (), SourceLoc())
4866
4873
{}
4867
4874
4868
4875
// / Create an unresolved component for a property.
4869
4876
static Component forUnresolvedProperty (DeclName UnresolvedName,
4870
4877
SourceLoc Loc) {
4871
4878
return Component (nullptr ,
4872
- UnresolvedName, nullptr , {}, {},
4879
+ UnresolvedName, nullptr , {}, {}, 0 ,
4873
4880
Kind::UnresolvedProperty,
4874
4881
Type (),
4875
4882
Loc);
@@ -4895,22 +4902,22 @@ class KeyPathExpr : public Expr {
4895
4902
SourceLoc loc) {
4896
4903
4897
4904
return Component (&context,
4898
- {}, index, subscriptLabels, {},
4905
+ {}, index, subscriptLabels, {}, 0 ,
4899
4906
Kind::UnresolvedSubscript,
4900
4907
Type (), loc);
4901
4908
}
4902
4909
4903
4910
// / Create an unresolved optional force `!` component.
4904
4911
static Component forUnresolvedOptionalForce (SourceLoc BangLoc) {
4905
- return Component (nullptr , {}, nullptr , {}, {},
4912
+ return Component (nullptr , {}, nullptr , {}, {}, 0 ,
4906
4913
Kind::OptionalForce,
4907
4914
Type (),
4908
4915
BangLoc);
4909
4916
}
4910
4917
4911
4918
// / Create an unresolved optional chain `?` component.
4912
4919
static Component forUnresolvedOptionalChain (SourceLoc QuestionLoc) {
4913
- return Component (nullptr , {}, nullptr , {}, {},
4920
+ return Component (nullptr , {}, nullptr , {}, {}, 0 ,
4914
4921
Kind::OptionalChain,
4915
4922
Type (),
4916
4923
QuestionLoc);
@@ -4920,7 +4927,7 @@ class KeyPathExpr : public Expr {
4920
4927
static Component forProperty (ConcreteDeclRef property,
4921
4928
Type propertyType,
4922
4929
SourceLoc loc) {
4923
- return Component (nullptr , property, nullptr , {}, {},
4930
+ return Component (nullptr , property, nullptr , {}, {}, 0 ,
4924
4931
Kind::Property,
4925
4932
propertyType,
4926
4933
loc);
@@ -4949,15 +4956,15 @@ class KeyPathExpr : public Expr {
4949
4956
4950
4957
// / Create an optional-forcing `!` component.
4951
4958
static Component forOptionalForce (Type forcedType, SourceLoc bangLoc) {
4952
- return Component (nullptr , {}, nullptr , {}, {},
4959
+ return Component (nullptr , {}, nullptr , {}, {}, 0 ,
4953
4960
Kind::OptionalForce, forcedType,
4954
4961
bangLoc);
4955
4962
}
4956
4963
4957
4964
// / Create an optional-chaining `?` component.
4958
4965
static Component forOptionalChain (Type unwrappedType,
4959
4966
SourceLoc questionLoc) {
4960
- return Component (nullptr , {}, nullptr , {}, {},
4967
+ return Component (nullptr , {}, nullptr , {}, {}, 0 ,
4961
4968
Kind::OptionalChain, unwrappedType,
4962
4969
questionLoc);
4963
4970
}
@@ -4966,17 +4973,26 @@ class KeyPathExpr : public Expr {
4966
4973
// / syntax but may appear when the non-optional result of an optional chain
4967
4974
// / is implicitly wrapped.
4968
4975
static Component forOptionalWrap (Type wrappedType) {
4969
- return Component (nullptr , {}, nullptr , {}, {},
4976
+ return Component (nullptr , {}, nullptr , {}, {}, 0 ,
4970
4977
Kind::OptionalWrap, wrappedType,
4971
4978
SourceLoc ());
4972
4979
}
4973
4980
4974
4981
static Component forIdentity (SourceLoc selfLoc) {
4975
- return Component (nullptr , {}, nullptr , {}, {},
4982
+ return Component (nullptr , {}, nullptr , {}, {}, 0 ,
4976
4983
Kind::Identity, Type (),
4977
4984
selfLoc);
4978
4985
}
4979
4986
4987
+ static Component forTupleElement (unsigned fieldNumber,
4988
+ Type elementType,
4989
+ SourceLoc loc) {
4990
+ return Component (nullptr , {}, nullptr , {}, {}, fieldNumber,
4991
+ Kind::TupleElement, elementType,
4992
+ loc);
4993
+ }
4994
+
4995
+
4980
4996
SourceLoc getLoc () const {
4981
4997
return Loc;
4982
4998
}
@@ -5000,6 +5016,7 @@ class KeyPathExpr : public Expr {
5000
5016
case Kind::OptionalForce:
5001
5017
case Kind::Property:
5002
5018
case Kind::Identity:
5019
+ case Kind::TupleElement:
5003
5020
return true ;
5004
5021
5005
5022
case Kind::UnresolvedSubscript:
@@ -5023,6 +5040,7 @@ class KeyPathExpr : public Expr {
5023
5040
case Kind::UnresolvedProperty:
5024
5041
case Kind::Property:
5025
5042
case Kind::Identity:
5043
+ case Kind::TupleElement:
5026
5044
return nullptr ;
5027
5045
}
5028
5046
llvm_unreachable (" unhandled kind" );
@@ -5032,7 +5050,7 @@ class KeyPathExpr : public Expr {
5032
5050
switch (getKind ()) {
5033
5051
case Kind::Subscript:
5034
5052
case Kind::UnresolvedSubscript:
5035
- return {SubscriptLabelsData, (size_t )SubscriptSize};
5053
+ return {SubscriptLabelsData, (size_t )technicated. SubscriptSize };
5036
5054
5037
5055
case Kind::Invalid:
5038
5056
case Kind::OptionalChain:
@@ -5041,6 +5059,7 @@ class KeyPathExpr : public Expr {
5041
5059
case Kind::UnresolvedProperty:
5042
5060
case Kind::Property:
5043
5061
case Kind::Identity:
5062
+ case Kind::TupleElement:
5044
5063
llvm_unreachable (" no subscript labels for this kind" );
5045
5064
}
5046
5065
llvm_unreachable (" unhandled kind" );
@@ -5052,7 +5071,7 @@ class KeyPathExpr : public Expr {
5052
5071
case Kind::Subscript:
5053
5072
if (!SubscriptHashableConformancesData)
5054
5073
return {};
5055
- return {SubscriptHashableConformancesData, (size_t )SubscriptSize};
5074
+ return {SubscriptHashableConformancesData, (size_t )technicated. SubscriptSize };
5056
5075
5057
5076
case Kind::UnresolvedSubscript:
5058
5077
case Kind::Invalid:
@@ -5062,6 +5081,7 @@ class KeyPathExpr : public Expr {
5062
5081
case Kind::UnresolvedProperty:
5063
5082
case Kind::Property:
5064
5083
case Kind::Identity:
5084
+ case Kind::TupleElement:
5065
5085
return {};
5066
5086
}
5067
5087
llvm_unreachable (" unhandled kind" );
@@ -5083,6 +5103,7 @@ class KeyPathExpr : public Expr {
5083
5103
case Kind::OptionalForce:
5084
5104
case Kind::Property:
5085
5105
case Kind::Identity:
5106
+ case Kind::TupleElement:
5086
5107
llvm_unreachable (" no unresolved name for this kind" );
5087
5108
}
5088
5109
llvm_unreachable (" unhandled kind" );
@@ -5101,10 +5122,30 @@ class KeyPathExpr : public Expr {
5101
5122
case Kind::OptionalWrap:
5102
5123
case Kind::OptionalForce:
5103
5124
case Kind::Identity:
5125
+ case Kind::TupleElement:
5104
5126
llvm_unreachable (" no decl ref for this kind" );
5105
5127
}
5106
5128
llvm_unreachable (" unhandled kind" );
5107
5129
}
5130
+
5131
+ unsigned getFieldNumber () const {
5132
+ switch (getKind ()) {
5133
+ case Kind::TupleElement:
5134
+ return technicated.FieldNumber ;
5135
+
5136
+ case Kind::Invalid:
5137
+ case Kind::UnresolvedProperty:
5138
+ case Kind::UnresolvedSubscript:
5139
+ case Kind::OptionalChain:
5140
+ case Kind::OptionalWrap:
5141
+ case Kind::OptionalForce:
5142
+ case Kind::Identity:
5143
+ case Kind::Property:
5144
+ case Kind::Subscript:
5145
+ llvm_unreachable (" no field number for this kind" );
5146
+ }
5147
+ llvm_unreachable (" unhandled kind" );
5148
+ }
5108
5149
5109
5150
Type getComponentType () const {
5110
5151
return ComponentType;
0 commit comments