Skip to content

Remove PolymorphicFunctionType #5935

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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
7d83704
AST: Add ConstructorDecl::getArgumentInterfaceType()
slavapestov Nov 24, 2016
69e7cca
AST: Remove ConstructorDecl::getResultType()
slavapestov Nov 24, 2016
55ad180
AST: Remove ConstructorDecl::getArgumentType()
slavapestov Nov 24, 2016
f6e6921
AST: Remove FuncDecl::getResultType()
slavapestov Nov 24, 2016
f803d8f
AST: Remove AbstractFunctionDecl::getBodyResultType()
slavapestov Nov 26, 2016
bd9e9d8
AST: Refactor TypeDecl::getDeclaredInterfaceType() a bit
slavapestov Nov 20, 2016
530478c
AST: Set NominalTypeDecls interface types in computeType() rather tha…
slavapestov Nov 24, 2016
6cbb494
AST: Give all ValueDecls an interface type
slavapestov Nov 24, 2016
e74d246
AST: Assert in getInterfaceType() if no interface type is set
slavapestov Nov 25, 2016
887f9c5
SILGen: getType() => getInterfaceType()
slavapestov Nov 27, 2016
7fc1fb8
ClangImporter: getType() => getInterfaceType()
slavapestov Nov 27, 2016
09980dd
AST: getType() => getInterfaceType()
slavapestov Nov 27, 2016
6c63514
IDE: getType() => getInterfaceType()
slavapestov Nov 27, 2016
7cfe0e6
Sema: getType() => getInterfaceType()
slavapestov Nov 27, 2016
f875aa5
PrintAsObjC: getType() => getInterfaceType()
slavapestov Nov 27, 2016
fa9d66c
Sema: Small refactoring for findGenericSubstitutions()
slavapestov Nov 26, 2016
4ebac86
AST: Type::subst(): try harder to preserve sugar
slavapestov Nov 28, 2016
492a849
Sema: CSDiag setType() => getInterfaceType()
slavapestov Nov 27, 2016
7c55671
Sema: Fix CSDiag bug noticed by inspection
slavapestov Nov 26, 2016
e71979e
Serialization: Don't serialize contextual type of AbstractFunctionDec…
slavapestov Nov 24, 2016
cb539bc
IRGen: Remove unnecessary hasType() check
slavapestov Nov 27, 2016
65dd44e
AST: Tweak ParameterList::getInterfaceType()
slavapestov Nov 27, 2016
2cb9c89
ArchetypeBuilder: Skip associated types with ErrorType
slavapestov Nov 28, 2016
40b0c5b
AST: More accurate hasInterfaceType()
slavapestov Nov 27, 2016
1657060
AST: hasType() => hasInterfaceType()
slavapestov Nov 27, 2016
044034c
Sema: hasType() => hasInterfaceType()
slavapestov Nov 27, 2016
5499f45
ClangImporter: hasType() => hasInterfaceType()
slavapestov Nov 27, 2016
9ed5f92
SILGen: hasType() => hasInterfaceType()
slavapestov Nov 27, 2016
7b59e75
IDE: hasType() => hasInterfaceType()
slavapestov Nov 27, 2016
0dd6cf3
Serialization: hasType() => hasInterfaceType()
slavapestov Nov 27, 2016
8272fc1
AST: Assert if getType() called on AbstractFunctionDecl or EnumElemen…
slavapestov Nov 24, 2016
087fe17
IDE: Rework TypeReconstruction to not rely on PolymorphicFunctionType
slavapestov Nov 27, 2016
82b764d
Sema: Tweak a circularity check
slavapestov Nov 28, 2016
0f7a455
AST: Don't call setType() on AbstractFunctionDecls and EnumElementDecls
slavapestov Nov 27, 2016
fd0f468
AST: Assert if setType() called on AbstractFunctionDecl or EnumElemen…
slavapestov Nov 27, 2016
c284bd4
AST: Assert if hasType() called on AbstractFunctionDecl or EnumElemen…
slavapestov Nov 27, 2016
2877006
Sema: configureImplicitSelf() no longer needs to return a type
slavapestov Nov 27, 2016
835472b
AST: Remove PolymorphicFunctionType
slavapestov Nov 27, 2016
01bb403
AST: Prohibit archetypes in setInterfaceType()
slavapestov Nov 28, 2016
b43c395
AST: Map ParamDecl types out of context when mangling
slavapestov Nov 28, 2016
1809fc8
AST: Map closure types out of context when mangling
slavapestov Nov 28, 2016
3749e78
Non-deterministic crasher
slavapestov Nov 29, 2016
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
8 changes: 5 additions & 3 deletions include/swift/AST/AnyFunctionRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define SWIFT_AST_ANY_FUNCTION_REF_H

