Skip to content

Commit 33c322f

Browse files
authored
Merge pull request #5935 from slavapestov/remove-polymorphic-function-type-wip-november-2016
Remove PolymorphicFunctionType
2 parents 0b34f20 + 3749e78 commit 33c322f

File tree

97 files changed

+722
-1149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+722
-1149
lines changed

include/swift/AST/AnyFunctionRef.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define SWIFT_AST_ANY_FUNCTION_REF_H
1515

1616
#include "swift/Basic/LLVM.h"
17+
#include "swift/AST/ArchetypeBuilder.h"
1718
#include "swift/AST/Decl.h"
1819
#include "swift/AST/Expr.h"
1920
#include "swift/AST/Types.h"
@@ -69,7 +70,7 @@ class AnyFunctionRef {
6970

7071
bool hasType() const {
7172
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>())
72-
return AFD->hasType();
73+
return AFD->hasInterfaceType();
7374
return !TheFunction.get<AbstractClosureExpr *>()->getType().isNull();
7475
}
7576

@@ -78,7 +79,7 @@ class AnyFunctionRef {
7879
return AFD->getType();
7980
return TheFunction.get<AbstractClosureExpr *>()->getType();
8081
}
81-
82+
8283
/// FIXME: This should just be getType() when interface types take over in
8384
/// the AST.
8485
Type getInterfaceType() const {
@@ -90,7 +91,8 @@ class AnyFunctionRef {
9091
Type getBodyResultType() const {
9192
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>()) {
9293
if (auto *FD = dyn_cast<FuncDecl>(AFD))
93-
return FD->getBodyResultType();
94+
return ArchetypeBuilder::mapTypeIntoContext(
95+
FD, FD->getResultInterfaceType());
9496
return TupleType::getEmpty(AFD->getASTContext());
9597
}
9698
return TheFunction.get<AbstractClosureExpr *>()->getResultType();

include/swift/AST/Decl.h

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,8 +2003,17 @@ class ValueDecl : public Decl {
20032003
SourceLoc getNameLoc() const { return NameLoc; }
20042004
SourceLoc getLoc() const { return NameLoc; }
20052005

2006-
bool hasType() const { return !TypeAndAccess.getPointer().isNull(); }
2006+
bool hasType() const {
2007+
assert(!isa<AbstractFunctionDecl>(this) &&
2008+
!isa<EnumElementDecl>(this) &&
2009+
"functions and enum case constructors only have an interface type");
2010+
return !TypeAndAccess.getPointer().isNull();
2011+
}
2012+
20072013
Type getType() const {
2014+
assert(!isa<AbstractFunctionDecl>(this) &&
2015+
!isa<EnumElementDecl>(this) &&
2016+
"functions and enum case constructors only have an interface type");
20082017
assert(hasType() && "declaration has no type set yet");
20092018
return TypeAndAccess.getPointer();
20102019
}
@@ -2097,7 +2106,7 @@ class ValueDecl : public Decl {
20972106
/// we will substitute in the appropriate archetypes within a particular
20982107
/// context.
20992108
Type getInterfaceType() const;
2100-
bool hasInterfaceType() const { return !!InterfaceTy; }
2109+
bool hasInterfaceType() const;
21012110

21022111
/// Set the interface type for the given value.
21032112
void setInterfaceType(Type type);
@@ -2642,6 +2651,7 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
26422651
protected:
26432652
Type DeclaredTy;
26442653
Type DeclaredTyInContext;
2654+
Type DeclaredInterfaceTy;
26452655

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

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

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

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

48414848
TypeLoc FnRetType;
48424849

4843-
/// The result type as seen from the body of the function.
4844-
///
4845-
/// \sa getBodyResultType()
4846-
Type BodyResultType;
4847-
48484850
/// If this declaration is part of an overload set, determine if we've
48494851
/// searched for a common overload amongst all overloads, or if we've found
48504852
/// one.
@@ -4865,7 +4867,7 @@ class FuncDecl final : public AbstractFunctionDecl,
48654867
bool Throws, SourceLoc ThrowsLoc,
48664868
SourceLoc AccessorKeywordLoc,
48674869
unsigned NumParameterLists,
4868-
GenericParamList *GenericParams, Type Ty, DeclContext *Parent)
4870+
GenericParamList *GenericParams, DeclContext *Parent)
48694871
: AbstractFunctionDecl(DeclKind::Func, Parent,
48704872
Name, NameLoc,
48714873
Throws, ThrowsLoc,
@@ -4878,7 +4880,6 @@ class FuncDecl final : public AbstractFunctionDecl,
48784880
StaticLoc.isValid() || StaticSpelling != StaticSpellingKind::None;
48794881
FuncDeclBits.StaticSpelling = static_cast<unsigned>(StaticSpelling);
48804882
assert(NumParameterLists > 0 && "Must have at least an empty tuple arg");
4881-
setType(Ty);
48824883
FuncDeclBits.Mutating = false;
48834884
FuncDeclBits.HasDynamicSelf = false;
48844885
FuncDeclBits.ForcedStaticDispatch = false;
@@ -4894,7 +4895,7 @@ class FuncDecl final : public AbstractFunctionDecl,
48944895
bool Throws, SourceLoc ThrowsLoc,
48954896
SourceLoc AccessorKeywordLoc,
48964897
GenericParamList *GenericParams,
4897-
unsigned NumParameterLists, Type Ty,
4898+
unsigned NumParameterLists,
48984899
DeclContext *Parent,
48994900
ClangNode ClangN);
49004901

@@ -4907,7 +4908,7 @@ class FuncDecl final : public AbstractFunctionDecl,
49074908
bool Throws, SourceLoc ThrowsLoc,
49084909
SourceLoc AccessorKeywordLoc,
49094910
GenericParamList *GenericParams,
4910-
unsigned NumParameterLists, Type Ty,
4911+
unsigned NumParameterLists,
49114912
DeclContext *Parent);
49124913

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

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

4993-
/// Retrieve the result type of this function.
4994-
Type getResultType() const;
4995-
49964994
/// Retrieve the result interface type of this function.
49974995
Type getResultInterfaceType() const;
49984996

4999-
/// Retrieve the result type of this function for use within the function
5000-
/// definition.
5001-
///
5002-
/// FIXME: The statement below is a wish, not reality.
5003-
/// The "body" result type will only differ from the result type within the
5004-
/// interface to the function for a polymorphic function, where the interface
5005-
/// may contain generic parameters while the definition will contain
5006-
/// the corresponding archetypes.
5007-
Type getBodyResultType() const { return BodyResultType; }
5008-
5009-
/// Set the result type as viewed from the function body.
5010-
///
5011-
/// \sa getBodyResultType
5012-
void setBodyResultType(Type bodyResultType) {
5013-
assert(BodyResultType.isNull() && "Already set body result type");
5014-
BodyResultType = bodyResultType;
5015-
}
5016-
5017-
/// Revert to an empty type.
5018-
void revertType() {
5019-
BodyResultType = Type();
5020-
overwriteType(Type());
5021-
}
5022-
50234997
/// isUnaryOperator - Determine whether this is a unary operator
50244998
/// implementation. This check is a syntactic rather than type-based check,
50254999
/// which looks at the number of parameters specified, in order to allow
@@ -5405,11 +5379,8 @@ class ConstructorDecl : public AbstractFunctionDecl {
54055379
SourceLoc getStartLoc() const { return getConstructorLoc(); }
54065380
SourceRange getSourceRange() const;
54075381

5408-
/// getArgumentType - get the type of the argument tuple
5409-
Type getArgumentType() const;
5410-
5411-
/// \brief Get the type of the constructed object.
5412-
Type getResultType() const;
5382+
/// getArgumentInterfaceType - get the interface type of the argument tuple
5383+
Type getArgumentInterfaceType() const;
54135384

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

include/swift/AST/TypeNodes.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ SUGARED_TYPE(Substituted, Type)
123123
TYPE(DependentMember, Type)
124124
ABSTRACT_TYPE(AnyFunction, Type)
125125
TYPE(Function, AnyFunctionType)
126-
TYPE(PolymorphicFunction, AnyFunctionType)
127126
TYPE(GenericFunction, AnyFunctionType)
128127
TYPE_RANGE(AnyFunction, Function, GenericFunction)
129128
ARTIFICIAL_TYPE(SILFunction, Type)

include/swift/AST/Types.h

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,7 +2253,7 @@ getSILFunctionLanguage(SILFunctionTypeRepresentation rep) {
22532253
/// function may be an arbitrary type.
22542254
///
22552255
/// There are two kinds of function types: monomorphic (FunctionType) and
2256-
/// polymorphic (PolymorphicFunctionType). Both type families additionally can
2256+
/// polymorphic (GenericFunctionType). Both type families additionally can
22572257
/// be 'thin', indicating that a function value has no capture context and can be
22582258
/// represented at the binary level as a single function pointer.
22592259
class AnyFunctionType : public TypeBase {
@@ -2538,58 +2538,13 @@ decomposeParamType(Type type, const ValueDecl *paramOwner, unsigned level);
25382538
/// include the types, something like (: , b:, c:)
25392539
std::string getParamListAsString(ArrayRef<CallArgParam> parameters);
25402540

2541-
/// PolymorphicFunctionType - A polymorphic function type.
2542-
class PolymorphicFunctionType : public AnyFunctionType {
2543-
// TODO: storing a GenericParamList* here is really the wrong solution;
2544-
// we should be able to store something readily canonicalizable.
2545-
GenericParamList *Params;
2546-
public:
2547-
/// 'Constructor' Factory Function
2548-
static PolymorphicFunctionType *get(Type input, Type output,
2549-
GenericParamList *params,
2550-
bool throws = false) {
2551-
return get(input, output, params, ExtInfo().withThrows(throws));
2552-
}
2553-
2554-
static PolymorphicFunctionType *get(Type input, Type output,
2555-
GenericParamList *params,
2556-
const ExtInfo &Info);
2557-
2558-
ArrayRef<GenericTypeParamDecl *> getGenericParameters() const;
2559-
2560-
GenericParamList &getGenericParams() const { return *Params; }
2561-
2562-
// Implement isa/cast/dyncast/etc.
2563-
static bool classof(const TypeBase *T) {
2564-
return T->getKind() == TypeKind::PolymorphicFunction;
2565-
}
2566-
2567-
private:
2568-
PolymorphicFunctionType(Type input, Type output,
2569-
GenericParamList *params,
2570-
const ExtInfo &Info,
2571-
const ASTContext &C,
2572-
RecursiveTypeProperties properties);
2573-
};
2574-
BEGIN_CAN_TYPE_WRAPPER(PolymorphicFunctionType, AnyFunctionType)
2575-
static CanPolymorphicFunctionType get(CanType input, CanType result,
2576-
GenericParamList *params,
2577-
const ExtInfo &info) {
2578-
return CanPolymorphicFunctionType(
2579-
PolymorphicFunctionType::get(input, result, params, info));
2580-
}
2581-
END_CAN_TYPE_WRAPPER(PolymorphicFunctionType, AnyFunctionType)
2582-
25832541
/// Describes a generic function type.
25842542
///
25852543
/// A generic function type describes a function that is polymorphic with
25862544
/// respect to some set of generic parameters and the requirements placed
25872545
/// on those parameters and dependent member types thereof. The input and
25882546
/// output types of the generic function can be expressed in terms of those
25892547
/// generic parameters.
2590-
///
2591-
/// FIXME: \c GenericFunctionType is meant as a replacement for
2592-
/// \c PolymorphicFunctionType.
25932548
class GenericFunctionType : public AnyFunctionType,
25942549
public llvm::FoldingSetNode
25952550
{

include/swift/SIL/SILType.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,6 @@ template<> Can##ID##Type SILType::getAs<ID##Type>() const = delete; \
540540
template<> Can##ID##Type SILType::castTo<ID##Type>() const = delete; \
541541
template<> bool SILType::is<ID##Type>() const = delete;
542542
NON_SIL_TYPE(Function)
543-
NON_SIL_TYPE(PolymorphicFunction)
544543
NON_SIL_TYPE(AnyFunction)
545544
NON_SIL_TYPE(LValue)
546545
#undef NON_SIL_TYPE

include/swift/Serialization/DeclTypeRecordNodes.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ TYPE(PROTOCOL_COMPOSITION)
9898
TYPE(SUBSTITUTED)
9999
TYPE(BOUND_GENERIC)
100100
TRAILING_INFO(BOUND_GENERIC_SUBSTITUTION)
101-
TYPE(POLYMORPHIC_FUNCTION)
102101
TYPE(GENERIC_FUNCTION)
103102
TYPE(ARRAY_SLICE)
104103
TYPE(DICTIONARY)

include/swift/Serialization/ModuleFormat.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const uint16_t VERSION_MAJOR = 0;
5454
/// in source control, you should also update the comment to briefly
5555
/// describe what change you made. The content of this comment isn't important;
5656
/// it just ensures a conflict if two people change the module format.
57-
const uint16_t VERSION_MINOR = 285; // Last change: simplified archetype format
57+
const uint16_t VERSION_MINOR = 287; // Last change: remove PolymorphicFunctionType
5858

5959
using DeclID = PointerEmbeddedInt<unsigned, 31>;
6060
using DeclIDField = BCFixed<31>;
@@ -681,16 +681,6 @@ namespace decls_block {
681681
// Trailed by protocol conformance info (if any)
682682
>;
683683

684-
using PolymorphicFunctionTypeLayout = BCRecordLayout<
685-
POLYMORPHIC_FUNCTION_TYPE,
686-
TypeIDField, // input
687-
TypeIDField, // output
688-
DeclIDField, // decl that owns the generic params
689-
FunctionTypeRepresentationField, // representation
690-
BCFixed<1> // throws?
691-
// Trailed by its generic parameters, if the owning decl ID is 0.
692-
>;
693-
694684
using GenericFunctionTypeLayout = BCRecordLayout<
695685
GENERIC_FUNCTION_TYPE,
696686
TypeIDField, // input
@@ -854,7 +844,6 @@ namespace decls_block {
854844
BCFixed<1>, // stub implementation?
855845
BCFixed<1>, // throws?
856846
CtorInitializerKindField, // initializer kind
857-
TypeIDField, // type (signature)
858847
TypeIDField, // type (interface)
859848
DeclIDField, // overridden decl
860849
AccessibilityKindField, // accessibility
@@ -908,7 +897,6 @@ namespace decls_block {
908897
BCFixed<1>, // has dynamic self?
909898
BCFixed<1>, // throws?
910899
BCVBR<5>, // number of parameter patterns
911-
TypeIDField, // type (signature)
912900
TypeIDField, // interface type
913901
DeclIDField, // operator decl
914902
DeclIDField, // overridden function
@@ -966,7 +954,6 @@ namespace decls_block {
966954
IdentifierIDField, // name
967955
DeclContextIDField,// context decl
968956
TypeIDField, // argument type
969-
TypeIDField, // constructor type
970957
TypeIDField, // interface type
971958
BCFixed<1>, // implicit?
972959
EnumElementRawValueKindField, // raw value kind
@@ -1013,7 +1000,6 @@ namespace decls_block {
10131000
DeclContextIDField, // context decl
10141001
BCFixed<1>, // implicit?
10151002
BCFixed<1>, // objc?
1016-
TypeIDField, // type (signature)
10171003
TypeIDField // interface type
10181004
// Trailed by a pattern for self.
10191005
>;

0 commit comments

Comments
 (0)