@@ -2356,6 +2356,17 @@ class AnyFunctionType : public TypeBase {
2356
2356
// / Whether the parameter is marked 'inout'
2357
2357
bool isInOut () const { return Flags.isInOut (); }
2358
2358
};
2359
+
2360
+ class CanParam : public Param {
2361
+ explicit CanParam (const Param ¶m) : Param(param) {}
2362
+ public:
2363
+ static CanParam getFromParam (const Param ¶m) { return CanParam (param); }
2364
+
2365
+ CanType getType () const { return CanType (Param::getType ()); }
2366
+ };
2367
+
2368
+ using CanParamArrayRef =
2369
+ ArrayRefView<Param,CanParam,CanParam::getFromParam,/* AccessOriginal*/ true >;
2359
2370
2360
2371
// / \brief A class which abstracts out some details necessary for
2361
2372
// / making a call.
@@ -2515,11 +2526,17 @@ class AnyFunctionType : public TypeBase {
2515
2526
// / needed.
2516
2527
static Type composeInput (ASTContext &ctx, ArrayRef<Param> params,
2517
2528
bool canonicalVararg);
2529
+ static Type composeInput (ASTContext &ctx, CanParamArrayRef params,
2530
+ bool canonicalVararg) {
2531
+ return composeInput (ctx, params.getOriginalArray (), canonicalVararg);
2532
+ }
2518
2533
2519
2534
Type getInput () const { return Input; }
2520
2535
Type getResult () const { return Output; }
2521
2536
ArrayRef<AnyFunctionType::Param> getParams () const ;
2522
2537
unsigned getNumParams () const { return NumParams; }
2538
+
2539
+ GenericSignature *getOptGenericSignature () const ;
2523
2540
2524
2541
ExtInfo getExtInfo () const {
2525
2542
return ExtInfo (AnyFunctionTypeBits.ExtInfo );
@@ -2561,14 +2578,26 @@ class AnyFunctionType : public TypeBase {
2561
2578
}
2562
2579
};
2563
2580
BEGIN_CAN_TYPE_WRAPPER (AnyFunctionType, Type)
2564
- typedef AnyFunctionType::ExtInfo ExtInfo;
2581
+ using ExtInfo = AnyFunctionType::ExtInfo;
2582
+ using CanParamArrayRef = AnyFunctionType::CanParamArrayRef;
2583
+
2584
+ static CanAnyFunctionType get (CanGenericSignature signature,
2585
+ CanType input, CanType result);
2586
+ static CanAnyFunctionType get (CanGenericSignature signature,
2587
+ CanType input, CanType result,
2588
+ const ExtInfo &extInfo);
2589
+ static CanAnyFunctionType get (CanGenericSignature signature,
2590
+ CanParamArrayRef params,
2591
+ CanType result, const ExtInfo &info);
2592
+
2593
+ CanGenericSignature getOptGenericSignature () const ;
2565
2594
2566
2595
CanType getInput () const {
2567
2596
return getPointer ()->getInput ()->getCanonicalType ();
2568
2597
}
2569
-
2570
- ArrayRef<AnyFunctionType::Param> getParams () const {
2571
- return getPointer ()->getParams ();
2598
+
2599
+ CanParamArrayRef getParams () const {
2600
+ return CanParamArrayRef ( getPointer ()->getParams () );
2572
2601
}
2573
2602
2574
2603
PROXY_CAN_TYPE_SIMPLE_GETTER (getResult)
@@ -2616,20 +2645,19 @@ class FunctionType final : public AnyFunctionType,
2616
2645
};
2617
2646
BEGIN_CAN_TYPE_WRAPPER (FunctionType, AnyFunctionType)
2618
2647
static CanFunctionType get(CanType input, CanType result) {
2619
- return CanFunctionType (
2620
- FunctionType::get (input, result)
2621
- ->getCanonicalType ()->castTo <FunctionType>());
2648
+ auto fnType = FunctionType::get (input, result);
2649
+ return cast<FunctionType>(fnType->getCanonicalType ());
2622
2650
}
2623
2651
static CanFunctionType get (CanType input, CanType result,
2624
2652
const ExtInfo &info) {
2625
- return CanFunctionType (
2626
- FunctionType::get (input, result, info)
2627
- ->getCanonicalType ()->castTo <FunctionType>());
2653
+ auto fnType = FunctionType::get (input, result, info);
2654
+ return cast<FunctionType>(fnType->getCanonicalType ());
2628
2655
}
2629
- static CanFunctionType get (ArrayRef<AnyFunctionType::Param> params,
2630
- Type result, const ExtInfo &info) {
2631
- return CanFunctionType (FunctionType::get (params, result, info,
2632
- /* canonicalVararg=*/ true ));
2656
+ static CanFunctionType get (CanParamArrayRef params, CanType result,
2657
+ const ExtInfo &info) {
2658
+ auto fnType = FunctionType::get (params.getOriginalArray (),
2659
+ result, info, /* canonicalVararg=*/ true );
2660
+ return cast<FunctionType>(fnType->getCanonicalType ());
2633
2661
}
2634
2662
2635
2663
CanFunctionType withExtInfo (ExtInfo info) const {
@@ -2749,13 +2777,13 @@ BEGIN_CAN_TYPE_WRAPPER(GenericFunctionType, AnyFunctionType)
2749
2777
2750
2778
// / Create a new generic function type.
2751
2779
static CanGenericFunctionType get (CanGenericSignature sig,
2752
- ArrayRef<AnyFunctionType::Param> params,
2753
- CanType result,
2780
+ CanParamArrayRef params, CanType result,
2754
2781
const ExtInfo &info) {
2755
2782
// Knowing that the argument types are independently canonical is
2756
2783
// not sufficient to guarantee that the function type will be canonical.
2757
- auto fnType = GenericFunctionType::get (sig, params, result, info,
2758
- /* canonicalVararg=*/ true );
2784
+ auto fnType = GenericFunctionType::get (sig, params.getOriginalArray (),
2785
+ result, info,
2786
+ /* canonicalVararg=*/ true );
2759
2787
return cast<GenericFunctionType>(fnType->getCanonicalType ());
2760
2788
}
2761
2789
@@ -2773,6 +2801,48 @@ BEGIN_CAN_TYPE_WRAPPER(GenericFunctionType, AnyFunctionType)
2773
2801
}
2774
2802
END_CAN_TYPE_WRAPPER (GenericFunctionType, AnyFunctionType)
2775
2803
2804
+ inline CanAnyFunctionType
2805
+ CanAnyFunctionType::get(CanGenericSignature signature,
2806
+ CanType input, CanType result) {
2807
+ return get (signature, input, result, ExtInfo ());
2808
+ }
2809
+
2810
+ inline CanAnyFunctionType
2811
+ CanAnyFunctionType::get (CanGenericSignature signature,
2812
+ CanType input, CanType result, const ExtInfo &extInfo) {
2813
+ if (signature) {
2814
+ return CanGenericFunctionType::get (signature, input, result, extInfo);
2815
+ } else {
2816
+ return CanFunctionType::get (input, result, extInfo);
2817
+ }
2818
+ }
2819
+
2820
+ inline CanAnyFunctionType
2821
+ CanAnyFunctionType::get (CanGenericSignature signature, CanParamArrayRef params,
2822
+ CanType result, const ExtInfo &extInfo) {
2823
+ if (signature) {
2824
+ return CanGenericFunctionType::get (signature, params, result, extInfo);
2825
+ } else {
2826
+ return CanFunctionType::get (params, result, extInfo);
2827
+ }
2828
+ }
2829
+
2830
+ inline GenericSignature *AnyFunctionType::getOptGenericSignature () const {
2831
+ if (auto genericFn = dyn_cast<GenericFunctionType>(this )) {
2832
+ return genericFn->getGenericSignature ();
2833
+ } else {
2834
+ return nullptr ;
2835
+ }
2836
+ }
2837
+
2838
+ inline CanGenericSignature CanAnyFunctionType::getOptGenericSignature () const {
2839
+ if (auto genericFn = dyn_cast<GenericFunctionType>(*this )) {
2840
+ return genericFn.getGenericSignature ();
2841
+ } else {
2842
+ return CanGenericSignature ();
2843
+ }
2844
+ }
2845
+
2776
2846
// / Conventions for passing arguments as parameters.
2777
2847
enum class ParameterConvention {
2778
2848
// / This argument is passed indirectly, i.e. by directly passing the address
0 commit comments