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
@@ -2919,20 +2921,28 @@ class AnyFunctionType : public TypeBase {
2919
2921
// /
2920
2922
// / Subclasses are responsible for storing and retrieving the
2921
2923
// / ClangTypeInfo value if one is present.
2922
- AnyFunctionType (TypeKind Kind, const ASTContext *CanTypeContext,
2923
- Type Output, RecursiveTypeProperties properties,
2924
- unsigned NumParams, ExtInfo Info)
2925
- : TypeBase (Kind, CanTypeContext, properties), Output (Output) {
2926
- Bits.AnyFunctionType .ExtInfoBits = Info.getBits ();
2927
- Bits.AnyFunctionType .HasClangTypeInfo = !Info.getClangTypeInfo ().empty ();
2924
+ AnyFunctionType (TypeKind Kind, const ASTContext *CanTypeContext, Type Output,
2925
+ RecursiveTypeProperties properties, unsigned NumParams,
2926
+ Optional<ExtInfo> Info)
2927
+ : TypeBase (Kind, CanTypeContext, properties), Output (Output) {
2928
+ if (Info.hasValue ()) {
2929
+ Bits.AnyFunctionType .HasExtInfo = true ;
2930
+ Bits.AnyFunctionType .ExtInfoBits = Info.getValue ().getBits ();
2931
+ Bits.AnyFunctionType .HasClangTypeInfo =
2932
+ !Info.getValue ().getClangTypeInfo ().empty ();
2933
+ // The use of both assert() and static_assert() is intentional.
2934
+ assert (Bits.AnyFunctionType .ExtInfoBits == Info.getValue ().getBits () &&
2935
+ " Bits were dropped!" );
2936
+ static_assert (
2937
+ ASTExtInfoBuilder::NumMaskBits == NumAFTExtInfoBits,
2938
+ " ExtInfo and AnyFunctionTypeBitfields must agree on bit size" );
2939
+ } else {
2940
+ Bits.AnyFunctionType .HasExtInfo = false ;
2941
+ Bits.AnyFunctionType .HasClangTypeInfo = false ;
2942
+ Bits.AnyFunctionType .ExtInfoBits = 0 ;
2943
+ }
2928
2944
Bits.AnyFunctionType .NumParams = NumParams;
2929
2945
assert (Bits.AnyFunctionType .NumParams == NumParams && " Params dropped!" );
2930
- // The use of both assert() and static_assert() is intentional.
2931
- assert (Bits.AnyFunctionType .ExtInfoBits == Info.getBits () &&
2932
- " Bits were dropped!" );
2933
- static_assert (
2934
- ASTExtInfoBuilder::NumMaskBits == NumAFTExtInfoBits,
2935
- " ExtInfo and AnyFunctionTypeBitfields must agree on bit size" );
2936
2946
}
2937
2947
2938
2948
public:
@@ -2993,7 +3003,10 @@ class AnyFunctionType : public TypeBase {
2993
3003
// / outer function type's mangling doesn't need to duplicate that information.
2994
3004
bool hasNonDerivableClangType ();
2995
3005
3006
+ bool hasExtInfo () const { return Bits.AnyFunctionType .HasExtInfo ; }
3007
+
2996
3008
ExtInfo getExtInfo () const {
3009
+ assert (hasExtInfo ());
2997
3010
return ExtInfo (Bits.AnyFunctionType .ExtInfoBits , getClangTypeInfo ());
2998
3011
}
2999
3012
@@ -3002,6 +3015,7 @@ class AnyFunctionType : public TypeBase {
3002
3015
// / The parameter useClangFunctionType is present only for staging purposes.
3003
3016
// / In the future, we will always use the canonical clang function type.
3004
3017
ExtInfo getCanonicalExtInfo (bool useClangFunctionType) const {
3018
+ assert (hasExtInfo ());
3005
3019
return ExtInfo (Bits.AnyFunctionType .ExtInfoBits ,
3006
3020
useClangFunctionType ? getCanonicalClangTypeInfo ()
3007
3021
: ClangTypeInfo ());
@@ -3193,7 +3207,7 @@ BEGIN_CAN_TYPE_WRAPPER(AnyFunctionType, Type)
3193
3207
static CanAnyFunctionType get (CanGenericSignature signature,
3194
3208
CanParamArrayRef params,
3195
3209
CanType result,
3196
- ExtInfo info = ExtInfo() );
3210
+ Optional< ExtInfo> info = None );
3197
3211
3198
3212
CanGenericSignature getOptGenericSignature () const ;
3199
3213
@@ -3234,7 +3248,7 @@ class FunctionType final
3234
3248
public:
3235
3249
// / 'Constructor' Factory Function
3236
3250
static FunctionType *get (ArrayRef<Param> params, Type result,
3237
- ExtInfo info = ExtInfo() );
3251
+ Optional< ExtInfo> info = None );
3238
3252
3239
3253
// Retrieve the input parameters of this function type.
3240
3254
ArrayRef<Param> getParams () const {
@@ -3251,25 +3265,28 @@ class FunctionType final
3251
3265
}
3252
3266
3253
3267
void Profile (llvm::FoldingSetNodeID &ID) {
3254
- Profile (ID, getParams (), getResult (), getExtInfo ());
3268
+ Optional<ExtInfo> info = None;
3269
+ if (hasExtInfo ())
3270
+ info = getExtInfo ();
3271
+ Profile (ID, getParams (), getResult (), info);
3255
3272
}
3256
3273
static void Profile (llvm::FoldingSetNodeID &ID,
3257
3274
ArrayRef<Param> params,
3258
3275
Type result,
3259
- ExtInfo info);
3276
+ Optional< ExtInfo> info);
3260
3277
3261
3278
// Implement isa/cast/dyncast/etc.
3262
3279
static bool classof (const TypeBase *T) {
3263
3280
return T->getKind () == TypeKind::Function;
3264
3281
}
3265
3282
3266
3283
private:
3267
- FunctionType (ArrayRef<Param> params, Type result, ExtInfo info,
3284
+ FunctionType (ArrayRef<Param> params, Type result, Optional< ExtInfo> info,
3268
3285
const ASTContext *ctx, RecursiveTypeProperties properties);
3269
3286
};
3270
3287
BEGIN_CAN_TYPE_WRAPPER (FunctionType, AnyFunctionType)
3271
3288
static CanFunctionType get(CanParamArrayRef params, CanType result,
3272
- ExtInfo info = ExtInfo() ) {
3289
+ Optional< ExtInfo> info = None ) {
3273
3290
auto fnType = FunctionType::get (params.getOriginalArray (), result, info);
3274
3291
return cast<FunctionType>(fnType->getCanonicalType ());
3275
3292
}
@@ -3334,7 +3351,7 @@ class GenericFunctionType final : public AnyFunctionType,
3334
3351
GenericFunctionType (GenericSignature sig,
3335
3352
ArrayRef<Param> params,
3336
3353
Type result,
3337
- ExtInfo info,
3354
+ Optional< ExtInfo> info,
3338
3355
const ASTContext *ctx,
3339
3356
RecursiveTypeProperties properties);
3340
3357
@@ -3343,7 +3360,7 @@ class GenericFunctionType final : public AnyFunctionType,
3343
3360
static GenericFunctionType *get (GenericSignature sig,
3344
3361
ArrayRef<Param> params,
3345
3362
Type result,
3346
- ExtInfo info = ExtInfo() );
3363
+ Optional< ExtInfo> info = None );
3347
3364
3348
3365
// Retrieve the input parameters of this function type.
3349
3366
ArrayRef<Param> getParams () const {
@@ -3367,14 +3384,16 @@ class GenericFunctionType final : public AnyFunctionType,
3367
3384
FunctionType *substGenericArgs (llvm::function_ref<Type(Type)> substFn) const ;
3368
3385
3369
3386
void Profile (llvm::FoldingSetNodeID &ID) {
3370
- Profile (ID, getGenericSignature (), getParams (), getResult (),
3371
- getExtInfo ());
3387
+ Optional<ExtInfo> info = None;
3388
+ if (hasExtInfo ())
3389
+ info = getExtInfo ();
3390
+ Profile (ID, getGenericSignature (), getParams (), getResult (), info);
3372
3391
}
3373
3392
static void Profile (llvm::FoldingSetNodeID &ID,
3374
3393
GenericSignature sig,
3375
3394
ArrayRef<Param> params,
3376
3395
Type result,
3377
- ExtInfo info);
3396
+ Optional< ExtInfo> info);
3378
3397
3379
3398
// Implement isa/cast/dyncast/etc.
3380
3399
static bool classof (const TypeBase *T) {
@@ -3387,11 +3406,11 @@ BEGIN_CAN_TYPE_WRAPPER(GenericFunctionType, AnyFunctionType)
3387
3406
static CanGenericFunctionType get(CanGenericSignature sig,
3388
3407
CanParamArrayRef params,
3389
3408
CanType result,
3390
- ExtInfo info = ExtInfo() ) {
3409
+ Optional< ExtInfo> info = None ) {
3391
3410
// Knowing that the argument types are independently canonical is
3392
3411
// not sufficient to guarantee that the function type will be canonical.
3393
- auto fnType = GenericFunctionType::get (sig, params. getOriginalArray (),
3394
- result, info);
3412
+ auto fnType =
3413
+ GenericFunctionType::get (sig, params. getOriginalArray (), result, info);
3395
3414
return cast<GenericFunctionType>(fnType->getCanonicalType ());
3396
3415
}
3397
3416
@@ -3413,7 +3432,7 @@ END_CAN_TYPE_WRAPPER(GenericFunctionType, AnyFunctionType)
3413
3432
3414
3433
inline CanAnyFunctionType
3415
3434
CanAnyFunctionType::get(CanGenericSignature signature, CanParamArrayRef params,
3416
- CanType result, ExtInfo extInfo) {
3435
+ CanType result, Optional< ExtInfo> extInfo) {
3417
3436
if (signature) {
3418
3437
return CanGenericFunctionType::get (signature, params, result, extInfo);
3419
3438
} else {
0 commit comments