Skip to content
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
60 changes: 20 additions & 40 deletions include/swift/AST/Attr.def
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ DECL_ATTR(available, Available,
AllowMultipleAttributes | LongAttribute,
1)
CONTEXTUAL_SIMPLE_DECL_ATTR(final, Final,
// SWIFT_ENABLE_TENSORFLOW
OnClass | OnFunc | OnAccessor | OnCall | OnVar | OnSubscript |
OnClass | OnFunc | OnAccessor | OnVar | OnSubscript |
DeclModifier,
2)
DECL_ATTR(objc, ObjC,
Expand All @@ -135,8 +134,7 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(required, Required,
DeclModifier,
4)
CONTEXTUAL_SIMPLE_DECL_ATTR(optional, Optional,
// SWIFT_ENABLE_TENSORFLOW
OnConstructor | OnFunc | OnAccessor | OnCall | OnVar | OnSubscript |
OnConstructor | OnFunc | OnAccessor | OnVar | OnSubscript |
DeclModifier,
5)
SIMPLE_DECL_ATTR(dynamicCallable, DynamicCallable,
Expand Down Expand Up @@ -192,8 +190,7 @@ DECL_ATTR(_semantics, Semantics,
AllowMultipleAttributes | UserInaccessible,
21)
CONTEXTUAL_SIMPLE_DECL_ATTR(dynamic, Dynamic,
// SWIFT_ENABLE_TENSORFLOW
OnFunc | OnAccessor | OnCall | OnVar | OnSubscript | OnConstructor |
OnFunc | OnAccessor | OnVar | OnSubscript | OnConstructor |
DeclModifier,
22)
CONTEXTUAL_SIMPLE_DECL_ATTR(infix, Infix,
Expand All @@ -209,16 +206,13 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(postfix, Postfix,
DeclModifier,
25)
SIMPLE_DECL_ATTR(_transparent, Transparent,
// SWIFT_ENABLE_TENSORFLOW
OnFunc | OnAccessor | OnCall | OnConstructor | OnVar | UserInaccessible,
OnFunc | OnAccessor | OnConstructor | OnVar | UserInaccessible,
26)
SIMPLE_DECL_ATTR(requires_stored_property_inits, RequiresStoredPropertyInits,
OnClass,
27)
SIMPLE_DECL_ATTR(nonobjc, NonObjC,
// SWIFT_ENABLE_TENSORFLOW
OnExtension | OnFunc | OnAccessor | OnCall | OnVar | OnSubscript |
OnConstructor,
OnExtension | OnFunc | OnAccessor | OnVar | OnSubscript | OnConstructor,
30)
SIMPLE_DECL_ATTR(_fixed_layout, FixedLayout,
OnVar | OnClass | OnStruct |
Expand All @@ -228,47 +222,40 @@ SIMPLE_DECL_ATTR(inlinable, Inlinable,
OnVar | OnSubscript | OnAbstractFunction,
32)
DECL_ATTR(_specialize, Specialize,
// SWIFT_ENABLE_TENSORFLOW
OnConstructor | OnFunc | OnAccessor | OnCall |
OnConstructor | OnFunc | OnAccessor |
AllowMultipleAttributes | LongAttribute | UserInaccessible,
33)
SIMPLE_DECL_ATTR(objcMembers, ObjCMembers,
OnClass,
34)
CONTEXTUAL_SIMPLE_DECL_ATTR(__consuming, Consuming,
// SWIFT_ENABLE_TENSORFLOW
OnFunc | OnAccessor | OnCall |
OnFunc | OnAccessor |
DeclModifier |
UserInaccessible |
NotSerialized, 40)
CONTEXTUAL_SIMPLE_DECL_ATTR(mutating, Mutating,
// SWIFT_ENABLE_TENSORFLOW
OnFunc | OnAccessor | OnCall |
OnFunc | OnAccessor |
DeclModifier |
NotSerialized, 41)
CONTEXTUAL_SIMPLE_DECL_ATTR(nonmutating, NonMutating,
// SWIFT_ENABLE_TENSORFLOW
OnFunc | OnAccessor | OnCall |
OnFunc | OnAccessor |
DeclModifier |
NotSerialized, 42)
CONTEXTUAL_SIMPLE_DECL_ATTR(convenience, Convenience,
OnConstructor |
DeclModifier |
NotSerialized, 43)
CONTEXTUAL_SIMPLE_DECL_ATTR(override, Override,
// SWIFT_ENABLE_TENSORFLOW
OnFunc | OnAccessor | OnCall | OnVar | OnSubscript | OnConstructor |
OnAssociatedType |
OnFunc | OnAccessor | OnVar | OnSubscript | OnConstructor | OnAssociatedType |
DeclModifier |
NotSerialized, 44)
SIMPLE_DECL_ATTR(_hasStorage, HasStorage,
OnVar |
UserInaccessible |
NotSerialized, 45)
DECL_ATTR(private, AccessControl,
// SWIFT_ENABLE_TENSORFLOW
OnFunc | OnAccessor | OnCall | OnExtension | OnGenericType | OnVar |
OnSubscript | OnConstructor |
OnFunc | OnAccessor | OnExtension | OnGenericType | OnVar | OnSubscript |
OnConstructor |
DeclModifier |
NotSerialized, 46)
DECL_ATTR_ALIAS(fileprivate, AccessControl)
Expand Down Expand Up @@ -316,8 +303,7 @@ DECL_ATTR(_alignment, Alignment,
UserInaccessible,
56)
SIMPLE_DECL_ATTR(rethrows, Rethrows,
// SWIFT_ENABLE_TENSORFLOW
OnFunc | OnAccessor | OnCall | OnConstructor |
OnFunc | OnAccessor | OnConstructor |
RejectByParser,
57)
DECL_ATTR(_swift_native_objc_runtime_base, SwiftNativeObjCRuntimeBase,
Expand All @@ -344,16 +330,14 @@ SIMPLE_DECL_ATTR(usableFromInline, UsableFromInline,
LongAttribute,
64)
SIMPLE_DECL_ATTR(discardableResult, DiscardableResult,
// SWIFT_ENABLE_TENSORFLOW
OnFunc | OnAccessor | OnCall | OnConstructor |
OnFunc | OnAccessor | OnConstructor |
LongAttribute,
65)
SIMPLE_DECL_ATTR(GKInspectable, GKInspectable,
OnVar,
66)
DECL_ATTR(_implements, Implements,
// SWIFT_ENABLE_TENSORFLOW
OnFunc | OnAccessor | OnCall | OnVar | OnSubscript | OnTypeAlias |
OnFunc | OnAccessor | OnVar | OnSubscript | OnTypeAlias |
UserInaccessible |
NotSerialized, 67)
DECL_ATTR(_objcRuntimeName, ObjCRuntimeName,
Expand All @@ -369,8 +353,7 @@ DECL_ATTR(_restatedObjCConformance, RestatedObjCConformance,
NotSerialized, 70)
// NOTE: 71 is unused
SIMPLE_DECL_ATTR(_implicitly_unwrapped_optional, ImplicitlyUnwrappedOptional,
// SWIFT_ENABLE_TENSORFLOW
OnFunc | OnAccessor | OnCall | OnVar | OnParam | OnSubscript | OnConstructor |
OnFunc | OnAccessor | OnVar | OnParam | OnSubscript | OnConstructor |
RejectByParser,
72)
DECL_ATTR(_optimize, Optimize,
Expand All @@ -382,8 +365,7 @@ DECL_ATTR(_clangImporterSynthesizedType, ClangImporterSynthesizedType,
LongAttribute | RejectByParser | UserInaccessible |
NotSerialized, 74)
SIMPLE_DECL_ATTR(_weakLinked, WeakLinked,
// SWIFT_ENABLE_TENSORFLOW
OnNominalType | OnAssociatedType | OnFunc | OnAccessor | OnCall | OnVar |
OnNominalType | OnAssociatedType | OnFunc | OnAccessor | OnVar |
OnSubscript | OnConstructor | OnEnumElement | UserInaccessible,
75)
SIMPLE_DECL_ATTR(_frozen, Frozen,
Expand All @@ -399,9 +381,7 @@ SIMPLE_DECL_ATTR(_hasInitialValue, HasInitialValue,
UserInaccessible,
78)
SIMPLE_DECL_ATTR(_nonoverride, NonOverride,
// SWIFT_ENABLE_TENSORFLOW
OnFunc | OnAccessor | OnCall | OnVar | OnSubscript | OnConstructor |
OnAssociatedType |
OnFunc | OnAccessor | OnVar | OnSubscript | OnConstructor | OnAssociatedType |
UserInaccessible | NotSerialized,
79)
DECL_ATTR(_dynamicReplacement, DynamicReplacement,
Expand All @@ -417,8 +397,8 @@ DECL_ATTR(_private, PrivateImport,

// SWIFT_ENABLE_TENSORFLOW
DECL_ATTR(differentiable, Differentiable,
OnAccessor | OnConstructor | OnFunc | OnCall | OnVar | OnSubscript |
LongAttribute | AllowMultipleAttributes,
OnAccessor | OnConstructor | OnFunc | OnVar | OnSubscript | LongAttribute |
AllowMultipleAttributes,
83)
DECL_ATTR(differentiating, Differentiating,
OnFunc | LongAttribute | AllowMultipleAttributes |
Expand Down
80 changes: 10 additions & 70 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ namespace swift {
struct ASTNode;
class ASTPrinter;
class ASTWalker;
// SWIFT_ENABLE_TENSORFLOW
class CallDecl;
class ConstructorDecl;
class DestructorDecl;
class DiagnosticEngine;
Expand Down Expand Up @@ -138,8 +136,6 @@ enum class DescriptiveDeclKind : uint8_t {
GenericStruct,
GenericClass,
GenericType,
// SWIFT_ENABLE_TENSORFLOW
Call,
Subscript,
Constructor,
Destructor,
Expand Down Expand Up @@ -5614,6 +5610,9 @@ class FuncDecl : public AbstractFunctionDecl {
bool isStatic() const {
return Bits.FuncDecl.IsStatic;
}
bool isCallable() const {
return getName().str() == "call" && isInstanceMember();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a IsCallable bit to FuncDecl, instead of checking "callable-ness" on the fly.
That requires further decl/serialization changes - we can make that change after committing our desired func call API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend not doing that, unless this is a particularly hot predicate. Cached bits like this have to be kept in sync with the ast. Also, instead of serializing it, if the bit needs to be stored, it can always be computed in the module reader.

}
/// \returns the way 'static'/'class' was spelled in the source.
StaticSpellingKind getStaticSpelling() const {
return static_cast<StaticSpellingKind>(Bits.FuncDecl.StaticSpelling);
Expand Down Expand Up @@ -5731,9 +5730,7 @@ class FuncDecl : public AbstractFunctionDecl {

static bool classof(const Decl *D) {
return D->getKind() == DeclKind::Func ||
D->getKind() == DeclKind::Accessor ||
// SWIFT_ENABLE_TENSORFLOW
D->getKind() == DeclKind::Call;
D->getKind() == DeclKind::Accessor;
}
static bool classof(const AbstractFunctionDecl *D) {
return classof(static_cast<const Decl*>(D));
Expand Down Expand Up @@ -5886,60 +5883,7 @@ AbstractStorageDecl::AccessorRecord::getAccessor(AccessorKind kind) const {
}
return nullptr;
}

// SWIFT_ENABLE_TENSORFLOW
/// CallDecl - Declares a callable method for a type. For example:
///
/// \code
/// struct Adder {
/// var base: Int
/// call(_ x: Int) -> Int {
/// return base + x
/// }
/// }
/// \endcode
class CallDecl final : public FuncDecl {
CallDecl(DeclName fullName, SourceLoc declLoc, bool throws,
SourceLoc throwsLoc, unsigned numParameterLists,
GenericParamList *genericParams, DeclContext *parent)
: FuncDecl(DeclKind::Call,
/*staticLoc*/ SourceLoc(), StaticSpellingKind::None,
/*func loc*/ declLoc, /*name*/ fullName, /*name loc*/ declLoc,
throws, throwsLoc, numParameterLists, genericParams, parent) {}

static CallDecl *createImpl(ASTContext &ctx, DeclName fullName,
SourceLoc declLoc, bool throws,
SourceLoc throwsLoc,
GenericParamList *genericParams,
DeclContext *parent, ClangNode clangNode);

public:
static CallDecl *createDeserialized(ASTContext &ctx, DeclName name,
SourceLoc declLoc, bool throws,
SourceLoc throwsLoc,
GenericParamList *genericParams,
DeclContext *parent);

static CallDecl *create(ASTContext &ctx, DeclName fullName, SourceLoc declLoc,
bool throws, SourceLoc throwsLoc,
GenericParamList *genericParams,
ParameterList *parameterList,
TypeLoc fnRetType, DeclContext *parent,
ClangNode clangNode = ClangNode());

static bool classof(const Decl *D) {
return D->getKind() == DeclKind::Call;
}
static bool classof(const AbstractFunctionDecl *D) {
return classof(static_cast<const Decl*>(D));
}
static bool classof(const DeclContext *DC) {
if (auto D = DC->getAsDecl())
return classof(D);
return false;
}
};


/// \brief This represents a 'case' declaration in an 'enum', which may declare
/// one or more individual comma-separated EnumElementDecls.
class EnumCaseDecl final : public Decl,
Expand Down Expand Up @@ -6852,8 +6796,6 @@ inline ParamDecl **AbstractFunctionDecl::getImplicitSelfDeclStorage() {
return cast<DestructorDecl>(this)->getImplicitSelfDeclStorage();
case DeclKind::Func:
case DeclKind::Accessor:
// SWIFT_ENABLE_TENSORFLOW
case DeclKind::Call:
return cast<FuncDecl>(this)->getImplicitSelfDeclStorage();
}
}
Expand All @@ -6862,13 +6804,11 @@ inline ParamDecl **FuncDecl::getImplicitSelfDeclStorage() {
if (!hasImplicitSelfDecl())
return nullptr;

if (isa<AccessorDecl>(this))
return reinterpret_cast<ParamDecl **>(static_cast<AccessorDecl *>(this)+1);
// SWIFT_ENABLE_TENSORFLOW
else if (isa<CallDecl>(this))
return reinterpret_cast<ParamDecl **>(static_cast<CallDecl *>(this)+1);
assert(getKind() == DeclKind::Func && "no new kinds of functions");
return reinterpret_cast<ParamDecl **>(this+1);
if (!isa<AccessorDecl>(this)) {
assert(getKind() == DeclKind::Func && "no new kinds of functions");
return reinterpret_cast<ParamDecl **>(this+1);
}
return reinterpret_cast<ParamDecl **>(static_cast<AccessorDecl*>(this)+1);
}

inline DeclIterator &DeclIterator::operator++() {
Expand Down
4 changes: 1 addition & 3 deletions include/swift/AST/DeclNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ ABSTRACT_DECL(Value, Decl)
ABSTRACT_FUNCTION_DECL(Destructor, AbstractFunctionDecl)
ABSTRACT_FUNCTION_DECL(Func, AbstractFunctionDecl)
ABSTRACT_FUNCTION_DECL(Accessor, FuncDecl)
// SWIFT_ENABLE_TENSORFLOW
ABSTRACT_FUNCTION_DECL(Call, FuncDecl)
DECL_RANGE(AbstractFunction, Constructor, Call)
DECL_RANGE(AbstractFunction, Constructor, Accessor)
VALUE_DECL(EnumElement, ValueDecl)
DECL_RANGE(Value, Enum, EnumElement)

Expand Down
13 changes: 0 additions & 13 deletions include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -398,19 +398,6 @@ ERROR(subscript_without_get,none,
ERROR(subscript_static,none,
"subscript cannot be marked %0", (StaticSpellingKind))

// SWIFT_ENABLE_TENSORFLOW
// `call` method
ERROR(call_decl_static,none,
"'call' method cannot be marked %0", (StaticSpellingKind))
ERROR(call_decl_wrong_scope,none,
"'call' methods may only be declared within a type", ())
ERROR(expected_lparen_call,PointsToFirstBadToken,
"expected '(' for 'call' member parameters", ())
ERROR(call_decl_cannot_have_name,PointsToFirstBadToken,
"'call' method cannot have a name", ())
ERROR(call_decl_expected_func_keyword,PointsToFirstBadToken,
"'call' must be followed by 'func'", ())

// initializer
ERROR(invalid_nested_init,none,
"missing '%select{super.|self.}0' at initializer invocation", (bool))
Expand Down
Loading