Skip to content

Commit 779e35f

Browse files
authored
Merge pull request #28924 from apple/tensorflow-merge
Merge tag 'swift-DEVELOPMENT-SNAPSHOT-2019-12-20-a' into tensorflow
2 parents bba00c6 + a34e259 commit 779e35f

File tree

271 files changed

+8621
-3593
lines changed

Some content is hidden

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

271 files changed

+8621
-3593
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Amr Aboelela <[email protected]> <[email protected]>
88
99
Argyrios Kyrtzidis <[email protected]> <[email protected]>
1010
11+
1112
Ben Cohen <[email protected]>
1213
1314

CMakeLists.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -970,10 +970,16 @@ if(SWIFT_BUILD_SYNTAXPARSERLIB OR SWIFT_BUILD_SOURCEKIT)
970970
set(SWIFT_LIBDISPATCH_CXX_COMPILER ${CMAKE_CXX_COMPILER})
971971
elseif(${CMAKE_SYSTEM_NAME} STREQUAL ${CMAKE_HOST_SYSTEM_NAME})
972972
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
973-
set(SWIFT_LIBDISPATCH_C_COMPILER
974-
$<TARGET_FILE_DIR:clang>/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
975-
set(SWIFT_LIBDISPATCH_CXX_COMPILER
976-
$<TARGET_FILE_DIR:clang>/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
973+
if(CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR AND
974+
TARGET clang)
975+
set(SWIFT_LIBDISPATCH_C_COMPILER
976+
$<TARGET_FILE_DIR:clang>/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
977+
set(SWIFT_LIBDISPATCH_CXX_COMPILER
978+
$<TARGET_FILE_DIR:clang>/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
979+
else()
980+
set(SWIFT_LIBDISPATCH_C_COMPILER clang-cl${CMAKE_EXECUTABLE_SUFFIX})
981+
set(SWIFT_LIBDISPATCH_CXX_COMPILER clang-cl${CMAKE_EXECUTABLE_SUFFIX})
982+
endif()
977983
else()
978984
set(SWIFT_LIBDISPATCH_C_COMPILER $<TARGET_FILE_DIR:clang>/clang)
979985
set(SWIFT_LIBDISPATCH_CXX_COMPILER $<TARGET_FILE_DIR:clang>/clang++)

include/swift/AST/ASTContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ class ASTContext final {
313313
// same parameter indices but different derivative generic signatures.
314314
llvm::DenseMap<
315315
std::tuple<Decl *, IndexSubset *, AutoDiffDerivativeFunctionKind>,
316-
DerivativeAttr *>
316+
llvm::SmallPtrSet<DerivativeAttr *, 1>>
317317
DerivativeAttrs;
318318

319319
private:

include/swift/AST/ASTScope.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,10 @@ class ASTScopeImpl {
479479
/// asked.
480480
virtual Optional<NullablePtr<DeclContext>> computeSelfDCForParent() const;
481481

482+
/// Returns the context that should be used when a nested scope (e.g. a
483+
/// closure) captures self explicitly.
484+
virtual NullablePtr<DeclContext> capturedSelfDC() const;
485+
482486
protected:
483487
/// Find either locals or members (no scope has both)
484488
/// \param history The scopes visited since the start of lookup (including
@@ -692,6 +696,15 @@ class Portion {
692696
/// to compute the selfDC from the history.
693697
static NullablePtr<DeclContext>
694698
computeSelfDC(ArrayRef<const ASTScopeImpl *> history);
699+
700+
/// If we find a lookup result that requires the dynamic implict self value,
701+
/// we need to check the nested scopes to see if any closures explicitly
702+
/// captured \c self. In that case, the appropriate selfDC is that of the
703+
/// innermost closure which captures a \c self value from one of this type's
704+
/// methods.
705+
static NullablePtr<DeclContext>
706+
checkNestedScopesForSelfCapture(ArrayRef<const ASTScopeImpl *> history,
707+
size_t start);
695708
};
696709

697710
/// Behavior specific to representing the trailing where clause of a
@@ -1449,6 +1462,13 @@ class ClosureParametersScope final : public AbstractClosureScope {
14491462
std::string getClassName() const override;
14501463
SourceRange
14511464
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
1465+
1466+
/// Since explicit captures of \c self by closures enable the use of implicit
1467+
/// \c self, we need to make sure that the appropriate \c self is used as the
1468+
/// base decl for these uses (otherwise, the capture would be marked as
1469+
/// unused. \c ClosureParametersScope::capturedSelfDC() checks if we have such
1470+
/// a capture of self.
1471+
NullablePtr<DeclContext> capturedSelfDC() const override;
14521472

14531473
protected:
14541474
ASTScopeImpl *expandSpecifically(ScopeCreator &) override;

include/swift/AST/Attr.def

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ TYPE_ATTR(noDerivative)
5757
TYPE_ATTR(autodiff)
5858
TYPE_ATTR(nondiff)
5959
TYPE_ATTR(quoted)
60+
// SWIFT_ENABLE_TENSORFLOW END
6061

6162
// SIL-specific attributes
6263
TYPE_ATTR(block_storage)
@@ -545,27 +546,28 @@ DECL_ATTR(_implicitly_synthesizes_nested_requirement, ImplicitlySynthesizesNeste
545546
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
546547
98)
547548

549+
DECL_ATTR(transpose, Transpose,
550+
OnFunc | LongAttribute | AllowMultipleAttributes |
551+
ABIStableToAdd | ABIBreakingToRemove | APIStableToAdd | APIBreakingToRemove,
552+
99)
553+
548554
// SWIFT_ENABLE_TENSORFLOW
549555
DECL_ATTR(quoted, Quoted,
550556
OnFunc |
551557
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
552-
99)
558+
100)
553559
// TODO(TF-999): Remove deprecated `@differentiating` attribute.
554560
DECL_ATTR(differentiating, Differentiating,
555561
OnFunc | LongAttribute | AllowMultipleAttributes |
556562
ABIStableToAdd | ABIBreakingToRemove | APIStableToAdd | APIBreakingToRemove,
557-
100)
563+
101)
558564
SIMPLE_DECL_ATTR(compilerEvaluable, CompilerEvaluable,
559565
OnAccessor | OnFunc | OnConstructor | OnSubscript |
560566
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove |
561-
NotSerialized, 101)
567+
NotSerialized, 102)
562568
SIMPLE_DECL_ATTR(noDerivative, NoDerivative,
563569
OnVar |
564570
ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,
565-
102)
566-
DECL_ATTR(transpose, Transpose,
567-
OnFunc | LongAttribute | AllowMultipleAttributes |
568-
ABIStableToAdd | ABIBreakingToRemove | APIStableToAdd | APIBreakingToRemove,
569571
103)
570572
// SWIFT_ENABLE_TENSORFLOW END
571573

include/swift/AST/Attr.h

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,8 @@ class OriginallyDefinedInAttr: public DeclAttribute {
16261626
/// Indicates when the symbol was moved here.
16271627
const llvm::VersionTuple MovedVersion;
16281628

1629+
/// Returns true if this attribute is active given the current platform.
1630+
bool isActivePlatform(const ASTContext &ctx) const;
16291631
static bool classof(const DeclAttribute *DA) {
16301632
return DA->getKind() == DAK_OriginallyDefinedIn;
16311633
}
@@ -1844,19 +1846,19 @@ class DifferentiableAttr final
18441846
}
18451847
};
18461848

1847-
/// The `@derivative` attribute registers a function as a derivative of another
1848-
/// function-like declaration: a 'func', 'init', 'subscript', or 'var' computed
1849-
/// property declaration.
1849+
/// The `@derivative(of:)` attribute registers a function as a derivative of
1850+
/// another function-like declaration: a 'func', 'init', 'subscript', or 'var'
1851+
/// computed property declaration.
18501852
///
1851-
/// The `@derivative` attribute also has an optional `wrt:` clause specifying
1852-
/// the parameters that are differentiated "with respect to", i.e. the
1853-
/// differentiation parameters. The differentiation parameters must conform to
1854-
/// the `Differentiable` protocol.
1853+
/// The `@derivative(of:)` attribute also has an optional `wrt:` clause
1854+
/// specifying the parameters that are differentiated "with respect to", i.e.
1855+
/// the differentiation parameters. The differentiation parameters must conform
1856+
/// to the `Differentiable` protocol.
18551857
///
18561858
/// If the `wrt:` clause is unspecified, the differentiation parameters are
18571859
/// inferred to be all parameters that conform to `Differentiable`.
18581860
///
1859-
/// `@derivative` attribute type-checking verifies that the type of the
1861+
/// `@derivative(of:)` attribute type-checking verifies that the type of the
18601862
/// derivative function declaration is consistent with the type of the
18611863
/// referenced original declaration and the differentiation parameters.
18621864
///
@@ -1868,6 +1870,11 @@ class DerivativeAttr final
18681870
private llvm::TrailingObjects<DerivativeAttr, ParsedAutoDiffParameter> {
18691871
friend TrailingObjects;
18701872

1873+
/// The base type repr for the referenced original function. This field is
1874+
/// non-null only for parsed attributes that reference a qualified original
1875+
/// declaration. This field is not serialized; type-checking uses it to
1876+
/// resolve the original declaration, which is serialized.
1877+
TypeRepr *BaseTypeRepr;
18711878
/// The original function name.
18721879
DeclNameRefWithLoc OriginalFunctionName;
18731880
/// The original function declaration, resolved by the type checker.
@@ -1880,23 +1887,27 @@ class DerivativeAttr final
18801887
Optional<AutoDiffDerivativeFunctionKind> Kind = None;
18811888

18821889
explicit DerivativeAttr(bool implicit, SourceLoc atLoc, SourceRange baseRange,
1883-
DeclNameRefWithLoc original,
1890+
TypeRepr *baseTypeRepr, DeclNameRefWithLoc original,
18841891
ArrayRef<ParsedAutoDiffParameter> params);
18851892

18861893
explicit DerivativeAttr(bool implicit, SourceLoc atLoc, SourceRange baseRange,
1887-
DeclNameRefWithLoc original, IndexSubset *indices);
1894+
TypeRepr *baseTypeRepr, DeclNameRefWithLoc original,
1895+
IndexSubset *parameterIndices);
18881896

18891897
public:
18901898
static DerivativeAttr *create(ASTContext &context, bool implicit,
18911899
SourceLoc atLoc, SourceRange baseRange,
1900+
TypeRepr *baseTypeRepr,
18921901
DeclNameRefWithLoc original,
18931902
ArrayRef<ParsedAutoDiffParameter> params);
18941903

18951904
static DerivativeAttr *create(ASTContext &context, bool implicit,
18961905
SourceLoc atLoc, SourceRange baseRange,
1906+
TypeRepr *baseTypeRepr,
18971907
DeclNameRefWithLoc original,
1898-
IndexSubset *indices);
1908+
IndexSubset *parameterIndices);
18991909

1910+
TypeRepr *getBaseTypeRepr() const { return BaseTypeRepr; }
19001911
DeclNameRefWithLoc getOriginalFunctionName() const {
19011912
return OriginalFunctionName;
19021913
}
@@ -1940,12 +1951,19 @@ class DerivativeAttr final
19401951
// SWIFT_ENABLE_TENSORFLOW
19411952
// TODO(TF-999): Remove deprecated `@differentiating` attribute.
19421953
using DifferentiatingAttr = DerivativeAttr;
1954+
// SWIFT_ENABLE_TENSORFLOW END
19431955

1944-
/// Attribute that registers a function as a transpose of another function.
1956+
/// The `@transpose(of:)` attribute registers a function as a transpose of
1957+
/// another function-like declaration: a 'func', 'init', 'subscript', or 'var'
1958+
/// computed property declaration.
1959+
///
1960+
/// The `@transpose(of:)` attribute also has a `wrt:` clause specifying the
1961+
/// parameters that are transposed "with respect to", i.e. the transposed
1962+
/// parameters.
19451963
///
19461964
/// Examples:
19471965
/// @transpose(of: foo)
1948-
/// @transpose(of: +, wrt: (lhs, rhs))
1966+
/// @transpose(of: +, wrt: (0, 1))
19491967
class TransposeAttr final
19501968
: public DeclAttribute,
19511969
private llvm::TrailingObjects<TransposeAttr, ParsedAutoDiffParameter> {
@@ -1966,23 +1984,23 @@ class TransposeAttr final
19661984
IndexSubset *ParameterIndices = nullptr;
19671985

19681986
explicit TransposeAttr(bool implicit, SourceLoc atLoc, SourceRange baseRange,
1969-
TypeRepr *baseTypeRepr, DeclNameRefWithLoc original,
1987+
TypeRepr *baseType, DeclNameRefWithLoc original,
19701988
ArrayRef<ParsedAutoDiffParameter> params);
19711989

19721990
explicit TransposeAttr(bool implicit, SourceLoc atLoc, SourceRange baseRange,
1973-
TypeRepr *baseTypeRepr, DeclNameRefWithLoc original,
1974-
IndexSubset *indices);
1991+
TypeRepr *baseType, DeclNameRefWithLoc original,
1992+
IndexSubset *parameterIndices);
19751993

19761994
public:
19771995
static TransposeAttr *create(ASTContext &context, bool implicit,
19781996
SourceLoc atLoc, SourceRange baseRange,
1979-
TypeRepr *baseTypeRepr, DeclNameRefWithLoc original,
1997+
TypeRepr *baseType, DeclNameRefWithLoc original,
19801998
ArrayRef<ParsedAutoDiffParameter> params);
19811999

19822000
static TransposeAttr *create(ASTContext &context, bool implicit,
19832001
SourceLoc atLoc, SourceRange baseRange,
1984-
TypeRepr *baseTypeRepr, DeclNameRefWithLoc original,
1985-
IndexSubset *indices);
2002+
TypeRepr *baseType, DeclNameRefWithLoc original,
2003+
IndexSubset *parameterIndices);
19862004

19872005
TypeRepr *getBaseTypeRepr() const { return BaseTypeRepr; }
19882006
DeclNameRefWithLoc getOriginalFunctionName() const {
@@ -2018,7 +2036,6 @@ class TransposeAttr final
20182036
return DA->getKind() == DAK_Transpose;
20192037
}
20202038
};
2021-
// SWIFT_ENABLE_TENSORFLOW END
20222039

20232040
/// Attributes that may be applied to declarations.
20242041
class DeclAttributes {

include/swift/AST/Builtins.def

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,10 @@ BUILTIN_MISC_OPERATION(PoundAssert, "poundAssert", "", Special)
654654

655655
/// globalStringTablePointer has type String -> Builtin.RawPointer.
656656
/// It returns an immortal, global string table pointer for strings constructed
657-
/// from string literals.
658-
BUILTIN_MISC_OPERATION_WITH_SILGEN(GlobalStringTablePointer, "globalStringTablePointer", "", Special)
657+
/// from string literals. We consider it effects as readnone meaning that it
658+
/// does not read any memory (note that even though it reads from a string, it
659+
/// is a pure value and therefore we can consider it as readnone).
660+
BUILTIN_MISC_OPERATION_WITH_SILGEN(GlobalStringTablePointer, "globalStringTablePointer", "n", Special)
659661

660662
#undef BUILTIN_MISC_OPERATION_WITH_SILGEN
661663

0 commit comments

Comments
 (0)