Skip to content

Commit a542510

Browse files
committed
AST: ExtInfo just wraps an unsigned integer, no need to pass it by reference
1 parent 1bbea4a commit a542510

File tree

12 files changed

+56
-84
lines changed

12 files changed

+56
-84
lines changed

include/swift/AST/Types.h

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2892,7 +2892,7 @@ class AnyFunctionType : public TypeBase {
28922892
protected:
28932893
AnyFunctionType(TypeKind Kind, const ASTContext *CanTypeContext,
28942894
Type Input, Type Output, RecursiveTypeProperties properties,
2895-
unsigned NumParams, const ExtInfo &Info)
2895+
unsigned NumParams, ExtInfo Info)
28962896
: TypeBase(Kind, CanTypeContext, properties), Input(Input), Output(Output) {
28972897
Bits.AnyFunctionType.ExtInfo = Info.Bits;
28982898
Bits.AnyFunctionType.NumParams = NumParams;
@@ -2906,7 +2906,7 @@ class AnyFunctionType : public TypeBase {
29062906
public:
29072907
/// \brief Break an input type into an array of \c AnyFunctionType::Params.
29082908
static void decomposeInput(Type type,
2909-
SmallVectorImpl<AnyFunctionType::Param> &result);
2909+
SmallVectorImpl<Param> &result);
29102910

29112911
/// \brief Take an array of parameters and turn it into an input type.
29122912
///
@@ -2920,15 +2920,14 @@ class AnyFunctionType : public TypeBase {
29202920
}
29212921

29222922
/// \brief Given two arrays of parameters determine if they are equal.
2923-
static bool equalParams(ArrayRef<AnyFunctionType::Param> a,
2924-
ArrayRef<AnyFunctionType::Param> b);
2923+
static bool equalParams(ArrayRef<Param> a, ArrayRef<Param> b);
29252924

29262925
/// \brief Given two arrays of parameters determine if they are equal.
29272926
static bool equalParams(CanParamArrayRef a, CanParamArrayRef b);
29282927

29292928
Type getInput() const { return Input; }
29302929
Type getResult() const { return Output; }
2931-
ArrayRef<AnyFunctionType::Param> getParams() const;
2930+
ArrayRef<Param> getParams() const;
29322931
unsigned getNumParams() const { return Bits.AnyFunctionType.NumParams; }
29332932

29342933
GenericSignature *getOptGenericSignature() const;
@@ -2980,14 +2979,13 @@ BEGIN_CAN_TYPE_WRAPPER(AnyFunctionType, Type)
29802979
using ExtInfo = AnyFunctionType::ExtInfo;
29812980
using CanParamArrayRef = AnyFunctionType::CanParamArrayRef;
29822981

2983-
static CanAnyFunctionType get(CanGenericSignature signature,
2984-
CanType input, CanType result);
29852982
static CanAnyFunctionType get(CanGenericSignature signature,
29862983
CanType input, CanType result,
2987-
const ExtInfo &extInfo);
2984+
ExtInfo extInfo = ExtInfo());
29882985
static CanAnyFunctionType get(CanGenericSignature signature,
29892986
CanParamArrayRef params,
2990-
CanType result, const ExtInfo &info);
2987+
CanType result,
2988+
ExtInfo info = ExtInfo());
29912989

29922990
CanGenericSignature getOptGenericSignature() const;
29932991

@@ -3020,19 +3018,17 @@ class FunctionType final : public AnyFunctionType,
30203018

30213019
public:
30223020
/// 'Constructor' Factory Function
3023-
static FunctionType *get(Type Input, Type Result) {
3024-
return get(Input, Result, ExtInfo());
3025-
}
3026-
3027-
static FunctionType *get(Type Input, Type Result, const ExtInfo &Info);
3021+
static FunctionType *get(Type Input, Type Result,
3022+
ExtInfo Info = ExtInfo());
30283023

