Skip to content

Commit 4975f3a

Browse files
committed
AST: Remove FunctionType::getInput()
1 parent 34fd5fa commit 4975f3a

File tree

4 files changed

+26
-57
lines changed

4 files changed

+26
-57
lines changed

include/swift/AST/Types.h

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,19 +2612,15 @@ getSILFunctionLanguage(SILFunctionTypeRepresentation rep) {
26122612
llvm_unreachable("Unhandled SILFunctionTypeRepresentation in switch.");
26132613
}
26142614

2615-
/// AnyFunctionType - A function type has a single input and result, but
2616-
/// these types may be tuples, for example:
2615+
/// AnyFunctionType - A function type has zero or more input parameters and a
2616+
/// single result. The result type may be a tuple. For example:
26172617
/// "(int) -> int" or "(a : int, b : int) -> (int, int)".
2618-
/// Note that the parser requires that the input to a function type be a Tuple
2619-
/// or ParenType, but ParenType desugars to its element, so the input to a
2620-
/// function may be an arbitrary type.
26212618
///
26222619
/// There are two kinds of function types: monomorphic (FunctionType) and
26232620
/// polymorphic (GenericFunctionType). Both type families additionally can
26242621
/// be 'thin', indicating that a function value has no capture context and can be
26252622
/// represented at the binary level as a single function pointer.
26262623
class AnyFunctionType : public TypeBase {
2627-
const Type Input;
26282624
const Type Output;
26292625

26302626
public:
@@ -2911,9 +2907,9 @@ class AnyFunctionType : public TypeBase {
29112907

29122908
protected:
29132909
AnyFunctionType(TypeKind Kind, const ASTContext *CanTypeContext,
2914-
Type Input, Type Output, RecursiveTypeProperties properties,
2910+
Type Output, RecursiveTypeProperties properties,
29152911
unsigned NumParams, ExtInfo Info)
2916-
: TypeBase(Kind, CanTypeContext, properties), Input(Input), Output(Output) {
2912+
: TypeBase(Kind, CanTypeContext, properties), Output(Output) {
29172913
Bits.AnyFunctionType.ExtInfo = Info.Bits;
29182914
Bits.AnyFunctionType.NumParams = NumParams;
29192915
assert(Bits.AnyFunctionType.NumParams == NumParams && "Params dropped!");
@@ -2950,7 +2946,6 @@ class AnyFunctionType : public TypeBase {
29502946
static void relabelParams(MutableArrayRef<Param> params,
29512947
ArrayRef<Identifier> labels);
29522948

2953-
Type getInput() const { return Input; }
29542949
Type getResult() const { return Output; }
29552950
ArrayRef<Param> getParams() const;
29562951
unsigned getNumParams() const { return Bits.AnyFunctionType.NumParams; }
@@ -3007,10 +3002,6 @@ BEGIN_CAN_TYPE_WRAPPER(AnyFunctionType, Type)
30073002

30083003
CanGenericSignature getOptGenericSignature() const;
30093004

3010-
CanType getInput() const {
3011-
return getPointer()->getInput()->getCanonicalType();
3012-
}
3013-
30143005
CanParamArrayRef getParams() const {
30153006
return CanParamArrayRef(getPointer()->getParams());
30163007
}
@@ -3037,10 +3028,8 @@ class FunctionType final : public AnyFunctionType,
30373028

30383029
public:
30393030
/// 'Constructor' Factory Function
3040-
static FunctionType *get(ArrayRef<Param> params,
3041-
Type result,
3042-
ExtInfo info = ExtInfo(),
3043-
bool canonicalVararg = false);
3031+
static FunctionType *get(ArrayRef<Param> params, Type result,
3032+
ExtInfo info = ExtInfo());
30443033

30453034
// Retrieve the input parameters of this function type.
30463035
ArrayRef<Param> getParams() const {
@@ -3061,17 +3050,13 @@ class FunctionType final : public AnyFunctionType,
30613050
}
30623051

30633052
private:
3064-
FunctionType(ArrayRef<Param> params,
3065-
Type input, Type result,
3066-
ExtInfo info,
3067-
const ASTContext *ctx,
3068-
RecursiveTypeProperties properties);
3053+
FunctionType(ArrayRef<Param> params, Type result, ExtInfo info,
3054+
const ASTContext *ctx, RecursiveTypeProperties properties);
30693055
};
30703056
BEGIN_CAN_TYPE_WRAPPER(FunctionType, AnyFunctionType)
30713057
static CanFunctionType get(CanParamArrayRef params, CanType result,
30723058
ExtInfo info = ExtInfo()) {
3073-
auto fnType = FunctionType::get(params.getOriginalArray(),
3074-
result, info, /*canonicalVararg=*/true);
3059+
auto fnType = FunctionType::get(params.getOriginalArray(), result, info);
30753060
return cast<FunctionType>(fnType->getCanonicalType());
30763061
}
30773062

@@ -3108,7 +3093,6 @@ class GenericFunctionType final : public AnyFunctionType,
31083093
/// Construct a new generic function type.
31093094
GenericFunctionType(GenericSignature *sig,
31103095
ArrayRef<Param> params,
3111-
Type input,
31123096
Type result,
31133097
ExtInfo info,
31143098
const ASTContext *ctx,
@@ -3119,8 +3103,7 @@ class GenericFunctionType final : public AnyFunctionType,
31193103
static GenericFunctionType *get(GenericSignature *sig,
31203104
ArrayRef<Param> params,
31213105
Type result,
3122-
ExtInfo info = ExtInfo(),
3123-
bool canonicalVararg = false);
3106+
ExtInfo info = ExtInfo());
31243107

31253108
// Retrieve the input parameters of this function type.
31263109
ArrayRef<Param> getParams() const {
@@ -3167,8 +3150,7 @@ BEGIN_CAN_TYPE_WRAPPER(GenericFunctionType, AnyFunctionType)
31673150
// Knowing that the argument types are independently canonical is
31683151
// not sufficient to guarantee that the function type will be canonical.
31693152
auto fnType = GenericFunctionType::get(sig, params.getOriginalArray(),
3170-
result, info,
3171-
/*canonicalVararg=*/true);
3153+
result, info);
31723154
return cast<GenericFunctionType>(fnType->getCanonicalType());
31733155
}
31743156

lib/AST/ASTContext.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3669,13 +3669,11 @@ isGenericFunctionTypeCanonical(GenericSignature *sig,
36693669

36703670
AnyFunctionType *AnyFunctionType::withExtInfo(ExtInfo info) const {
36713671
if (isa<FunctionType>(this))
3672-
return FunctionType::get(getParams(), getResult(), info,
3673-
/*canonicalVararg=*/isCanonical());
3672+
return FunctionType::get(getParams(), getResult(), info);
36743673

36753674
auto *genFnTy = cast<GenericFunctionType>(this);
36763675
return GenericFunctionType::get(genFnTy->getGenericSignature(),
3677-
getParams(), getResult(), info,
3678-
/*canonicalVararg=*/isCanonical());
3676+
getParams(), getResult(), info);
36793677
}
36803678

36813679
void AnyFunctionType::decomposeInput(
@@ -3792,9 +3790,7 @@ void FunctionType::Profile(llvm::FoldingSetNodeID &ID,
37923790
}
37933791

37943792
FunctionType *FunctionType::get(ArrayRef<AnyFunctionType::Param> params,
3795-
Type result, ExtInfo info,
3796-
bool canonicalVararg) {
3797-
auto input = composeInput(result->getASTContext(), params, canonicalVararg);
3793+
Type result, ExtInfo info) {
37983794
auto properties = getFunctionRecursiveProperties(params, result);
37993795
auto arena = getArena(properties);
38003796

@@ -3815,7 +3811,7 @@ FunctionType *FunctionType::get(ArrayRef<AnyFunctionType::Param> params,
38153811
alignof(FunctionType), arena);
38163812

38173813
bool isCanonical = isFunctionTypeCanonical(params, result);
3818-
auto funcTy = new (mem) FunctionType(params, input, result, info,
3814+
auto funcTy = new (mem) FunctionType(params, result, info,
38193815
isCanonical ? &ctx : nullptr,
38203816
properties);
38213817
ctx.getImpl().getArena(arena).FunctionTypes.InsertNode(funcTy, insertPos);
@@ -3824,12 +3820,11 @@ FunctionType *FunctionType::get(ArrayRef<AnyFunctionType::Param> params,
38243820

38253821
// If the input and result types are canonical, then so is the result.
38263822
FunctionType::FunctionType(ArrayRef<AnyFunctionType::Param> params,
3827-
Type input, Type output,
3828-
ExtInfo info,
3823+
Type output, ExtInfo info,
38293824
const ASTContext *ctx,
38303825
RecursiveTypeProperties properties)
38313826
: AnyFunctionType(TypeKind::Function, ctx,
3832-
input, output, properties, params.size(), info) {
3827+
output, properties, params.size(), info) {
38333828
std::uninitialized_copy(params.begin(), params.end(),
38343829
getTrailingObjects<AnyFunctionType::Param>());
38353830
}
@@ -3848,17 +3843,14 @@ void GenericFunctionType::Profile(llvm::FoldingSetNodeID &ID,
38483843
GenericFunctionType *GenericFunctionType::get(GenericSignature *sig,
38493844
ArrayRef<Param> params,
38503845
Type result,
3851-
ExtInfo info,
3852-
bool canonicalVararg) {
3846+
ExtInfo info) {
38533847
assert(sig && "no generic signature for generic function type?!");
3854-
3855-
auto input = composeInput(result->getASTContext(), params, canonicalVararg);
38563848
assert(!result->hasTypeVariable());
38573849

38583850
llvm::FoldingSetNodeID id;
38593851
GenericFunctionType::Profile(id, sig, params, result, info);
38603852

3861-
const ASTContext &ctx = input->getASTContext();
3853+
const ASTContext &ctx = result->getASTContext();
38623854

38633855
// Do we already have this generic function type?
38643856
void *insertPos;
@@ -3883,7 +3875,7 @@ GenericFunctionType *GenericFunctionType::get(GenericSignature *sig,
38833875
alignof(GenericFunctionType));
38843876

38853877
auto properties = getGenericFunctionRecursiveProperties(params, result);
3886-
auto funcTy = new (mem) GenericFunctionType(sig, params, input, result, info,
3878+
auto funcTy = new (mem) GenericFunctionType(sig, params, result, info,
38873879
isCanonical ? &ctx : nullptr,
38883880
properties);
38893881

@@ -3894,12 +3886,11 @@ GenericFunctionType *GenericFunctionType::get(GenericSignature *sig,
38943886
GenericFunctionType::GenericFunctionType(
38953887
GenericSignature *sig,
38963888
ArrayRef<AnyFunctionType::Param> params,
3897-
Type input,
38983889
Type result,
38993890
ExtInfo info,
39003891
const ASTContext *ctx,
39013892
RecursiveTypeProperties properties)
3902-
: AnyFunctionType(TypeKind::GenericFunction, ctx, input, result,
3893+
: AnyFunctionType(TypeKind::GenericFunction, ctx, result,
39033894
properties, params.size(), info), Signature(sig) {
39043895
std::uninitialized_copy(params.begin(), params.end(),
39053896
getTrailingObjects<AnyFunctionType::Param>());

lib/AST/Type.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,12 +1119,10 @@ CanType TypeBase::computeCanonicalType() {
11191119

11201120
if (genericSig) {
11211121
Result = GenericFunctionType::get(genericSig, canParams, resultTy,
1122-
funcTy->getExtInfo(),
1123-
/*canonicalVararg=*/true);
1122+
funcTy->getExtInfo());
11241123
} else {
11251124
Result = FunctionType::get(canParams, resultTy,
1126-
funcTy->getExtInfo(),
1127-
/*canonicalVararg=*/true);
1125+
funcTy->getExtInfo());
11281126
}
11291127
assert(Result->isCanonical());
11301128
break;
@@ -3740,15 +3738,13 @@ case TypeKind::Id:
37403738

37413739
auto genericSig = genericFnType->getGenericSignature();
37423740
return GenericFunctionType::get(genericSig, substParams, resultTy,
3743-
function->getExtInfo(),
3744-
/*canonicalVararg=*/function->isCanonical());
3741+
function->getExtInfo());
37453742
}
37463743

37473744
if (isUnchanged) return *this;
37483745

37493746
return FunctionType::get(substParams, resultTy,
3750-
function->getExtInfo(),
3751-
/*canonicalVararg=*/function->isCanonical());
3747+
function->getExtInfo());
37523748
}
37533749

37543750
case TypeKind::ArraySlice: {

lib/Sema/CSDiag.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6271,7 +6271,7 @@ bool FailureDiagnosis::diagnoseClosureExpr(
62716271
// Before doing so, strip attributes off the function type so that they
62726272
// don't confuse the issue.
62736273
fnType = FunctionType::get(fnType->getParams(), fnType->getResult(),
6274-
fnType->getExtInfo(), false);
6274+
fnType->getExtInfo());
62756275
auto diag = diagnose(
62766276
params->getStartLoc(), diag::closure_argument_list_tuple, fnType,
62776277
inferredArgCount, actualArgCount, (actualArgCount == 1));

0 commit comments

Comments
 (0)