@@ -2785,8 +2785,9 @@ class AnyFunctionType : public TypeBase {
2785
2785
public:
2786
2786
explicit Param (Type t,
2787
2787
Identifier l = Identifier(),
2788
- ParameterTypeFlags f = ParameterTypeFlags())
2789
- : Ty(t), Label(l), Flags(f) {
2788
+ ParameterTypeFlags f = ParameterTypeFlags(),
2789
+ Identifier internalLabel = Identifier())
2790
+ : Ty(t), Label(l), InternalLabel(internalLabel), Flags(f) {
2790
2791
assert (t && " param type must be non-null" );
2791
2792
assert (!t->is <InOutType>() && " set flags instead" );
2792
2793
}
@@ -2796,8 +2797,18 @@ class AnyFunctionType : public TypeBase {
2796
2797
// / element type.
2797
2798
Type Ty;
2798
2799
2799
- // The label associated with the parameter, if any.
2800
+ // / The label associated with the parameter, if any.
2800
2801
Identifier Label;
2802
+
2803
+ // / The internal label of the parameter, if explicitly specified, otherwise
2804
+ // / empty. The internal label is considered syntactic sugar. It is not
2805
+ // / considered part of the canonical type and is thus also ignored in \c
2806
+ // / operator==.
2807
+ // / E.g.
2808
+ // / - `name name2: Int` has internal label `name2`
2809
+ // / - `_ name2: Int` has internal label `name2`
2810
+ // / - `name: Int` has no internal label
2811
+ Identifier InternalLabel;
2801
2812
2802
2813
// / Parameter specific flags.
2803
2814
ParameterTypeFlags Flags = {};
@@ -2823,6 +2834,9 @@ class AnyFunctionType : public TypeBase {
2823
2834
2824
2835
bool hasLabel () const { return !Label.empty (); }
2825
2836
Identifier getLabel () const { return Label; }
2837
+
2838
+ bool hasInternalLabel () const { return !InternalLabel.empty (); }
2839
+ Identifier getInternalLabel () const { return InternalLabel; }
2826
2840
2827
2841
ParameterTypeFlags getParameterFlags () const { return Flags; }
2828
2842
@@ -2851,23 +2865,34 @@ class AnyFunctionType : public TypeBase {
2851
2865
return Flags.getValueOwnership ();
2852
2866
}
2853
2867
2868
+ // / Returns \c true if the two \c Params are equal in their canonicalized
2869
+ // / form.
2870
+ // / Two \c Params are equal if their external label, flags and
2871
+ // / *canonicalized* types match. The internal label and sugar types are
2872
+ // / *not* considered for type equality.
2854
2873
bool operator ==(Param const &b) const {
2855
2874
return (Label == b.Label &&
2856
2875
getPlainType ()->isEqual (b.getPlainType ()) &&
2857
2876
Flags == b.Flags );
2858
2877
}
2859
2878
bool operator !=(Param const &b) const { return !(*this == b); }
2860
2879
2861
- Param getWithoutLabel () const { return Param (Ty, Identifier (), Flags); }
2880
+ // / Return the parameter without external and internal labels.
2881
+ Param getWithoutLabels () const {
2882
+ return Param (Ty, /* Label=*/ Identifier (), Flags,
2883
+ /* InternalLabel=*/ Identifier ());
2884
+ }
2862
2885
2863
2886
Param withLabel (Identifier newLabel) const {
2864
- return Param (Ty, newLabel, Flags);
2887
+ return Param (Ty, newLabel, Flags, InternalLabel );
2865
2888
}
2866
2889
2867
- Param withType (Type newType) const { return Param (newType, Label, Flags); }
2890
+ Param withType (Type newType) const {
2891
+ return Param (newType, Label, Flags, InternalLabel);
2892
+ }
2868
2893
2869
2894
Param withFlags (ParameterTypeFlags flags) const {
2870
- return Param (Ty, Label, flags);
2895
+ return Param (Ty, Label, flags, InternalLabel );
2871
2896
}
2872
2897
};
2873
2898
@@ -2988,14 +3013,19 @@ class AnyFunctionType : public TypeBase {
2988
3013
return composeInput (ctx, params.getOriginalArray (), canonicalVararg);
2989
3014
}
2990
3015
2991
- // / Given two arrays of parameters determine if they are equal.
3016
+ // / Given two arrays of parameters determine if they are equal in their
3017
+ // / canonicalized form. Internal labels and type sugar is *not* taken into
3018
+ // / account.
2992
3019
static bool equalParams (ArrayRef<Param> a, ArrayRef<Param> b);
2993
3020
2994
- // / Given two arrays of parameters determine if they are equal.
3021
+ // / Given two arrays of parameters determine if they are equal in their
3022
+ // / canonicalized form. Internal labels and type sugar is *not* taken into
3023
+ // / account.
2995
3024
static bool equalParams (CanParamArrayRef a, CanParamArrayRef b);
2996
3025
2997
3026
// / Given an array of parameters and an array of labels of the
2998
3027
// / same length, update each parameter to have the corresponding label.
3028
+ // / The internal parameter labels remain the same.
2999
3029
static void relabelParams (MutableArrayRef<Param> params,
3000
3030
ArrayRef<Identifier> labels);
3001
3031
0 commit comments