3029-
static FunctionType *get(ArrayRef<AnyFunctionType::Param> params,
3030-
Type result, const ExtInfo &info,
3024+
static FunctionType *get(ArrayRef<Param> params,
3025+
Type result,
3026+
ExtInfo info = ExtInfo(),
30313027
bool canonicalVararg = false);
30323028

30333029
// Retrieve the input parameters of this function type.
3034-
ArrayRef<AnyFunctionType::Param> getParams() const {
3035-
return {getTrailingObjects<AnyFunctionType::Param>(), getNumParams()};
3030+
ArrayRef<Param> getParams() const {
3031+
return {getTrailingObjects<Param>(), getNumParams()};
30363032
}
30373033

30383034
// Implement isa/cast/dyncast/etc.
@@ -3041,23 +3037,19 @@ class FunctionType final : public AnyFunctionType,
30413037
}
30423038

30433039
private:
3044-
FunctionType(ArrayRef<AnyFunctionType::Param> params,
3040+
FunctionType(ArrayRef<Param> params,
30453041
Type Input, Type Result,
30463042
RecursiveTypeProperties properties,
3047-
const ExtInfo &Info);
3043+
ExtInfo Info);
30483044
};
30493045
BEGIN_CAN_TYPE_WRAPPER(FunctionType, AnyFunctionType)
3050-
static CanFunctionType get(CanType input, CanType result) {
3051-
auto fnType = FunctionType::get(input, result);
3052-
return cast<FunctionType>(fnType->getCanonicalType());
3053-
}
30543046
static CanFunctionType get(CanType input, CanType result,
3055-
const ExtInfo &info) {
3047+
ExtInfo info = ExtInfo()) {
30563048
auto fnType = FunctionType::get(input, result, info);
30573049
return cast<FunctionType>(fnType->getCanonicalType());
30583050
}
30593051
static CanFunctionType get(CanParamArrayRef params, CanType result,
3060-
const ExtInfo &info) {
3052+
ExtInfo info = ExtInfo()) {
30613053
auto fnType = FunctionType::get(params.getOriginalArray(),
30623054
result, info, /*canonicalVararg=*/true);
30633055
return cast<FunctionType>(fnType->getCanonicalType());
@@ -3102,10 +3094,10 @@ class GenericFunctionType final : public AnyFunctionType,
31023094

31033095
/// Construct a new generic function type.
31043096
GenericFunctionType(GenericSignature *sig,
3105-
ArrayRef<AnyFunctionType::Param> params,
3097+
ArrayRef<Param> params,
31063098
Type input,
31073099
Type result,
3108-
const ExtInfo &info,
3100+
ExtInfo info,
31093101
const ASTContext *ctx,
31103102
RecursiveTypeProperties properties);
31113103

@@ -3114,18 +3106,18 @@ class GenericFunctionType final : public AnyFunctionType,
31143106
static GenericFunctionType *get(GenericSignature *sig,
31153107
Type input,
31163108
Type result,
3117-
const ExtInfo &info);
3109+
ExtInfo info = ExtInfo());
31183110

31193111
/// Create a new generic function type.
31203112
static GenericFunctionType *get(GenericSignature *sig,
31213113
ArrayRef<Param> params,
31223114
Type result,
3123-
const ExtInfo &info,
3115+
ExtInfo info = ExtInfo(),
31243116
bool canonicalVararg = false);
31253117

31263118
// Retrieve the input parameters of this function type.
3127-
ArrayRef<AnyFunctionType::Param> getParams() const {
3128-
return {getTrailingObjects<AnyFunctionType::Param>(), getNumParams()};
3119+
ArrayRef<Param> getParams() const {
3120+
return {getTrailingObjects<Param>(), getNumParams()};
31293121
}
31303122

31313123
/// Retrieve the generic signature of this function type.
@@ -3151,7 +3143,7 @@ class GenericFunctionType final : public AnyFunctionType,
31513143
GenericSignature *sig,
31523144
Type input,
31533145
Type result,
3154-
const ExtInfo &info);
3146+
ExtInfo info);
31553147

