Skip to content

Remove FunctionType::getInput() #19560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5954,9 +5954,6 @@ class ConstructorDecl : public AbstractFunctionDecl {
SourceLoc getStartLoc() const { return getConstructorLoc(); }
SourceRange getSourceRange() const;

/// getArgumentInterfaceType - get the interface type of the argument tuple
Type getArgumentInterfaceType() const;

/// \brief Get the interface type of the constructed object.
Type getResultInterfaceType() const;

Expand Down
12 changes: 6 additions & 6 deletions include/swift/AST/TypeMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ class TypeMatcher {
if (firstElt.getLabel() != secondElt.getLabel() ||
firstElt.isVariadic() != secondElt.isVariadic() ||
firstElt.isInOut() != secondElt.isInOut())
return mismatch(firstElt.getType().getPointer(),
secondElt.getType(),
sugaredFirstFunc->getParams()[i].getType());
return mismatch(firstElt.getOldType().getPointer(),
secondElt.getOldType(),
sugaredFirstFunc->getParams()[i].getOldType());

// Recurse on parameter components.
if (!this->visit(firstElt.getType()->getCanonicalType(),
secondElt.getType(),
sugaredFirstFunc->getParams()[i].getType()))
if (!this->visit(firstElt.getOldType()->getCanonicalType(),
secondElt.getOldType(),
sugaredFirstFunc->getParams()[i].getOldType()))
return false;
}

Expand Down
76 changes: 36 additions & 40 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2612,19 +2612,15 @@ getSILFunctionLanguage(SILFunctionTypeRepresentation rep) {
llvm_unreachable("Unhandled SILFunctionTypeRepresentation in switch.");
}

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

public:
Expand All @@ -2651,13 +2647,21 @@ class AnyFunctionType : public TypeBase {
ParameterTypeFlags Flags = {};

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

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

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

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

CanType getType() const { return CanType(Param::getType()); }
CanType getOldType() const { return CanType(Param::getOldType()); }
CanType getPlainType() const { return CanType(Param::getPlainType()); }
CanType getParameterType() const {
return CanType(Param::getParameterType(/*forCanonical*/ true));
Expand Down Expand Up @@ -2911,9 +2915,9 @@ class AnyFunctionType : public TypeBase {

protected:
AnyFunctionType(TypeKind Kind, const ASTContext *CanTypeContext,
Type Input, Type Output, RecursiveTypeProperties properties,
Type Output, RecursiveTypeProperties properties,
unsigned NumParams, ExtInfo Info)
: TypeBase(Kind, CanTypeContext, properties), Input(Input), Output(Output) {
: TypeBase(Kind, CanTypeContext, properties), Output(Output) {
Bits.AnyFunctionType.ExtInfo = Info.Bits;
Bits.AnyFunctionType.NumParams = NumParams;
assert(Bits.AnyFunctionType.NumParams == NumParams && "Params dropped!");
Expand Down Expand Up @@ -2950,7 +2954,6 @@ class AnyFunctionType : public TypeBase {
static void relabelParams(MutableArrayRef<Param> params,
ArrayRef<Identifier> labels);

Type getInput() const { return Input; }
Type getResult() const { return Output; }
ArrayRef<Param> getParams() const;
unsigned getNumParams() const { return Bits.AnyFunctionType.NumParams; }
Expand Down Expand Up @@ -2982,10 +2985,6 @@ class AnyFunctionType : public TypeBase {
return getExtInfo().throws();
}

/// Determine whether the given function input type is one of the
/// canonical forms.
static bool isCanonicalFunctionInputType(Type input);

/// Returns a new function type exactly like this one but with the ExtInfo
/// replaced.
AnyFunctionType *withExtInfo(ExtInfo info) const;
Expand All @@ -3011,10 +3010,6 @@ BEGIN_CAN_TYPE_WRAPPER(AnyFunctionType, Type)

CanGenericSignature getOptGenericSignature() const;

CanType getInput() const {
return getPointer()->getInput()->getCanonicalType();
}

CanParamArrayRef getParams() const {
return CanParamArrayRef(getPointer()->getParams());
}
Expand All @@ -3035,37 +3030,41 @@ inline AnyFunctionType::CanYield AnyFunctionType::Yield::getCanonical() const {
/// For example:
/// let x : (Float, Int) -> Int
class FunctionType final : public AnyFunctionType,
public llvm::FoldingSetNode,
private llvm::TrailingObjects<FunctionType, AnyFunctionType::Param> {
friend TrailingObjects;

public:
/// 'Constructor' Factory Function
static FunctionType *get(ArrayRef<Param> params,
Type result,
ExtInfo info = ExtInfo(),
bool canonicalVararg = false);
static FunctionType *get(ArrayRef<Param> params, Type result,
ExtInfo info = ExtInfo());

// Retrieve the input parameters of this function type.
ArrayRef<Param> getParams() const {
return {getTrailingObjects<Param>(), getNumParams()};
}


void Profile(llvm::FoldingSetNodeID &ID) {
Profile(ID, getParams(), getResult(), getExtInfo());
}
static void Profile(llvm::FoldingSetNodeID &ID,
ArrayRef<Param> params,
Type result,
ExtInfo info);

// Implement isa/cast/dyncast/etc.
static bool classof(const TypeBase *T) {
return T->getKind() == TypeKind::Function;
}

private:
FunctionType(ArrayRef<Param> params,
Type Input, Type Result,
RecursiveTypeProperties properties,
ExtInfo Info);
FunctionType(ArrayRef<Param> params, Type result, ExtInfo info,
const ASTContext *ctx, RecursiveTypeProperties properties);
};
BEGIN_CAN_TYPE_WRAPPER(FunctionType, AnyFunctionType)
static CanFunctionType get(CanParamArrayRef params, CanType result,
ExtInfo info = ExtInfo()) {
auto fnType = FunctionType::get(params.getOriginalArray(),
result, info, /*canonicalVararg=*/true);
auto fnType = FunctionType::get(params.getOriginalArray(), result, info);
return cast<FunctionType>(fnType->getCanonicalType());
}

Expand Down Expand Up @@ -3102,7 +3101,6 @@ class GenericFunctionType final : public AnyFunctionType,
/// Construct a new generic function type.
GenericFunctionType(GenericSignature *sig,
ArrayRef<Param> params,
Type input,
Type result,
ExtInfo info,
const ASTContext *ctx,
Expand All @@ -3113,8 +3111,7 @@ class GenericFunctionType final : public AnyFunctionType,
static GenericFunctionType *get(GenericSignature *sig,
ArrayRef<Param> params,
Type result,
ExtInfo info = ExtInfo(),
bool canonicalVararg = false);
ExtInfo info = ExtInfo());

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

void Profile(llvm::FoldingSetNodeID &ID) {
Profile(ID, getGenericSignature(), getInput(), getResult(),
Profile(ID, getGenericSignature(), getParams(), getResult(),
getExtInfo());
}
static void Profile(llvm::FoldingSetNodeID &ID,
GenericSignature *sig,
Type input,
ArrayRef<Param> params,
Type result,
ExtInfo info);

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

Expand Down
Loading