@@ -2612,19 +2612,15 @@ getSILFunctionLanguage(SILFunctionTypeRepresentation rep) {
2612
2612
llvm_unreachable (" Unhandled SILFunctionTypeRepresentation in switch." );
2613
2613
}
2614
2614
2615
- // / AnyFunctionType - A function type has a single input and result, but
2616
- // / these types may be tuples, for example:
2615
+ // / AnyFunctionType - A function type has zero or more input parameters and a
2616
+ // / single result. The result type may be a tuple. For example:
2617
2617
// / "(int) -> int" or "(a : int, b : int) -> (int, int)".
2618
- // / Note that the parser requires that the input to a function type be a Tuple
2619
- // / or ParenType, but ParenType desugars to its element, so the input to a
2620
- // / function may be an arbitrary type.
2621
2618
// /
2622
2619
// / There are two kinds of function types: monomorphic (FunctionType) and
2623
2620
// / polymorphic (GenericFunctionType). Both type families additionally can
2624
2621
// / be 'thin', indicating that a function value has no capture context and can be
2625
2622
// / represented at the binary level as a single function pointer.
2626
2623
class AnyFunctionType : public TypeBase {
2627
- const Type Input;
2628
2624
const Type Output;
2629
2625
2630
2626
public:
@@ -2651,13 +2647,21 @@ class AnyFunctionType : public TypeBase {
2651
2647
ParameterTypeFlags Flags = {};
2652
2648
2653
2649
public:
2654
- // / FIXME(Remove InOutType): This is mostly for copying between param
2655
- // / types and should go away.
2656
- Type getType () const ;
2650
+ // / FIXME: Remove this. Return the formal type of the parameter in the
2651
+ // / function type, including the InOutType if there is one.
2652
+ // /
2653
+ // / For example, 'inout Int' => 'inout Int', 'Int...' => 'Int'.
2654
+ Type getOldType () const ;
2657
2655
2656
+ // / Return the formal type of the parameter.
2657
+ // /
2658
+ // / For example, 'inout Int' => 'Int', 'Int...' => 'Int'.
2658
2659
Type getPlainType () const { return Ty; }
2659
2660
2660
- // / The type of the parameter. Adjusts for varargs, but not inout.
2661
+ // / The type of the parameter when referenced inside the function body
2662
+ // / as an rvalue.
2663
+ // /
2664
+ // / For example, 'inout Int' => 'Int', 'Int...' => '[Int]'.
2661
2665
Type getParameterType (bool forCanonical = false ,
2662
2666
ASTContext *ctx = nullptr ) const ;
2663
2667
@@ -2703,7 +2707,7 @@ class AnyFunctionType : public TypeBase {
2703
2707
public:
2704
2708
static CanParam getFromParam (const Param ¶m) { return CanParam (param); }
2705
2709
2706
- CanType getType () const { return CanType (Param::getType ()); }
2710
+ CanType getOldType () const { return CanType (Param::getOldType ()); }
2707
2711
CanType getPlainType () const { return CanType (Param::getPlainType ()); }
2708
2712
CanType getParameterType () const {
2709
2713
return CanType (Param::getParameterType (/* forCanonical*/ true ));
@@ -2911,9 +2915,9 @@ class AnyFunctionType : public TypeBase {
2911
2915
2912
2916
protected:
2913
2917
AnyFunctionType (TypeKind Kind, const ASTContext *CanTypeContext,
2914
- Type Input, Type Output, RecursiveTypeProperties properties,
2918
+ Type Output, RecursiveTypeProperties properties,
2915
2919
unsigned NumParams, ExtInfo Info)
2916
- : TypeBase(Kind, CanTypeContext, properties), Input(Input), Output(Output) {
2920
+ : TypeBase(Kind, CanTypeContext, properties), Output(Output) {
2917
2921
Bits.AnyFunctionType .ExtInfo = Info.Bits ;
2918
2922
Bits.AnyFunctionType .NumParams = NumParams;
2919
2923
assert (Bits.AnyFunctionType .NumParams == NumParams && " Params dropped!" );
@@ -2950,7 +2954,6 @@ class AnyFunctionType : public TypeBase {
2950
2954
static void relabelParams (MutableArrayRef<Param> params,
2951
2955
ArrayRef<Identifier> labels);
2952
2956
2953
- Type getInput () const { return Input; }
2954
2957
Type getResult () const { return Output; }
2955
2958
ArrayRef<Param> getParams () const ;
2956
2959
unsigned getNumParams () const { return Bits.AnyFunctionType .NumParams ; }
@@ -2982,10 +2985,6 @@ class AnyFunctionType : public TypeBase {
2982
2985
return getExtInfo ().throws ();
2983
2986
}
2984
2987
2985
- // / Determine whether the given function input type is one of the
2986
- // / canonical forms.
2987
- static bool isCanonicalFunctionInputType (Type input);
2988
-
2989
2988
// / Returns a new function type exactly like this one but with the ExtInfo
2990
2989
// / replaced.
2991
2990
AnyFunctionType *withExtInfo (ExtInfo info) const ;
@@ -3011,10 +3010,6 @@ BEGIN_CAN_TYPE_WRAPPER(AnyFunctionType, Type)
3011
3010
3012
3011
CanGenericSignature getOptGenericSignature () const ;
3013
3012
3014
- CanType getInput () const {
3015
- return getPointer ()->getInput ()->getCanonicalType ();
3016
- }
3017
-
3018
3013
CanParamArrayRef getParams () const {
3019
3014
return CanParamArrayRef (getPointer ()->getParams ());
3020
3015
}
@@ -3035,37 +3030,41 @@ inline AnyFunctionType::CanYield AnyFunctionType::Yield::getCanonical() const {
3035
3030
// / For example:
3036
3031
// / let x : (Float, Int) -> Int
3037
3032
class FunctionType final : public AnyFunctionType,
3033
+ public llvm::FoldingSetNode,
3038
3034
private llvm::TrailingObjects<FunctionType, AnyFunctionType::Param> {
3039
3035
friend TrailingObjects;
3040
3036
3041
3037
public:
3042
3038
// / 'Constructor' Factory Function
3043
- static FunctionType *get (ArrayRef<Param> params,
3044
- Type result,
3045
- ExtInfo info = ExtInfo(),
3046
- bool canonicalVararg = false);
3039
+ static FunctionType *get (ArrayRef<Param> params, Type result,
3040
+ ExtInfo info = ExtInfo());
3047
3041
3048
3042
// Retrieve the input parameters of this function type.
3049
3043
ArrayRef<Param> getParams () const {
3050
3044
return {getTrailingObjects<Param>(), getNumParams ()};
3051
3045
}
3052
-
3046
+
3047
+ void Profile (llvm::FoldingSetNodeID &ID) {
3048
+ Profile (ID, getParams (), getResult (), getExtInfo ());
3049
+ }
3050
+ static void Profile (llvm::FoldingSetNodeID &ID,
3051
+ ArrayRef<Param> params,
3052
+ Type result,
3053
+ ExtInfo info);
3054
+
3053
3055
// Implement isa/cast/dyncast/etc.
3054
3056
static bool classof (const TypeBase *T) {
3055
3057
return T->getKind () == TypeKind::Function;
3056
3058
}
3057
3059
3058
3060
private:
3059
- FunctionType (ArrayRef<Param> params,
3060
- Type Input, Type Result,
3061
- RecursiveTypeProperties properties,
3062
- ExtInfo Info);
3061
+ FunctionType (ArrayRef<Param> params, Type result, ExtInfo info,
3062
+ const ASTContext *ctx, RecursiveTypeProperties properties);
3063
3063
};
3064
3064
BEGIN_CAN_TYPE_WRAPPER (FunctionType, AnyFunctionType)
3065
3065
static CanFunctionType get(CanParamArrayRef params, CanType result,
3066
3066
ExtInfo info = ExtInfo()) {
3067
- auto fnType = FunctionType::get (params.getOriginalArray (),
3068
- result, info, /* canonicalVararg=*/ true );
3067
+ auto fnType = FunctionType::get (params.getOriginalArray (), result, info);
3069
3068
return cast<FunctionType>(fnType->getCanonicalType ());
3070
3069
}
3071
3070
@@ -3102,7 +3101,6 @@ class GenericFunctionType final : public AnyFunctionType,
3102
3101
// / Construct a new generic function type.
3103
3102
GenericFunctionType (GenericSignature *sig,
3104
3103
ArrayRef<Param> params,
3105
- Type input,
3106
3104
Type result,
3107
3105
ExtInfo info,
3108
3106
const ASTContext *ctx,
@@ -3113,8 +3111,7 @@ class GenericFunctionType final : public AnyFunctionType,
3113
3111
static GenericFunctionType *get (GenericSignature *sig,
3114
3112
ArrayRef<Param> params,
3115
3113
Type result,
3116
- ExtInfo info = ExtInfo(),
3117
- bool canonicalVararg = false);
3114
+ ExtInfo info = ExtInfo());
3118
3115
3119
3116
// Retrieve the input parameters of this function type.
3120
3117
ArrayRef<Param> getParams () const {
@@ -3137,12 +3134,12 @@ class GenericFunctionType final : public AnyFunctionType,
3137
3134
FunctionType *substGenericArgs (SubstitutionMap subs);
3138
3135
3139
3136
void Profile (llvm::FoldingSetNodeID &ID) {
3140
- Profile (ID, getGenericSignature (), getInput (), getResult (),
3137
+ Profile (ID, getGenericSignature (), getParams (), getResult (),
3141
3138
getExtInfo ());
3142
3139
}
3143
3140
static void Profile (llvm::FoldingSetNodeID &ID,
3144
3141
GenericSignature *sig,
3145
- Type input ,
3142
+ ArrayRef<Param> params ,
3146
3143
Type result,
3147
3144
ExtInfo info);
3148
3145
@@ -3161,8 +3158,7 @@ BEGIN_CAN_TYPE_WRAPPER(GenericFunctionType, AnyFunctionType)
3161
3158
// Knowing that the argument types are independently canonical is
3162
3159
// not sufficient to guarantee that the function type will be canonical.
3163
3160
auto fnType = GenericFunctionType::get (sig, params.getOriginalArray (),
3164
- result, info,
3165
- /* canonicalVararg=*/ true );
3161
+ result, info);
3166
3162
return cast<GenericFunctionType>(fnType->getCanonicalType ());
3167
3163
}
3168
3164
0 commit comments