Skip to content

Commit 527ff37

Browse files
committed
AST: Rename old form of {Generic,}FunctionType::get() to getOld()
This makes it easier to grep for and eventually remove the remaining usages. It also allows you to write FunctionType::get({}, ...) to call the ArrayRef overload empty parameter list, instead of picking the Type overload and calling it with an empty Type() value. While I"m at it, in a few places instead of renaming just clean up usages where it was completely mechanical to do so.
1 parent a542510 commit 527ff37

28 files changed

+237
-225
lines changed

include/swift/AST/Types.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2979,9 +2979,9 @@ BEGIN_CAN_TYPE_WRAPPER(AnyFunctionType, Type)
29792979
using ExtInfo = AnyFunctionType::ExtInfo;
29802980
using CanParamArrayRef = AnyFunctionType::CanParamArrayRef;
29812981

2982-
static CanAnyFunctionType get(CanGenericSignature signature,
2983-
CanType input, CanType result,
2984-
ExtInfo extInfo = ExtInfo());
2982+
static CanAnyFunctionType getOld(CanGenericSignature signature,
2983+
CanType input, CanType result,
2984+
ExtInfo extInfo = ExtInfo());
29852985
static CanAnyFunctionType get(CanGenericSignature signature,
29862986
CanParamArrayRef params,
29872987
CanType result,
@@ -3018,8 +3018,8 @@ class FunctionType final : public AnyFunctionType,
30183018

30193019
public:
30203020
/// 'Constructor' Factory Function
3021-
static FunctionType *get(Type Input, Type Result,
3022-
ExtInfo Info = ExtInfo());
3021+
static FunctionType *getOld(Type Input, Type Result,
3022+
ExtInfo Info = ExtInfo());
30233023

30243024
static FunctionType *get(ArrayRef<Param> params,
30253025
Type result,
@@ -3043,9 +3043,9 @@ class FunctionType final : public AnyFunctionType,
30433043
ExtInfo Info);
30443044
};
30453045
BEGIN_CAN_TYPE_WRAPPER(FunctionType, AnyFunctionType)
3046-
static CanFunctionType get(CanType input, CanType result,
3047-
ExtInfo info = ExtInfo()) {
3048-
auto fnType = FunctionType::get(input, result, info);
3046+
static CanFunctionType getOld(CanType input, CanType result,
3047+
ExtInfo info = ExtInfo()) {
3048+
auto fnType = FunctionType::getOld(input, result, info);
30493049
return cast<FunctionType>(fnType->getCanonicalType());
30503050
}
30513051
static CanFunctionType get(CanParamArrayRef params, CanType result,
@@ -3103,10 +3103,10 @@ class GenericFunctionType final : public AnyFunctionType,
31033103

31043104
public:
31053105
/// Create a new generic function type.
3106-
static GenericFunctionType *get(GenericSignature *sig,
3107-
Type input,
3108-
Type result,
3109-
ExtInfo info = ExtInfo());
3106+
static GenericFunctionType *getOld(GenericSignature *sig,
3107+
Type input,
3108+
Type result,
3109+
ExtInfo info = ExtInfo());
31103110

31113111
/// Create a new generic function type.
31123112
static GenericFunctionType *get(GenericSignature *sig,
@@ -3152,12 +3152,12 @@ class GenericFunctionType final : public AnyFunctionType,
31523152
};
31533153

31543154
BEGIN_CAN_TYPE_WRAPPER(GenericFunctionType, AnyFunctionType)
3155-
static CanGenericFunctionType get(CanGenericSignature sig,
3156-
CanType input, CanType result,
3157-
ExtInfo info = ExtInfo()) {
3155+
static CanGenericFunctionType getOld(CanGenericSignature sig,
3156+
CanType input, CanType result,
3157+
ExtInfo info = ExtInfo()) {
31583158
// Knowing that the argument types are independently canonical is
31593159
// not sufficient to guarantee that the function type will be canonical.
3160-
auto fnType = GenericFunctionType::get(sig, input, result, info);
3160+
auto fnType = GenericFunctionType::getOld(sig, input, result, info);
31613161
return cast<GenericFunctionType>(fnType->getCanonicalType());
31623162
}
31633163

@@ -3189,12 +3189,12 @@ BEGIN_CAN_TYPE_WRAPPER(GenericFunctionType, AnyFunctionType)
31893189
END_CAN_TYPE_WRAPPER(GenericFunctionType, AnyFunctionType)
31903190

31913191
inline CanAnyFunctionType
3192-
CanAnyFunctionType::get(CanGenericSignature signature,
3193-
CanType input, CanType result, ExtInfo extInfo) {
3192+
CanAnyFunctionType::getOld(CanGenericSignature signature,
3193+
CanType input, CanType result, ExtInfo extInfo) {
31943194
if (signature) {
3195-
return CanGenericFunctionType::get(signature, input, result, extInfo);
3195+
return CanGenericFunctionType::getOld(signature, input, result, extInfo);
31963196
} else {
3197-
return CanFunctionType::get(input, result, extInfo);
3197+
return CanFunctionType::getOld(input, result, extInfo);
31983198
}
31993199
}
32003200

lib/AST/ASTContext.cpp

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3052,14 +3052,12 @@ AnyFunctionType::Param swift::computeSelfParam(AbstractFunctionDecl *AFD,
30523052
// Determine the type of the container.
30533053
auto containerTy = dc->getDeclaredInterfaceType();
30543054
if (!containerTy || containerTy->hasError())
3055-
return AnyFunctionType::Param(ErrorType::get(Ctx), Identifier(),
3056-
ParameterTypeFlags());
3055+
return AnyFunctionType::Param(ErrorType::get(Ctx));
30573056

30583057
// Determine the type of 'self' inside the container.
30593058
auto selfTy = dc->getSelfInterfaceType();
30603059
if (!selfTy || selfTy->hasError())
3061-
return AnyFunctionType::Param(ErrorType::get(Ctx), Identifier(),
3062-
ParameterTypeFlags());
3060+
return AnyFunctionType::Param(ErrorType::get(Ctx));
30633061

30643062
bool isStatic = false;
30653063
bool isMutating = false;
@@ -3101,13 +3099,11 @@ AnyFunctionType::Param swift::computeSelfParam(AbstractFunctionDecl *AFD,
31013099

31023100
// 'static' functions have 'self' of type metatype<T>.
31033101
if (isStatic)
3104-
return AnyFunctionType::Param(MetatypeType::get(selfTy, Ctx), Identifier(),
3105-
ParameterTypeFlags());
3102+
return AnyFunctionType::Param(MetatypeType::get(selfTy, Ctx));
31063103

31073104
// Reference types have 'self' of type T.
31083105
if (containerTy->hasReferenceSemantics())
3109-
return AnyFunctionType::Param(selfTy, Identifier(),
3110-
ParameterTypeFlags());
3106+
return AnyFunctionType::Param(selfTy);
31113107

31123108
return AnyFunctionType::Param(selfTy, Identifier(),
31133109
ParameterTypeFlags().withInOut(isMutating));
@@ -3524,10 +3520,10 @@ getGenericFunctionRecursiveProperties(Type Input, Type Result) {
35243520

35253521
AnyFunctionType *AnyFunctionType::withExtInfo(ExtInfo info) const {
35263522
if (isa<FunctionType>(this))
3527-
return FunctionType::get(getInput(), getResult(), info);
3523+
return FunctionType::getOld(getInput(), getResult(), info);
35283524
if (auto *genFnTy = dyn_cast<GenericFunctionType>(this))
3529-
return GenericFunctionType::get(genFnTy->getGenericSignature(),
3530-
getInput(), getResult(), info);
3525+
return GenericFunctionType::getOld(genFnTy->getGenericSignature(),
3526+
getInput(), getResult(), info);
35313527

35323528
static_assert(2 - 1 ==
35333529
static_cast<int>(TypeKind::Last_AnyFunctionType) -
@@ -3614,12 +3610,12 @@ bool AnyFunctionType::equalParams(CanParamArrayRef a, CanParamArrayRef b) {
36143610
FunctionType *FunctionType::get(ArrayRef<AnyFunctionType::Param> params,
36153611
Type result, ExtInfo info,
36163612
bool canonicalVararg) {
3617-
return get(composeInput(result->getASTContext(), params, canonicalVararg),
3618-
result, info);
3613+
return getOld(composeInput(result->getASTContext(), params, canonicalVararg),
3614+
result, info);
36193615
}
36203616

3621-
FunctionType *FunctionType::get(Type input, Type result,
3622-
ExtInfo info) {
3617+
FunctionType *FunctionType::getOld(Type input, Type result,
3618+
ExtInfo info) {
36233619
auto properties = getFunctionRecursiveProperties(input, result);
36243620
auto arena = getArena(properties);
36253621
uint16_t attrKey = info.getFuncAttrKey();
@@ -3679,16 +3675,16 @@ GenericFunctionType *GenericFunctionType::get(GenericSignature *sig,
36793675
Type result,
36803676
ExtInfo info,
36813677
bool canonicalVararg) {
3682-
return get(sig, composeInput(result->getASTContext(), params,
3683-
canonicalVararg),
3684-
result, info);
3678+
return getOld(sig, composeInput(result->getASTContext(), params,
3679+
canonicalVararg),
3680+
result, info);
36853681
}
36863682

36873683
GenericFunctionType *
3688-
GenericFunctionType::get(GenericSignature *sig,
3689-
Type input,
3690-
Type output,
3691-
ExtInfo info) {
3684+
GenericFunctionType::getOld(GenericSignature *sig,
3685+
Type input,
3686+
Type output,
3687+
ExtInfo info) {
36923688
assert(sig && "no generic signature for generic function type?!");
36933689
assert(!input->hasTypeVariable() && !output->hasTypeVariable());
36943690

lib/AST/ASTMangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2055,7 +2055,7 @@ CanType ASTMangler::getDeclTypeForMangling(
20552055
genericSig = gft.getGenericSignature();
20562056
CurGenericSignature = gft.getGenericSignature();
20572057

2058-
type = CanFunctionType::get(gft->getParams(), gft.getResult(),
2058+
type = CanFunctionType::get(gft.getParams(), gft.getResult(),
20592059
gft->getExtInfo());
20602060
}
20612061

lib/AST/Builtins.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,11 +1109,11 @@ static ValueDecl *getOnceOperation(ASTContext &Context,
11091109
/*throws*/ false);
11101110
if (withContext) {
11111111
auto ContextTy = Context.TheRawPointerType;
1112-
auto ContextArg = ParenType::get(Context, ContextTy);
1113-
auto BlockTy = FunctionType::get(ContextArg, VoidTy, Thin);
1112+
auto ContextArg = FunctionType::Param(ContextTy);
1113+
auto BlockTy = FunctionType::get({ContextArg}, VoidTy, Thin);
11141114
return getBuiltinFunction(Id, {HandleTy, BlockTy, ContextTy}, VoidTy);
11151115
} else {
1116-
auto BlockTy = FunctionType::get(VoidTy, VoidTy, Thin);
1116+
auto BlockTy = FunctionType::get({}, VoidTy, Thin);
11171117
return getBuiltinFunction(Id, {HandleTy, BlockTy}, VoidTy);
11181118
}
11191119
}

lib/AST/Decl.cpp

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5416,34 +5416,30 @@ void AbstractFunctionDecl::computeType(AnyFunctionType::ExtInfo info) {
54165416
}
54175417
}
54185418

5419-
Type initFuncTy;
5420-
54215419
// (Self) -> (Args...) -> Result
54225420
if (hasSelf) {
5423-
SmallVector<AnyFunctionType::Param, 1> argTy;
5424-
SmallVector<AnyFunctionType::Param, 1> initArgTy;
5421+
// Constructors have an initializer type that takes an instance
5422+
// instead of a metatype.
5423+
if (auto *ctor = dyn_cast<ConstructorDecl>(this)) {
5424+
auto initSelfParam = computeSelfParam(this, /*isInitializingCtor=*/true);
5425+
Type initFuncTy;
5426+
if (sig)
5427+
initFuncTy = GenericFunctionType::get(sig, {initSelfParam}, funcTy);
5428+
else
5429+
initFuncTy = FunctionType::get({initSelfParam}, funcTy);
5430+
ctor->setInitializerInterfaceType(initFuncTy);
5431+
}
54255432

54265433
// Substitute in our own 'self' parameter.
5427-
argTy.push_back(computeSelfParam(this));
5428-
if (isa<ConstructorDecl>(this))
5429-
initArgTy.push_back(computeSelfParam(this, /*isInitializingCtor=*/true));
5430-
5431-
AnyFunctionType::ExtInfo info;
5432-
if (sig) {
5433-
if (isa<ConstructorDecl>(this))
5434-
initFuncTy = GenericFunctionType::get(sig, initArgTy, funcTy, info);
5435-
funcTy = GenericFunctionType::get(sig, argTy, funcTy, info);
5436-
} else {
5437-
if (isa<ConstructorDecl>(this))
5438-
initFuncTy = FunctionType::get(initArgTy, funcTy, info);
5439-
funcTy = FunctionType::get(argTy, funcTy, info);
5440-
}
5434+
auto selfParam = computeSelfParam(this);
5435+
if (sig)
5436+
funcTy = GenericFunctionType::get(sig, {selfParam}, funcTy);
5437+
else
5438+
funcTy = FunctionType::get({selfParam}, funcTy);
54415439
}
54425440

54435441
// Record the interface type.
54445442
setInterfaceType(funcTy);
5445-
if (auto *ctor = dyn_cast<ConstructorDecl>(this))
5446-
ctor->setInitializerInterfaceType(initFuncTy);
54475443
}
54485444

54495445
FuncDecl *FuncDecl::createImpl(ASTContext &Context,
@@ -5731,10 +5727,7 @@ void EnumElementDecl::computeType() {
57315727
// or (Self.Type) -> (Args...) -> Self.
57325728
auto resultTy = ED->getDeclaredInterfaceType();
57335729

5734-
SmallVector<AnyFunctionType::Param, 1> selfTy;
5735-
selfTy.emplace_back(MetatypeType::get(resultTy, ctx),
5736-
Identifier(),
5737-
ParameterTypeFlags());
5730+
AnyFunctionType::Param selfTy(MetatypeType::get(resultTy, ctx));
57385731

57395732
if (auto *PL = getParameterList()) {
57405733
SmallVector<AnyFunctionType::Param, 4> argTy;
@@ -5744,9 +5737,9 @@ void EnumElementDecl::computeType() {
57445737
}
57455738

57465739
if (auto *genericSig = ED->getGenericSignature())
5747-
resultTy = GenericFunctionType::get(genericSig, selfTy, resultTy);
5740+
resultTy = GenericFunctionType::get(genericSig, {selfTy}, resultTy);
57485741
else
5749-
resultTy = FunctionType::get(selfTy, resultTy);
5742+
resultTy = FunctionType::get({selfTy}, resultTy);
57505743

57515744
// Record the interface type.
57525745
setInterfaceType(resultTy);

lib/AST/LookupVisibleDecls.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ class RestateFilteringConsumer : public VisibleDeclConsumer {
519519
}
520520
auto newSig = GenericSignature::get(params, newReqs, false);
521521

522-
return GenericFunctionType::get(newSig, GFT->getInput(),
522+
return GenericFunctionType::get(newSig, GFT->getParams(),
523523
GFT->getResult(), GFT->getExtInfo())
524524
->getCanonicalType();
525525
}

lib/AST/Type.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,8 +1202,8 @@ CanType TypeBase::computeCanonicalType() {
12021202
return type->getCanonicalType(sig);
12031203
});
12041204
auto resultTy = function->getResult()->getCanonicalType(sig);
1205-
Result = GenericFunctionType::get(sig, inputTy, resultTy,
1206-
function->getExtInfo());
1205+
Result = GenericFunctionType::getOld(sig, inputTy, resultTy,
1206+
function->getExtInfo());
12071207
assert(Result->isCanonical());
12081208
break;
12091209
}
@@ -1219,7 +1219,7 @@ CanType TypeBase::computeCanonicalType() {
12191219
auto In = getCanonicalInputType(
12201220
FT, [](Type type) -> CanType { return type->getCanonicalType(); });
12211221
Type Out = FT->getResult()->getCanonicalType();
1222-
Result = FunctionType::get(In, Out, FT->getExtInfo());
1222+
Result = FunctionType::getOld(In, Out, FT->getExtInfo());
12231223
break;
12241224
}
12251225
case TypeKind::ProtocolComposition: {
@@ -3808,14 +3808,14 @@ case TypeKind::Id:
38083808
if (isUnchanged) return *this;
38093809

38103810
auto genericSig = genericFnType->getGenericSignature();
3811-
return GenericFunctionType::get(genericSig, inputTy, resultTy,
3812-
function->getExtInfo());
3811+
return GenericFunctionType::getOld(genericSig, inputTy, resultTy,
3812+
function->getExtInfo());
38133813
}
38143814

38153815
if (isUnchanged) return *this;
38163816

3817-
return FunctionType::get(inputTy, resultTy,
3818-
function->getExtInfo());
3817+
return FunctionType::getOld(inputTy, resultTy,
3818+
function->getExtInfo());
38193819
}
38203820

38213821
case TypeKind::ArraySlice: {

lib/ClangImporter/ImportDecl.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@ makeEnumRawValueConstructor(ClangImporter::Implementation &Impl,
464464
ConcreteDeclRef concreteDeclRef(reinterpretCast, subMap);
465465
auto reinterpretCastRef
466466
= new (C) DeclRefExpr(concreteDeclRef, DeclNameLoc(), /*implicit*/ true);
467-
reinterpretCastRef->setType(FunctionType::get({rawTy}, enumTy));
467+
reinterpretCastRef->setType(FunctionType::get({FunctionType::Param(rawTy)},
468+
enumTy));
468469

469470
auto reinterpreted = CallExpr::createImplicit(C, reinterpretCastRef,
470471
{ paramRef }, { Identifier() });
@@ -549,7 +550,8 @@ static AccessorDecl *makeEnumRawValueGetter(ClangImporter::Implementation &Impl,
549550

550551
auto reinterpretCastRef
551552
= new (C) DeclRefExpr(concreteDeclRef, DeclNameLoc(), /*implicit*/ true);
552-
reinterpretCastRef->setType(FunctionType::get({enumTy}, rawTy));
553+
reinterpretCastRef->setType(FunctionType::get({FunctionType::Param(enumTy)},
554+
rawTy));
553555

554556
auto reinterpreted = CallExpr::createImplicit(C, reinterpretCastRef,
555557
{ selfRef }, { Identifier() });
@@ -1175,7 +1177,7 @@ createDefaultConstructor(ClangImporter::Implementation &Impl,
11751177
auto zeroInitializerRef =
11761178
new (context) DeclRefExpr(concreteDeclRef, DeclNameLoc(),
11771179
/*implicit*/ true);
1178-
zeroInitializerRef->setType(FunctionType::get(emptyTuple, selfType));
1180+
zeroInitializerRef->setType(FunctionType::get({}, selfType));
11791181

11801182
auto call = CallExpr::createImplicit(context, zeroInitializerRef, {}, {});
11811183
call->setType(selfType);

lib/ClangImporter/ImportType.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ namespace {
523523
if (!resultTy)
524524
return Type();
525525

526-
SmallVector<TupleTypeElt, 4> params;
526+
SmallVector<FunctionType::Param, 4> params;
527527
for (auto param = type->param_type_begin(),
528528
paramEnd = type->param_type_end();
529529
param != paramEnd; ++param) {
@@ -537,14 +537,11 @@ namespace {
537537
// names. The probably doesn't matter outside of a FuncDecl, which
538538
// we'll have to special-case, but it's an interesting bit of data loss.
539539
// We also lose `noescape`. <https://bugs.swift.org/browse/SR-2529>
540-
params.push_back(swiftParamTy);
540+
params.push_back(FunctionType::Param(swiftParamTy));
541541
}
542542

543-
// Form the parameter tuple.
544-
auto paramsTy = TupleType::get(params, Impl.SwiftContext);
545-
546543
// Form the function type.
547-
return FunctionType::get(paramsTy, resultTy);
544+
return FunctionType::get(params, resultTy);
548545
}
549546

550547
ImportResult
@@ -556,7 +553,7 @@ namespace {
556553
if (!resultTy)
557554
return Type();
558555

559-
return FunctionType::get(TupleType::getEmpty(Impl.SwiftContext),resultTy);
556+
return FunctionType::get({}, resultTy);
560557
}
561558

562559
ImportResult VisitParenType(const clang::ParenType *type) {

0 commit comments

Comments
 (0)