@@ -2785,8 +2785,9 @@ class AnyFunctionType : public TypeBase {
27852785 public:
27862786 explicit Param (Type t,
27872787 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) {
27902791 assert (t && " param type must be non-null" );
27912792 assert (!t->is <InOutType>() && " set flags instead" );
27922793 }
@@ -2796,8 +2797,18 @@ class AnyFunctionType : public TypeBase {
27962797 // / element type.
27972798 Type Ty;
27982799
2799- // The label associated with the parameter, if any.
2800+ // / The label associated with the parameter, if any.
28002801 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;
28012812
28022813 // / Parameter specific flags.
28032814 ParameterTypeFlags Flags = {};
@@ -2823,6 +2834,9 @@ class AnyFunctionType : public TypeBase {
28232834
28242835 bool hasLabel () const { return !Label.empty (); }
28252836 Identifier getLabel () const { return Label; }
2837+
2838+ bool hasInternalLabel () const { return !InternalLabel.empty (); }
2839+ Identifier getInternalLabel () const { return InternalLabel; }
28262840
28272841 ParameterTypeFlags getParameterFlags () const { return Flags; }
28282842
@@ -2851,23 +2865,34 @@ class AnyFunctionType : public TypeBase {
28512865 return Flags.getValueOwnership ();
28522866 }
28532867
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.
28542873 bool operator ==(Param const &b) const {
28552874 return (Label == b.Label &&
28562875 getPlainType ()->isEqual (b.getPlainType ()) &&
28572876 Flags == b.Flags );
28582877 }
28592878 bool operator !=(Param const &b) const { return !(*this == b); }
28602879
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+ }
28622885
28632886 Param withLabel (Identifier newLabel) const {
2864- return Param (Ty, newLabel, Flags);
2887+ return Param (Ty, newLabel, Flags, InternalLabel );
28652888 }
28662889
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+ }
28682893
28692894 Param withFlags (ParameterTypeFlags flags) const {
2870- return Param (Ty, Label, flags);
2895+ return Param (Ty, Label, flags, InternalLabel );
28712896 }
28722897 };
28732898
@@ -2988,14 +3013,19 @@ class AnyFunctionType : public TypeBase {
29883013 return composeInput (ctx, params.getOriginalArray (), canonicalVararg);
29893014 }
29903015
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.
29923019 static bool equalParams (ArrayRef<Param> a, ArrayRef<Param> b);
29933020
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.
29953024 static bool equalParams (CanParamArrayRef a, CanParamArrayRef b);
29963025
29973026 // / Given an array of parameters and an array of labels of the
29983027 // / same length, update each parameter to have the corresponding label.
3028+ // / The internal parameter labels remain the same.
29993029 static void relabelParams (MutableArrayRef<Param> params,
30003030 ArrayRef<Identifier> labels);
30013031
0 commit comments