#include "swift/Basic/LLVM.h"
#include "swift/AST/ArchetypeBuilder.h"
#include "swift/AST/Decl.h"
#include "swift/AST/Expr.h"
#include "swift/AST/Types.h"
Expand Down Expand Up @@ -69,7 +70,7 @@ class AnyFunctionRef {

bool hasType() const {
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>())
return AFD->hasType();
return AFD->hasInterfaceType();
return !TheFunction.get<AbstractClosureExpr *>()->getType().isNull();
}

Expand All @@ -78,7 +79,7 @@ class AnyFunctionRef {
return AFD->getType();
return TheFunction.get<AbstractClosureExpr *>()->getType();
}

/// FIXME: This should just be getType() when interface types take over in
/// the AST.
Type getInterfaceType() const {
Expand All @@ -90,7 +91,8 @@ class AnyFunctionRef {
Type getBodyResultType() const {
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>()) {
if (auto *FD = dyn_cast<FuncDecl>(AFD))
return FD->getBodyResultType();
return ArchetypeBuilder::mapTypeIntoContext(
FD, FD->getResultInterfaceType());
return TupleType::getEmpty(AFD->getASTContext());
}
return TheFunction.get<AbstractClosureExpr *>()->getResultType();
Expand Down
73 changes: 22 additions & 51 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2003,8 +2003,17 @@ class ValueDecl : public Decl {
SourceLoc getNameLoc() const { return NameLoc; }
SourceLoc getLoc() const { return NameLoc; }

bool hasType() const { return !TypeAndAccess.getPointer().isNull(); }
bool hasType() const {
assert(!isa<AbstractFunctionDecl>(this) &&
!isa<EnumElementDecl>(this) &&
"functions and enum case constructors only have an interface type");
return !TypeAndAccess.getPointer().isNull();
}

Type getType() const {
assert(!isa<AbstractFunctionDecl>(this) &&
!isa<EnumElementDecl>(this) &&
"functions and enum case constructors only have an interface type");
assert(hasType() && "declaration has no type set yet");
return TypeAndAccess.getPointer();
}
Expand Down Expand Up @@ -2097,7 +2106,7 @@ class ValueDecl : public Decl {
/// we will substitute in the appropriate archetypes within a particular
/// context.
Type getInterfaceType() const;
bool hasInterfaceType() const { return !!InterfaceTy; }
bool hasInterfaceType() const;

/// Set the interface type for the given value.
void setInterfaceType(Type type);
Expand Down Expand Up @@ -2642,6 +2651,7 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
protected:
Type DeclaredTy;
Type DeclaredTyInContext;
Type DeclaredInterfaceTy;

NominalTypeDecl(DeclKind K, DeclContext *DC, Identifier name,
SourceLoc NameLoc,
Expand Down Expand Up @@ -2726,16 +2736,13 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
/// any generic parameters bound if this is a generic type.
Type getDeclaredType() const;

/// getDeclaredType - Retrieve the type declared by this entity, with
/// getDeclaredTypeInContext - Retrieve the type declared by this entity, with
/// context archetypes bound if this is a generic type.
Type getDeclaredTypeInContext() const;

/// Get the "interface" type of the given nominal type, which is the
/// type used to refer to the nominal type externally.
///
/// For a generic type, or a member thereof, this is the a specialization
/// of the type using its own generic parameters.
Type computeInterfaceType() const;
/// getDeclaredInterfaceType - Retrieve the type declared by this entity, with
/// generic parameters bound if this is a generic type.
Type getDeclaredInterfaceType() const;

/// \brief Add a new extension to this nominal type.
void addExtension(ExtensionDecl *extension);
Expand Down Expand Up @@ -4840,11 +4847,6 @@ class FuncDecl final : public AbstractFunctionDecl,

TypeLoc FnRetType;

/// The result type as seen from the body of the function.
///
/// \sa getBodyResultType()
Type BodyResultType;

/// If this declaration is part of an overload set, determine if we've
/// searched for a common overload amongst all overloads, or if we've found
/// one.
Expand All @@ -4865,7 +4867,7 @@ class FuncDecl final : public AbstractFunctionDecl,
bool Throws, SourceLoc ThrowsLoc,
SourceLoc AccessorKeywordLoc,
unsigned NumParameterLists,
GenericParamList *GenericParams, Type Ty, DeclContext *Parent)
GenericParamList *GenericParams, DeclContext *Parent)
: AbstractFunctionDecl(DeclKind::Func, Parent,
Name, NameLoc,
Throws, ThrowsLoc,
Expand All @@ -4878,7 +4880,6 @@ class FuncDecl final : public AbstractFunctionDecl,
StaticLoc.isValid() || StaticSpelling != StaticSpellingKind::None;
FuncDeclBits.StaticSpelling = static_cast<unsigned>(StaticSpelling);
assert(NumParameterLists > 0 && "Must have at least an empty tuple arg");
setType(Ty);
FuncDeclBits.Mutating = false;
FuncDeclBits.HasDynamicSelf = false;
FuncDeclBits.ForcedStaticDispatch = false;
Expand All @@ -4894,7 +4895,7 @@ class FuncDecl final : public AbstractFunctionDecl,
bool Throws, SourceLoc ThrowsLoc,
SourceLoc AccessorKeywordLoc,
GenericParamList *GenericParams,
unsigned NumParameterLists, Type Ty,
unsigned NumParameterLists,
DeclContext *Parent,
ClangNode ClangN);

Expand All @@ -4907,7 +4908,7 @@ class FuncDecl final : public AbstractFunctionDecl,
bool Throws, SourceLoc ThrowsLoc,
SourceLoc AccessorKeywordLoc,
GenericParamList *GenericParams,
unsigned NumParameterLists, Type Ty,
unsigned NumParameterLists,
DeclContext *Parent);

static FuncDecl *create(ASTContext &Context, SourceLoc StaticLoc,
Expand All @@ -4917,7 +4918,7 @@ class FuncDecl final : public AbstractFunctionDecl,
bool Throws, SourceLoc ThrowsLoc,
SourceLoc AccessorKeywordLoc,
GenericParamList *GenericParams,
ArrayRef<ParameterList *> ParameterLists, Type Ty,
ArrayRef<ParameterList *> ParameterLists,
TypeLoc FnRetType, DeclContext *Parent,
ClangNode ClangN = ClangNode());

Expand Down Expand Up @@ -4990,36 +4991,9 @@ class FuncDecl final : public AbstractFunctionDecl,
TypeLoc &getBodyResultTypeLoc() { return FnRetType; }
const TypeLoc &getBodyResultTypeLoc() const { return FnRetType; }

/// Retrieve the result type of this function.
Type getResultType() const;

/// Retrieve the result interface type of this function.
Type getResultInterfaceType() const;

/// Retrieve the result type of this function for use within the function
/// definition.
///
/// FIXME: The statement below is a wish, not reality.
/// The "body" result type will only differ from the result type within the
/// interface to the function for a polymorphic function, where the interface
/// may contain generic parameters while the definition will contain
/// the corresponding archetypes.
Type getBodyResultType() const { return BodyResultType; }

/// Set the result type as viewed from the function body.
///
/// \sa getBodyResultType
void setBodyResultType(Type bodyResultType) {
assert(BodyResultType.isNull() && "Already set body result type");
BodyResultType = bodyResultType;
}

/// Revert to an empty type.
void revertType() {
BodyResultType = Type();
overwriteType(Type());
}

/// isUnaryOperator - Determine whether this is a unary operator
/// implementation. This check is a syntactic rather than type-based check,
/// which looks at the number of parameters specified, in order to allow
Expand Down Expand Up @@ -5405,11 +5379,8 @@ class ConstructorDecl : public AbstractFunctionDecl {
SourceLoc getStartLoc() const { return getConstructorLoc(); }
SourceRange getSourceRange() const;

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

/// \brief Get the type of the constructed object.
Type getResultType() 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
1 change: 0 additions & 1 deletion include/swift/AST/TypeNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ SUGARED_TYPE(Substituted, Type)
TYPE(DependentMember, Type)
ABSTRACT_TYPE(AnyFunction, Type)
TYPE(Function, AnyFunctionType)
TYPE(PolymorphicFunction, AnyFunctionType)
TYPE(GenericFunction, AnyFunctionType)
TYPE_RANGE(AnyFunction, Function, GenericFunction)
ARTIFICIAL_TYPE(SILFunction, Type)
Expand Down
47 changes: 1 addition & 46 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2253,7 +2253,7 @@ getSILFunctionLanguage(SILFunctionTypeRepresentation rep) {
/// function may be an arbitrary type.
///
/// There are two kinds of function types: monomorphic (FunctionType) and
/// polymorphic (PolymorphicFunctionType). Both type families additionally can
/// 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 {
Expand Down Expand Up @@ -2538,58 +2538,13 @@ decomposeParamType(Type type, const ValueDecl *paramOwner, unsigned level);
/// include the types, something like (: , b:, c:)
std::string getParamListAsString(ArrayRef<CallArgParam> parameters);

/// PolymorphicFunctionType - A polymorphic function type.
class PolymorphicFunctionType : public AnyFunctionType {
// TODO: storing a GenericParamList* here is really the wrong solution;
// we should be able to store something readily canonicalizable.
GenericParamList *Params;
public:
/// 'Constructor' Factory Function
static PolymorphicFunctionType *get(Type input, Type output,
GenericParamList *params,
bool throws = false) {
return get(input, output, params, ExtInfo().withThrows(throws));
}

static PolymorphicFunctionType *get(Type input, Type output,
GenericParamList *params,
const ExtInfo &Info);

ArrayRef<GenericTypeParamDecl *> getGenericParameters() const;

GenericParamList &getGenericParams() const { return *Params; }

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

private:
PolymorphicFunctionType(Type input, Type output,
GenericParamList *params,
const ExtInfo &Info,
const ASTContext &C,
RecursiveTypeProperties properties);
};
BEGIN_CAN_TYPE_WRAPPER(PolymorphicFunctionType, AnyFunctionType)
static CanPolymorphicFunctionType get(CanType input, CanType result,
GenericParamList *params,
const ExtInfo &info) {
return CanPolymorphicFunctionType(
PolymorphicFunctionType::get(input, result, params, info));
}
END_CAN_TYPE_WRAPPER(PolymorphicFunctionType, AnyFunctionType)

/// Describes a generic function type.
///
/// A generic function type describes a function that is polymorphic with
/// respect to some set of generic parameters and the requirements placed
/// on those parameters and dependent member types thereof. The input and
/// output types of the generic function can be expressed in terms of those
/// generic parameters.
///
/// FIXME: \c GenericFunctionType is meant as a replacement for
/// \c PolymorphicFunctionType.
class GenericFunctionType : public AnyFunctionType,
public llvm::FoldingSetNode
{
Expand Down
1 change: 0 additions & 1 deletion include/swift/SIL/SILType.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,6 @@ template<> Can##ID##Type SILType::getAs<ID##Type>() const = delete; \
template<> Can##ID##Type SILType::castTo<ID##Type>() const = delete; \
template<> bool SILType::is<ID##Type>() const = delete;
NON_SIL_TYPE(Function)
NON_SIL_TYPE(PolymorphicFunction)
NON_SIL_TYPE(AnyFunction)
NON_SIL_TYPE(LValue)
#undef NON_SIL_TYPE
Expand Down
1 change: 0 additions & 1 deletion include/swift/Serialization/DeclTypeRecordNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ TYPE(PROTOCOL_COMPOSITION)
TYPE(SUBSTITUTED)
TYPE(BOUND_GENERIC)
TRAILING_INFO(BOUND_GENERIC_SUBSTITUTION)
TYPE(POLYMORPHIC_FUNCTION)
TYPE(GENERIC_FUNCTION)
TYPE(ARRAY_SLICE)
TYPE(DICTIONARY)
Expand Down
16 changes: 1 addition & 15 deletions include/swift/Serialization/ModuleFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const uint16_t VERSION_MAJOR = 0;
/// in source control, you should also update the comment to briefly
/// describe what change you made. The content of this comment isn't important;
/// it just ensures a conflict if two people change the module format.
const uint16_t VERSION_MINOR = 285; // Last change: simplified archetype format
const uint16_t VERSION_MINOR = 287; // Last change: remove PolymorphicFunctionType

using DeclID = PointerEmbeddedInt<unsigned, 31>;
using DeclIDField = BCFixed<31>;
Expand Down Expand Up @@ -681,16 +681,6 @@ namespace decls_block {
// Trailed by protocol conformance info (if any)
>;

using PolymorphicFunctionTypeLayout = BCRecordLayout<
POLYMORPHIC_FUNCTION_TYPE,
TypeIDField, // input
TypeIDField, // output
DeclIDField, // decl that owns the generic params
FunctionTypeRepresentationField, // representation
BCFixed<1> // throws?
// Trailed by its generic parameters, if the owning decl ID is 0.
>;

using GenericFunctionTypeLayout = BCRecordLayout<
GENERIC_FUNCTION_TYPE,
TypeIDField, // input
Expand Down Expand Up @@ -854,7 +844,6 @@ namespace decls_block {
BCFixed<1>, // stub implementation?
BCFixed<1>, // throws?
CtorInitializerKindField, // initializer kind
TypeIDField, // type (signature)
TypeIDField, // type (interface)
DeclIDField, // overridden decl
AccessibilityKindField, // accessibility
Expand Down Expand Up @@ -908,7 +897,6 @@ namespace decls_block {
BCFixed<1>, // has dynamic self?
BCFixed<1>, // throws?
BCVBR<5>, // number of parameter patterns
TypeIDField, // type (signature)
TypeIDField, // interface type
DeclIDField, // operator decl
DeclIDField, // overridden function
Expand Down Expand Up @@ -966,7 +954,6 @@ namespace decls_block {
IdentifierIDField, // name
DeclContextIDField,// context decl
TypeIDField, // argument type
TypeIDField, // constructor type
TypeIDField, // interface type
BCFixed<1>, // implicit?
EnumElementRawValueKindField, // raw value kind
Expand Down Expand Up @@ -1013,7 +1000,6 @@ namespace decls_block {
DeclContextIDField, // context decl
BCFixed<1>, // implicit?
BCFixed<1>, // objc?
TypeIDField, // type (signature)
TypeIDField // interface type
// Trailed by a pattern for self.
>;
Expand Down
Loading