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

// SWIFT_ENABLE_TENSORFLOW
DECL_ATTR(differentiable, Differentiable,
OnAccessor | OnConstructor | OnFunc | OnVar | OnSubscript | LongAttribute |
AllowMultipleAttributes,
OnAccessor | OnConstructor | OnFunc | OnCall | OnVar | OnSubscript |
LongAttribute | AllowMultipleAttributes,
83)
DECL_ATTR(differentiating, Differentiating,
OnFunc | LongAttribute | AllowMultipleAttributes |
Expand Down
71 changes: 64 additions & 7 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ namespace swift {
struct ASTNode;
class ASTPrinter;
class ASTWalker;
// SWIFT_ENABLE_TENSORFLOW
class CallDecl;
class ConstructorDecl;
class DestructorDecl;
class DiagnosticEngine;
Expand Down Expand Up @@ -136,6 +138,8 @@ enum class DescriptiveDeclKind : uint8_t {
GenericStruct,
GenericClass,
GenericType,
// SWIFT_ENABLE_TENSORFLOW
Call,
Subscript,
Constructor,
Destructor,
Expand Down Expand Up @@ -5727,7 +5731,9 @@ class FuncDecl : public AbstractFunctionDecl {

static bool classof(const Decl *D) {
return D->getKind() == DeclKind::Func ||
D->getKind() == DeclKind::Accessor;
D->getKind() == DeclKind::Accessor ||
// SWIFT_ENABLE_TENSORFLOW
D->getKind() == DeclKind::Call;
}
static bool classof(const AbstractFunctionDecl *D) {
return classof(static_cast<const Decl*>(D));
Expand Down Expand Up @@ -5880,7 +5886,54 @@ 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 *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 @@ -6793,6 +6846,8 @@ 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 @@ -6801,11 +6856,13 @@ inline ParamDecl **FuncDecl::getImplicitSelfDeclStorage() {
if (!hasImplicitSelfDecl())
return nullptr;

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);
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);
}

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

Expand Down
13 changes: 13 additions & 0 deletions include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,19 @@ 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
25 changes: 17 additions & 8 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ NOTE(archetype_declared_in_type,none,
NOTE(unbound_generic_parameter_explicit_fix,none,
"explicitly specify the generic arguments to fix this issue", ())

// SWIFT_ENABLE_TENSORFLOW
ERROR(invalid_dynamic_callable_type,none,
"@dynamicCallable attribute requires %0 to have either a valid "
"'dynamicallyCall(withArguments:)' method or "
Expand Down Expand Up @@ -1689,15 +1690,17 @@ ERROR(witness_requires_class_implementation,none,
(DeclName, Type))
ERROR(witness_not_accessible_proto,none,
"%select{initializer %1|method %1|%select{|setter for }2property %1"
"|subscript%select{| setter}2}0 must be declared "
// SWIFT_ENABLE_TENSORFLOW
"|subscript%select{| setter}2|'call' method}0 must be declared "
"%select{%error|fileprivate|internal|public|%error}3 because it matches a "
"requirement in %select{private|fileprivate|internal|public|%error}4 protocol "
"%5",
(RequirementKind, DeclName, bool, AccessLevel, AccessLevel, DeclName))
ERROR(witness_not_accessible_type,none,
"%select{initializer %1|method %1|%select{|setter for }2property %1"
"|subscript%select{| setter}2}0 must be as accessible as its enclosing "
"type because it matches a requirement in protocol %5",
// SWIFT_ENABLE_TENSORFLOW
"|subscript%select{| setter}2|'call' method}0 must be as accessible as "
"its enclosing type because it matches a requirement in protocol %5",
(RequirementKind, DeclName, bool, AccessLevel, AccessLevel, DeclName))
ERROR(type_witness_not_accessible_proto,none,
"%0 %1 must be declared %select{%error|fileprivate|internal|public|%error}2 "
Expand Down Expand Up @@ -1761,19 +1764,24 @@ NOTE(inherited_protocol_does_not_conform,none,
"type %0 does not conform to inherited protocol %1", (Type, Type))
NOTE(no_witnesses,none,
"protocol requires "
"%select{initializer %1|function %1|property %1|subscript}0 with type %2"
"%select{|; do you want to add a stub?}3",
// SWIFT_ENABLE_TENSORFLOW
"%select{initializer %1|function %1|property %1|subscript|'call' method}0 "
"with type %2%select{|; do you want to add a stub?}3",
(RequirementKind, DeclName, Type, bool))
NOTE(missing_witnesses_general,none, "do you want to add protocol stubs?",
())
NOTE(ambiguous_witnesses,none,
"multiple matching "
"%select{initializers named %1|functions named %1|properties named %1|"
"subscript operators}0 with type %2", (RequirementKind, DeclName, Type))
// SWIFT_ENABLE_TENSORFLOW
"subscript operators|'call' method}0 with type %2",
(RequirementKind, DeclName, Type))
NOTE(ambiguous_witnesses_wrong_name,none,
"multiple matching "
"%select{initializers named %1|functions named %1|properties named %1|"
"subscript operators}0 with type %2", (RequirementKind, DeclName, Type))
// SWIFT_ENABLE_TENSORFLOW
"subscript operators|'call' method}0 with type %2",
(RequirementKind, DeclName, Type))
NOTE(no_witnesses_type,none,
"protocol requires nested type %0; do you want to add it?", (Identifier))
NOTE(default_associated_type_req_fail,none,
Expand Down Expand Up @@ -1837,7 +1845,8 @@ NOTE(protocol_witness_renamed,none,
"rename to %0 to satisfy this requirement%1", (DeclName, StringRef))
NOTE(protocol_witness_kind_conflict,none,
"candidate is not %select{an initializer|a function|a variable|"
"a subscript}0", (RequirementKind))
// SWIFT_ENABLE_TENSORFLOW
"a subscript|a 'call' method}0", (RequirementKind))
NOTE(protocol_witness_type_conflict,none,
"candidate has non-matching type %0%1", (Type, StringRef))
NOTE(protocol_witness_missing_requirement,none,
Expand Down
4 changes: 3 additions & 1 deletion include/swift/AST/DiagnosticsSema.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ namespace swift {
Constructor,
Func,
Var,
Subscript
Subscript,
// SWIFT_ENABLE_TENSORFLOW
Call
};

// Declare common diagnostics objects with their appropriate types.
Expand Down
Loading