Skip to content

Commit 8c94b38

Browse files
authored
Merge pull request #19560 from slavapestov/remove-functype-getinput
Remove FunctionType::getInput()
2 parents 66b1830 + 3b60ae1 commit 8c94b38

32 files changed

+277
-254
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5954,9 +5954,6 @@ class ConstructorDecl : public AbstractFunctionDecl {
59545954
SourceLoc getStartLoc() const { return getConstructorLoc(); }
59555955
SourceRange getSourceRange() const;
59565956

5957-
/// getArgumentInterfaceType - get the interface type of the argument tuple
5958-
Type getArgumentInterfaceType() const;
5959-
59605957
/// \brief Get the interface type of the constructed object.
59615958
Type getResultInterfaceType() const;
59625959

include/swift/AST/TypeMatcher.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,14 @@ class TypeMatcher {
217217
if (firstElt.getLabel() != secondElt.getLabel() ||
218218
firstElt.isVariadic() != secondElt.isVariadic() ||
219219
firstElt.isInOut() != secondElt.isInOut())
220-
return mismatch(firstElt.getType().getPointer(),
221-
secondElt.getType(),
222-
sugaredFirstFunc->getParams()[i].getType());
220+
return mismatch(firstElt.getOldType().getPointer(),
221+
secondElt.getOldType(),
222+
sugaredFirstFunc->getParams()[i].getOldType());
223223

224224
// Recurse on parameter components.
225-
if (!this->visit(firstElt.getType()->getCanonicalType(),
226-
secondElt.getType(),
227-
sugaredFirstFunc->getParams()[i].getType()))
225+
if (!this->visit(firstElt.getOldType()->getCanonicalType(),
226+
secondElt.getOldType(),
227+
sugaredFirstFunc->getParams()[i].getOldType()))
228228
return false;
229229
}
230230

include/swift/AST/Types.h

Lines changed: 36 additions & 40 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:
@@ -2651,13 +2647,21 @@ class AnyFunctionType : public TypeBase {
26512647
ParameterTypeFlags Flags = {};
26522648

26532649
public:
2654-
/// FIXME(Remove InOutType): This is mostly for copying between param
2655-
/// types and should go away.
2656-
Type getType() const;
2650+
/// FIXME: Remove this. Return the formal type of the parameter in the
2651+
/// function type, including the InOutType if there is one.
2652+
///
2653+
/// For example, 'inout Int' => 'inout Int', 'Int...' => 'Int'.
2654+
Type getOldType() const;
26572655

2656+
/// Return the formal type of the parameter.
2657+
///
2658+
/// For example, 'inout Int' => 'Int', 'Int...' => 'Int'.
26582659
Type getPlainType() const { return Ty; }
26592660

2660-
/// The type of the parameter. Adjusts for varargs, but not inout.
2661+
/// The type of the parameter when referenced inside the function body
2662+
/// as an rvalue.
2663+
///
2664+
/// For example, 'inout Int' => 'Int', 'Int...' => '[Int]'.
26612665
Type getParameterType(bool forCanonical = false,
26622666
ASTContext *ctx = nullptr) const;
26632667

@@ -2703,7 +2707,7 @@ class AnyFunctionType : public TypeBase {
27032707
public:
27042708
static CanParam getFromParam(const Param &param) { return CanParam(param); }
27052709

2706-
CanType getType() const { return CanType(Param::getType()); }
2710+
CanType getOldType() const { return CanType(Param::getOldType()); }
27072711
CanType getPlainType() const { return CanType(Param::getPlainType()); }
27082712
CanType getParameterType() const {
27092713
return CanType(Param::getParameterType(/*forCanonical*/ true));
@@ -2911,9 +2915,9 @@ class AnyFunctionType : public TypeBase {
29112915

29122916
protected:
29132917
AnyFunctionType(TypeKind Kind, const ASTContext *CanTypeContext,
2914-
Type Input, Type Output, RecursiveTypeProperties properties,
2918+
Type Output, RecursiveTypeProperties properties,
29152919
unsigned NumParams, ExtInfo Info)
2916-
: TypeBase(Kind, CanTypeContext, properties), Input(Input), Output(Output) {
2920+
: TypeBase(Kind, CanTypeContext, properties), Output(Output) {
29172921
Bits.AnyFunctionType.ExtInfo = Info.Bits;
29182922
Bits.AnyFunctionType.NumParams = NumParams;
29192923
assert(Bits.AnyFunctionType.NumParams == NumParams && "Params dropped!");
@@ -2950,7 +2954,6 @@ class AnyFunctionType : public TypeBase {
29502954
static void relabelParams(MutableArrayRef<Param> params,
29512955
ArrayRef<Identifier> labels);
29522956

2953-
Type getInput() const { return Input; }
29542957
Type getResult() const { return Output; }
29552958
ArrayRef<Param> getParams() const;
29562959
unsigned getNumParams() const { return Bits.AnyFunctionType.NumParams; }
@@ -2982,10 +2985,6 @@ class AnyFunctionType : public TypeBase {
29822985
return getExtInfo().throws();
29832986
}
29842987

2985-
/// Determine whether the given function input type is one of the
2986-
/// canonical forms.
2987-
static bool isCanonicalFunctionInputType(Type input);
2988-
29892988
/// Returns a new function type exactly like this one but with the ExtInfo
29902989
/// replaced.
29912990
AnyFunctionType *withExtInfo(ExtInfo info) const;
@@ -3011,10 +3010,6 @@ BEGIN_CAN_TYPE_WRAPPER(AnyFunctionType, Type)
30113010

30123011
CanGenericSignature getOptGenericSignature() const;
30133012

3014-
CanType getInput() const {
3015-
return getPointer()->getInput()->getCanonicalType();
3016-
}
3017-
30183013
CanParamArrayRef getParams() const {
30193014
return CanParamArrayRef(getPointer()->getParams());
30203015
}
@@ -3035,37 +3030,41 @@ inline AnyFunctionType::CanYield AnyFunctionType::Yield::getCanonical() const {
30353030
/// For example:
30363031
/// let x : (Float, Int) -> Int
30373032
class FunctionType final : public AnyFunctionType,
3033+
public llvm::FoldingSetNode,
30383034
private llvm::TrailingObjects<FunctionType, AnyFunctionType::Param> {
30393035
friend TrailingObjects;
30403036

30413037
public:
30423038
/// 'Constructor' Factory Function
3043-
static FunctionType *get(ArrayRef<Param> params,
3044-
Type result,
3045-
ExtInfo info = ExtInfo(),
3046-
bool canonicalVararg = false);
3039+
static FunctionType *get(ArrayRef<Param> params, Type result,
3040+
ExtInfo info = ExtInfo());
30473041

30483042
// Retrieve the input parameters of this function type.
30493043
ArrayRef<Param> getParams() const {
30503044
return {getTrailingObjects<Param>(), getNumParams()};
30513045
}
3052-
3046+
3047+
void Profile(llvm::FoldingSetNodeID &ID) {
3048+
Profile(ID, getParams(), getResult(), getExtInfo());
3049+
}
3050+
static void Profile(llvm::FoldingSetNodeID &ID,
3051+
ArrayRef<Param> params,
3052+
Type result,
3053+
ExtInfo info);
3054+
30533055
// Implement isa/cast/dyncast/etc.
30543056
static bool classof(const TypeBase *T) {
30553057
return T->getKind() == TypeKind::Function;
30563058
}
30573059

30583060
private:
3059-
FunctionType(ArrayRef<Param> params,
3060-
Type Input, Type Result,
3061-
RecursiveTypeProperties properties,
3062-
ExtInfo Info);
3061+
FunctionType(ArrayRef<Param> params, Type result, ExtInfo info,
3062+
const ASTContext *ctx, RecursiveTypeProperties properties);
30633063
};
30643064
BEGIN_CAN_TYPE_WRAPPER(FunctionType, AnyFunctionType)
30653065
static CanFunctionType get(CanParamArrayRef params, CanType result,
30663066
ExtInfo info = ExtInfo()) {
3067-
auto fnType = FunctionType::get(params.getOriginalArray(),
3068-
result, info, /*canonicalVararg=*/true);
3067+
auto fnType = FunctionType::get(params.getOriginalArray(), result, info);
30693068
return cast<FunctionType>(fnType->getCanonicalType());
30703069
}
30713070

@@ -3102,7 +3101,6 @@ class GenericFunctionType final : public AnyFunctionType,
31023101
/// Construct a new generic function type.
31033102
GenericFunctionType(GenericSignature *sig,
31043103
ArrayRef<Param> params,
3105-
Type input,
31063104
Type result,
31073105
ExtInfo info,
31083106
const ASTContext *ctx,
@@ -3113,8 +3111,7 @@ class GenericFunctionType final : public AnyFunctionType,
31133111
static GenericFunctionType *get(GenericSignature *sig,
31143112
ArrayRef<Param> params,
31153113
Type result,
3116-
ExtInfo info = ExtInfo(),
3117-
bool canonicalVararg = false);
3114+
ExtInfo info = ExtInfo());
31183115

31193116
// Retrieve the input parameters of this function type.
31203117
ArrayRef<Param> getParams() const {
@@ -3137,12 +3134,12 @@ class GenericFunctionType final : public AnyFunctionType,
31373134
FunctionType *substGenericArgs(SubstitutionMap subs);
31383135

31393136
void Profile(llvm::FoldingSetNodeID &ID) {
3140-
Profile(ID, getGenericSignature(), getInput(), getResult(),
3137+
Profile(ID, getGenericSignature(), getParams(), getResult(),
31413138
getExtInfo());
31423139
}
31433140
static void Profile(llvm::FoldingSetNodeID &ID,
31443141
GenericSignature *sig,
3145-
Type input,
3142+
ArrayRef<Param> params,
31463143
Type result,
31473144
ExtInfo info);
31483145

@@ -3161,8 +3158,7 @@ BEGIN_CAN_TYPE_WRAPPER(GenericFunctionType, AnyFunctionType)
31613158
// Knowing that the argument types are independently canonical is
31623159
// not sufficient to guarantee that the function type will be canonical.
31633160
auto fnType = GenericFunctionType::get(sig, params.getOriginalArray(),
3164-
result, info,
3165-
/*canonicalVararg=*/true);
3161+
result, info);
31663162
return cast<GenericFunctionType>(fnType->getCanonicalType());
31673163
}
31683164

0 commit comments

Comments
 (0)