37
37
#include " llvm/ADT/ArrayRef.h"
38
38
#include " llvm/ADT/DenseMapInfo.h"
39
39
#include " llvm/ADT/FoldingSet.h"
40
+ #include " llvm/ADT/Optional.h"
40
41
#include " llvm/ADT/PointerEmbeddedInt.h"
41
42
#include " llvm/ADT/PointerUnion.h"
42
43
#include " llvm/ADT/SmallBitVector.h"
@@ -347,10 +348,11 @@ class alignas(1 << TypeAlignInBits) TypeBase {
347
348
Flags : NumFlagBits
348
349
);
349
350
350
- SWIFT_INLINE_BITFIELD_FULL (AnyFunctionType, TypeBase, NumAFTExtInfoBits+1 +16 ,
351
+ SWIFT_INLINE_BITFIELD_FULL (AnyFunctionType, TypeBase, NumAFTExtInfoBits+1 +1 + 16 ,
351
352
// / Extra information which affects how the function is called, like
352
353
// / regparm and the calling convention.
353
354
ExtInfoBits : NumAFTExtInfoBits,
355
+ HasExtInfo : 1 ,
354
356
HasClangTypeInfo : 1 ,
355
357
: NumPadBits,
356
358
NumParams : 16
@@ -2922,20 +2924,28 @@ class AnyFunctionType : public TypeBase {
2922
2924
// /
2923
2925
// / Subclasses are responsible for storing and retrieving the
2924
2926
// / ClangTypeInfo value if one is present.
2925
- AnyFunctionType (TypeKind Kind, const ASTContext *CanTypeContext,
2926
- Type Output, RecursiveTypeProperties properties,
2927
- unsigned NumParams, ExtInfo Info)
2928
- : TypeBase (Kind, CanTypeContext, properties), Output (Output) {
2929
- Bits.AnyFunctionType .ExtInfoBits = Info.getBits ();
2930
- Bits.AnyFunctionType .HasClangTypeInfo = !Info.getClangTypeInfo ().empty ();
2927
+ AnyFunctionType (TypeKind Kind, const ASTContext *CanTypeContext, Type Output,
2928
+ RecursiveTypeProperties properties, unsigned NumParams,
2929
+ Optional<ExtInfo> Info)
2930
+ : TypeBase (Kind, CanTypeContext, properties), Output (Output) {
2931
+ if (Info.hasValue ()) {
2932
+ Bits.AnyFunctionType .HasExtInfo = true ;
2933
+ Bits.AnyFunctionType .ExtInfoBits = Info.getValue ().getBits ();
2934
+ Bits.AnyFunctionType .HasClangTypeInfo =
2935
+ !Info.getValue ().getClangTypeInfo ().empty ();
2936
+ // The use of both assert() and static_assert() is intentional.
2937
+ assert (Bits.AnyFunctionType .ExtInfoBits == Info.getValue ().getBits () &&
2938
+ " Bits were dropped!" );
2939
+ static_assert (
2940
+ ASTExtInfoBuilder::NumMaskBits == NumAFTExtInfoBits,
2941
+ " ExtInfo and AnyFunctionTypeBitfields must agree on bit size" );
2942
+ } else {
2943
+ Bits.AnyFunctionType .HasExtInfo = false ;
2944
+ Bits.AnyFunctionType .HasClangTypeInfo = false ;
2945
+ Bits.AnyFunctionType .ExtInfoBits = 0 ;
2946
+ }
2931
2947
Bits.AnyFunctionType .NumParams = NumParams;
2932
2948
assert (Bits.AnyFunctionType .NumParams == NumParams && " Params dropped!" );
2933
- // The use of both assert() and static_assert() is intentional.
2934
- assert (Bits.AnyFunctionType .ExtInfoBits == Info.getBits () &&
2935
- " Bits were dropped!" );
2936
- static_assert (
2937
- ASTExtInfoBuilder::NumMaskBits == NumAFTExtInfoBits,
2938
- " ExtInfo and AnyFunctionTypeBitfields must agree on bit size" );
2939
2949
}
2940
2950
2941
2951
public:
@@ -2996,7 +3006,10 @@ class AnyFunctionType : public TypeBase {
2996
3006
// / outer function type's mangling doesn't need to duplicate that information.
2997
3007
bool hasNonDerivableClangType ();
2998
3008
3009
+ bool hasExtInfo () const { return Bits.AnyFunctionType .HasExtInfo ; }
3010
+
2999
3011
ExtInfo getExtInfo () const {
3012
+ assert (hasExtInfo ());
3000
3013
return ExtInfo (Bits.AnyFunctionType .ExtInfoBits , getClangTypeInfo ());
3001
3014
}
3002
3015
@@ -3005,6 +3018,7 @@ class AnyFunctionType : public TypeBase {
3005
3018
// / The parameter useClangFunctionType is present only for staging purposes.
3006
3019
// / In the future, we will always use the canonical clang function type.
3007
3020
ExtInfo getCanonicalExtInfo (bool useClangFunctionType) const {
3021
+ assert (hasExtInfo ());
3008
3022
return ExtInfo (Bits.AnyFunctionType .ExtInfoBits ,
3009
3023
useClangFunctionType ? getCanonicalClangTypeInfo ()
3010
3024
: ClangTypeInfo ());
@@ -3196,7 +3210,7 @@ BEGIN_CAN_TYPE_WRAPPER(AnyFunctionType, Type)
3196
3210
static CanAnyFunctionType get (CanGenericSignature signature,
3197
3211
CanParamArrayRef params,
3198
3212
CanType result,
3199
- ExtInfo info = ExtInfo() );
3213
+ Optional< ExtInfo> info = None );
3200
3214
3201
3215
CanGenericSignature getOptGenericSignature () const ;
3202
3216
@@ -3237,7 +3251,7 @@ class FunctionType final
3237
3251
public:
3238
3252
// / 'Constructor' Factory Function
3239
3253
static FunctionType *get (ArrayRef<Param> params, Type result,
3240
- ExtInfo info = ExtInfo() );
3254
+ Optional< ExtInfo> info = None );
3241
3255
3242
3256
// Retrieve the input parameters of this function type.
3243
3257
ArrayRef<Param> getParams () const {
@@ -3254,25 +3268,28 @@ class FunctionType final
3254
3268
}
3255
3269
3256
3270
void Profile (llvm::FoldingSetNodeID &ID) {
3257
- Profile (ID, getParams (), getResult (), getExtInfo ());
3271
+ Optional<ExtInfo> info = None;
3272
+ if (hasExtInfo ())
3273
+ info = getExtInfo ();
3274
+ Profile (ID, getParams (), getResult (), info);
3258
3275
}
3259
3276
static void Profile (llvm::FoldingSetNodeID &ID,
3260
3277
ArrayRef<Param> params,
3261
3278
Type result,
3262
- ExtInfo info);
3279
+ Optional< ExtInfo> info);
3263
3280
3264
3281
// Implement isa/cast/dyncast/etc.
3265
3282
static bool classof (const TypeBase *T) {
3266
3283
return T->getKind () == TypeKind::Function;
3267
3284
}
3268
3285
3269
3286
private:
3270
- FunctionType (ArrayRef<Param> params, Type result, ExtInfo info,
3287
+ FunctionType (ArrayRef<Param> params, Type result, Optional< ExtInfo> info,
3271
3288
const ASTContext *ctx, RecursiveTypeProperties properties);
3272
3289
};
3273
3290
BEGIN_CAN_TYPE_WRAPPER (FunctionType, AnyFunctionType)
3274
3291
static CanFunctionType get(CanParamArrayRef params, CanType result,
3275
- ExtInfo info = ExtInfo() ) {
3292
+ Optional< ExtInfo> info = None ) {
3276
3293
auto fnType = FunctionType::get (params.getOriginalArray (), result, info);
3277
3294
return cast<FunctionType>(fnType->getCanonicalType ());
3278
3295
}
@@ -3337,7 +3354,7 @@ class GenericFunctionType final : public AnyFunctionType,
3337
3354
GenericFunctionType (GenericSignature sig,
3338
3355
ArrayRef<Param> params,
3339
3356
Type result,
3340
- ExtInfo info,
3357
+ Optional< ExtInfo> info,
3341
3358
const ASTContext *ctx,
3342
3359
RecursiveTypeProperties properties);
3343
3360
@@ -3346,7 +3363,7 @@ class GenericFunctionType final : public AnyFunctionType,
3346
3363
static GenericFunctionType *get (GenericSignature sig,
3347
3364
ArrayRef<Param> params,
3348
3365
Type result,
3349
- ExtInfo info = ExtInfo() );
3366
+ Optional< ExtInfo> info = None );
3350
3367
3351
3368
// Retrieve the input parameters of this function type.
3352
3369
ArrayRef<Param> getParams () const {
@@ -3370,14 +3387,16 @@ class GenericFunctionType final : public AnyFunctionType,
3370
3387
FunctionType *substGenericArgs (llvm::function_ref<Type(Type)> substFn) const ;
3371
3388
3372
3389
void Profile (llvm::FoldingSetNodeID &ID) {
3373
- Profile (ID, getGenericSignature (), getParams (), getResult (),
3374
- getExtInfo ());
3390
+ Optional<ExtInfo> info = None;
3391
+ if (hasExtInfo ())
3392
+ info = getExtInfo ();
3393
+ Profile (ID, getGenericSignature (), getParams (), getResult (), info);
3375
3394
}
3376
3395
static void Profile (llvm::FoldingSetNodeID &ID,
3377
3396
GenericSignature sig,
3378
3397
ArrayRef<Param> params,
3379
3398
Type result,
3380
- ExtInfo info);
3399
+ Optional< ExtInfo> info);
3381
3400
3382
3401
// Implement isa/cast/dyncast/etc.
3383
3402
static bool classof (const TypeBase *T) {
@@ -3390,11 +3409,11 @@ BEGIN_CAN_TYPE_WRAPPER(GenericFunctionType, AnyFunctionType)
3390
3409
static CanGenericFunctionType get(CanGenericSignature sig,
3391
3410
CanParamArrayRef params,
3392
3411
CanType result,
3393
- ExtInfo info = ExtInfo() ) {
3412
+ Optional< ExtInfo> info = None ) {
3394
3413
// Knowing that the argument types are independently canonical is
3395
3414
// not sufficient to guarantee that the function type will be canonical.
3396
- auto fnType = GenericFunctionType::get (sig, params. getOriginalArray (),
3397
- result, info);
3415
+ auto fnType =
3416
+ GenericFunctionType::get (sig, params. getOriginalArray (), result, info);
3398
3417
return cast<GenericFunctionType>(fnType->getCanonicalType ());
3399
3418
}
3400
3419
@@ -3416,7 +3435,7 @@ END_CAN_TYPE_WRAPPER(GenericFunctionType, AnyFunctionType)
3416
3435
3417
3436
inline CanAnyFunctionType
3418
3437
CanAnyFunctionType::get(CanGenericSignature signature, CanParamArrayRef params,
3419
- CanType result, ExtInfo extInfo) {
3438
+ CanType result, Optional< ExtInfo> extInfo) {
3420
3439
if (signature) {
3421
3440
return CanGenericFunctionType::get (signature, params, result, extInfo);
3422
3441
} else {
0 commit comments