31563148
// Implement isa/cast/dyncast/etc.
31573149
static bool classof(const TypeBase *T) {
@@ -3162,7 +3154,7 @@ class GenericFunctionType final : public AnyFunctionType,
31623154
BEGIN_CAN_TYPE_WRAPPER(GenericFunctionType, AnyFunctionType)
31633155
static CanGenericFunctionType get(CanGenericSignature sig,
31643156
CanType input, CanType result,
3165-
const ExtInfo &info) {
3157+
ExtInfo info = ExtInfo()) {
31663158
// Knowing that the argument types are independently canonical is
31673159
// not sufficient to guarantee that the function type will be canonical.
31683160
auto fnType = GenericFunctionType::get(sig, input, result, info);
@@ -3171,8 +3163,9 @@ BEGIN_CAN_TYPE_WRAPPER(GenericFunctionType, AnyFunctionType)
31713163

31723164
/// Create a new generic function type.
31733165
static CanGenericFunctionType get(CanGenericSignature sig,
3174-
CanParamArrayRef params, CanType result,
3175-
const ExtInfo &info) {
3166+
CanParamArrayRef params,
3167+
CanType result,
3168+
ExtInfo info = ExtInfo()) {
31763169
// Knowing that the argument types are independently canonical is
31773170
// not sufficient to guarantee that the function type will be canonical.
31783171
auto fnType = GenericFunctionType::get(sig, params.getOriginalArray(),
@@ -3197,13 +3190,7 @@ END_CAN_TYPE_WRAPPER(GenericFunctionType, AnyFunctionType)
31973190

31983191
inline CanAnyFunctionType
31993192
CanAnyFunctionType::get(CanGenericSignature signature,
3200-
CanType input, CanType result) {
3201-
return get(signature, input, result, ExtInfo());
3202-
}
3203-
3204-
inline CanAnyFunctionType
3205-
CanAnyFunctionType::get(CanGenericSignature signature,
3206-
CanType input, CanType result, const ExtInfo &extInfo) {
3193+
CanType input, CanType result, ExtInfo extInfo) {
32073194
if (signature) {
32083195
return CanGenericFunctionType::get(signature, input, result, extInfo);
32093196
} else {
@@ -3213,7 +3200,7 @@ CanAnyFunctionType::get(CanGenericSignature signature,
32133200

32143201
inline CanAnyFunctionType
32153202
CanAnyFunctionType::get(CanGenericSignature signature, CanParamArrayRef params,
3216-
CanType result, const ExtInfo &extInfo) {
3203+
CanType result, ExtInfo extInfo) {
32173204
if (signature) {
32183205
return CanGenericFunctionType::get(signature, params, result, extInfo);
32193206
} else {

lib/AST/ASTContext.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3612,14 +3612,14 @@ bool AnyFunctionType::equalParams(CanParamArrayRef a, CanParamArrayRef b) {
36123612
}
36133613

36143614
FunctionType *FunctionType::get(ArrayRef<AnyFunctionType::Param> params,
3615-
Type result, const ExtInfo &info,
3615+
Type result, ExtInfo info,
36163616
bool canonicalVararg) {
36173617
return get(composeInput(result->getASTContext(), params, canonicalVararg),
36183618
result, info);
36193619
}
36203620

36213621
FunctionType *FunctionType::get(Type input, Type result,
3622-
const ExtInfo &info) {
3622+
ExtInfo info) {
36233623
auto properties = getFunctionRecursiveProperties(input, result);
36243624
auto arena = getArena(properties);
36253625
uint16_t attrKey = info.getFuncAttrKey();
@@ -3643,7 +3643,7 @@ FunctionType *FunctionType::get(Type input, Type result,
36433643
FunctionType::FunctionType(ArrayRef<AnyFunctionType::Param> params,
36443644
Type input, Type output,
36453645
RecursiveTypeProperties properties,
3646-
const ExtInfo &Info)
3646+
ExtInfo Info)
36473647
: AnyFunctionType(TypeKind::Function,
36483648
(isCanonicalFunctionInputType(input) &&
36493649
output->isCanonical())
@@ -3658,7 +3658,7 @@ void GenericFunctionType::Profile(llvm::FoldingSetNodeID &ID,
36583658
GenericSignature *sig,
36593659
Type input,
36603660
Type result,
3661-
const ExtInfo &info) {
3661+
ExtInfo info) {
36623662
ID.AddPointer(sig);
36633663
ID.AddPointer(input.getPointer());
36643664
ID.AddPointer(result.getPointer());
@@ -3677,7 +3677,7 @@ static Type unwrapParenType(Type type) {
36773677
GenericFunctionType *GenericFunctionType::get(GenericSignature *sig,
36783678
ArrayRef<Param> params,
36793679
Type result,
3680-
const ExtInfo &info,
3680+
ExtInfo info,
36813681
bool canonicalVararg) {
36823682
return get(sig, composeInput(result->getASTContext(), params,
36833683
canonicalVararg),
@@ -3688,7 +3688,7 @@ GenericFunctionType *
36883688
GenericFunctionType::get(GenericSignature *sig,
36893689
Type input,
36903690
Type output,
3691-
const ExtInfo &info) {
3691+
ExtInfo info) {
36923692
assert(sig && "no generic signature for generic function type?!");
36933693
assert(!input->hasTypeVariable() && !output->hasTypeVariable());
36943694

@@ -3738,7 +3738,7 @@ GenericFunctionType::GenericFunctionType(
37383738
ArrayRef<AnyFunctionType::Param> params,
37393739
Type input,
37403740
Type result,
3741-
const ExtInfo &info,
3741+
ExtInfo info,
37423742
const ASTContext *ctx,
37433743
RecursiveTypeProperties properties)
37443744
: AnyFunctionType(TypeKind::GenericFunction, ctx, input, result,

lib/AST/ASTMangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2045,7 +2045,7 @@ CanType ASTMangler::getDeclTypeForMangling(
20452045
if (!decl->hasInterfaceType() || decl->getInterfaceType()->is<ErrorType>()) {
20462046
if (isa<AbstractFunctionDecl>(decl))
20472047
return CanFunctionType::get({AnyFunctionType::Param(C.TheErrorType)},
2048-
C.TheErrorType, AnyFunctionType::ExtInfo());
2048+
C.TheErrorType);
20492049
return C.TheErrorType;
20502050
}
20512051

lib/AST/Decl.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4975,11 +4975,9 @@ void SubscriptDecl::computeType() {
49754975

49764976
Type funcTy;
49774977
if (auto *sig = getGenericSignature())
4978-
funcTy = GenericFunctionType::get(sig, argTy, elementTy,
4979-
AnyFunctionType::ExtInfo());
4978+
funcTy = GenericFunctionType::get(sig, argTy, elementTy);
49804979
else
4981-
funcTy = FunctionType::get(argTy, elementTy,
4982-
AnyFunctionType::ExtInfo());
4980+
funcTy = FunctionType::get(argTy, elementTy);
49834981

49844982
// Record the interface type.
49854983
setInterfaceType(funcTy);
@@ -5742,16 +5740,13 @@ void EnumElementDecl::computeType() {
57425740
SmallVector<AnyFunctionType::Param, 4> argTy;
57435741
PL->getParams(argTy);
57445742

5745-
resultTy = FunctionType::get(argTy, resultTy,
5746-
AnyFunctionType::ExtInfo());
5743+
resultTy = FunctionType::get(argTy, resultTy);
57475744
}
57485745

57495746
if (auto *genericSig = ED->getGenericSignature())
5750-
resultTy = GenericFunctionType::get(genericSig, selfTy, resultTy,
5751-
AnyFunctionType::ExtInfo());
5747+
resultTy = GenericFunctionType::get(genericSig, selfTy, resultTy);
57525748
else
5753-
resultTy = FunctionType::get(selfTy, resultTy,
5754-
AnyFunctionType::ExtInfo());
5749+
resultTy = FunctionType::get(selfTy, resultTy);
57555750

57565751
// Record the interface type.
57575752
setInterfaceType(resultTy);

lib/AST/Type.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,10 @@ Type TypeBase::addCurriedSelfType(const DeclContext *dc) {
434434
}
435435

436436
auto selfTy = dc->getDeclaredInterfaceType();
437-
auto selfParam = AnyFunctionType::Param(selfTy,
438-
Identifier(), ParameterTypeFlags());
437+
auto selfParam = AnyFunctionType::Param(selfTy);
439438
if (sig)
440-
return GenericFunctionType::get(sig, {selfParam}, type,
441-
AnyFunctionType::ExtInfo());
442-
return FunctionType::get({selfParam}, type, AnyFunctionType::ExtInfo());
439+
return GenericFunctionType::get(sig, {selfParam}, type);
440+
return FunctionType::get({selfParam}, type);
443441
}
444442

445443
void

lib/IDE/TypeReconstruction.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,7 @@ static void VisitNodeAddressor(
712712
// level
713713
CanFunctionType swift_can_func_type =
714714
CanFunctionType::get(AnyFunctionType::CanParamArrayRef(),
715-
ast->TheRawPointerType,
716-
AnyFunctionType::ExtInfo());
715+
ast->TheRawPointerType);
717716
result._types.push_back(swift_can_func_type.getPointer());
718717
}
719718

lib/SILGen/SILGenApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
14091409
.getOptionalObjectType());
14101410
substFormalType = CanFunctionType::get(
14111411
dynamicMemberRef->getBase()->getType()->getCanonicalType(),
1412-
substFormalType, AnyFunctionType::ExtInfo());
1412+
substFormalType);
14131413

14141414
setCallee(Callee::forDynamic(SGF, member,
14151415
memberRef.getSubstitutions(),

lib/Sema/CodeSynthesis.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,8 +1472,7 @@ void TypeChecker::completePropertyBehaviorParameter(VarDecl *VD,
14721472
genericEnv = DC->getGenericEnvironmentOfContext();
14731473
SubstInterfaceTy = GenericFunctionType::get(genericSig,
14741474
DC->getSelfInterfaceType(),
1475-
SubstInterfaceTy,
1476-
AnyFunctionType::ExtInfo());
1475+
SubstInterfaceTy);
14771476
} else {
14781477
SubstInterfaceTy = FunctionType::get(DC->getSelfInterfaceType(),
14791478
SubstInterfaceTy);

lib/Sema/ConstraintSystem.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,8 +1320,7 @@ ConstraintSystem::getTypeOfMemberReference(
13201320
}
13211321

13221322
auto indicesTy = subscript->getIndicesInterfaceType();
1323-
refType = FunctionType::get(indicesTy, elementTy,
1324-
AnyFunctionType::ExtInfo());
1323+
refType = FunctionType::get(indicesTy, elementTy);
13251324
} else {
13261325
refType = getUnopenedTypeOfReference(cast<VarDecl>(value), baseTy, useDC,
13271326
base, /*wantInterfaceType=*/true);
@@ -1340,11 +1339,9 @@ ConstraintSystem::getTypeOfMemberReference(
13401339
// If the storage is generic, add a generic signature.
13411340
auto selfParam = AnyFunctionType::Param(selfTy, Identifier(), selfFlags);
13421341
if (auto *sig = innerDC->getGenericSignatureOfContext()) {
1343-
funcType = GenericFunctionType::get(sig, {selfParam}, refType,
1344-
AnyFunctionType::ExtInfo());
1342+
funcType = GenericFunctionType::get(sig, {selfParam}, refType);
13451343
} else {
1346-
funcType = FunctionType::get({selfParam}, refType,
1347-
AnyFunctionType::ExtInfo());
1344+
funcType = FunctionType::get({selfParam}, refType);
13481345
}
13491346
}
13501347

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ Type swift::getMemberTypeForComparison(ASTContext &ctx, ValueDecl *member,
108108
// For subscripts, we don't have a 'Self' type, but turn it
109109
// into a monomorphic function type.
110110
auto funcTy = memberType->castTo<AnyFunctionType>();
111-
memberType = FunctionType::get(funcTy->getParams(), funcTy->getResult(),
112-
FunctionType::ExtInfo());
111+
memberType = FunctionType::get(funcTy->getParams(), funcTy->getResult());
113112
} else {
114113
// For properties, strip off ownership.
115114
memberType = memberType->getReferenceStorageReferent();

0 commit comments

Comments
 (0)