Skip to content

Commit 948f551

Browse files
author
Dave Abrahams
committed
Merge github/tensorflow into copy of github/master (using imerge)
2 parents 400accb + ce56277 commit 948f551

File tree

347 files changed

+16035
-231
lines changed

Some content is hidden

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

347 files changed

+16035
-231
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# vim swap files
1919
.*.sw[a-z]
2020
.sw?
21+
*.vscode
2122

2223
#==============================================================================#
2324
# Explicit files to ignore (only matches one).

CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ option(SWIFT_BUILD_STDLIB_EXTRA_TOOLCHAIN_CONTENT
8686
"If not building stdlib, controls whether to build 'stdlib/toolchain' content"
8787
TRUE)
8888

89+
# `SWIFT_ENABLE_TENSOFRFLOW` affects lit tests, adding "tensorflow" as an
90+
# available feature.
91+
option(SWIFT_ENABLE_TENSORFLOW
92+
"Enable TensorFlow in the compiler"
93+
FALSE)
94+
8995
# In many cases, the CMake build system needs to determine whether to include
9096
# a directory, or perform other actions, based on whether the stdlib or SDK is
9197
# being built at all -- statically or dynamically. Please note that these
@@ -373,6 +379,19 @@ option(SWIFT_DISABLE_OBJC_INTEROP
373379
"Disable Objective-C interoperability even on platforms what would normally have it"
374380
FALSE)
375381

382+
#
383+
# User-configurable TensorFlow specific options.
384+
#
385+
set(SWIFT_TENSORFLOW_HOST_LIB_DIR "" CACHE PATH
386+
"If set, directory with TensorFlow host libraries to be linked into swiftc.")
387+
set(SWIFT_TENSORFLOW_TARGET_LIB_DIR "" CACHE PATH
388+
"If set, directory with TensorFlow target libraries to be linked into swift programs.")
389+
390+
set(SWIFT_TENSORFLOW_HOST_INCLUDE_DIR "" CACHE PATH
391+
"If set, directory with host TensorFlow headers.")
392+
set(SWIFT_TENSORFLOW_TARGET_INCLUDE_DIR "" CACHE PATH
393+
"If set, directory with target TensorFlow headers.")
394+
376395
#
377396
# User-configurable experimental options. Do not use in production builds.
378397
#
@@ -1084,6 +1103,11 @@ if(SWIFT_BUILD_SYNTAXPARSERLIB OR SWIFT_BUILD_SOURCEKIT)
10841103
endif()
10851104
endif()
10861105

1106+
# Enable TensorFlow in compiler code.
1107+
if(SWIFT_ENABLE_TENSORFLOW)
1108+
add_definitions(-DSWIFT_ENABLE_TENSORFLOW)
1109+
endif()
1110+
10871111
# Add all of the subdirectories, where we actually do work.
10881112

10891113
###############

CONTRIBUTING.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,23 @@ license](https://swift.org/LICENSE.txt).
55

66
---
77

8-
Before submitting the pull request, please make sure you have [tested your
9-
changes](https://github.com/apple/swift/blob/master/docs/ContinuousIntegration.md)
10-
and that they follow the Swift project [guidelines for contributing
11-
code](https://swift.org/contributing/#contributing-code).
8+
Before submitting a pull request, please make sure that your changes follow the
9+
[Swift project guidelines for contributing code](https://swift.org/contributing/#contributing-code).
10+
11+
We request that code changes unrelated to Swift for TensorFlow be submitted to
12+
the [upstream Swift repository](https://github.com/apple/swift). For example,
13+
code formatting changes that do not affect Swift for TensorFlow source code
14+
should be submitted upstream.
15+
16+
It is a good idea to discuss any non-trivial submissions with the project
17+
maintainers before submitting a pull request: please join the
18+
[[email protected]](https://groups.google.com/a/tensorflow.org/d/forum/swift)
19+
mailing list to participate in discussions.
20+
21+
All changes to existing Swift source code should be marked clearly with a
22+
`SWIFT_ENABLE_TENSORFLOW` comment at the top of every diff hunk. This makes
23+
it easier to merge from upstream.
24+
25+
Continuous integration (CI) is still being set up, so if you submit a pull
26+
request with non-trivial changes that require test coverage, please anticipate
27+
some delay before we can properly review and merge it.

README.md

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
<img src="https://swift.org/assets/images/swift.svg" alt="Swift logo" height="70" >
2-
3-
# Swift Programming Language
1+
# Swift for TensorFlow
42

3+
| OS | CI platform | x86_64 | GPU |
4+
|---|:---:|:---:|:---:|
5+
| **macOS** | Google Kokoro | ![Build Status](https://storage.googleapis.com/tensorflow-kokoro-build-badges/macos-swift-tf-release.svg) | - |
6+
| **Ubuntu 16.04** | Swift.org CI | [![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-tensorflow/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-tensorflow) | [![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-tensorflow-gpu/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-tensorflow-gpu) |
57

68
| | **Architecture** | **Master** | **Package** |
79
|---|:---:|:---:|:---:|
@@ -34,6 +36,13 @@
3436
|**[macOS 10.13](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_macos_high_sierra_tensorflow.json)** | x86_64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-macOS-tensorflow/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-macOS-tensorflow)|
3537
|**[Ubuntu 16.04 (GPU)](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_ubuntu_16_04_tensorflow_gpu.json)** | x86_64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-tensorflow-gpu/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-tensorflow-gpu)|
3638

39+
<!-- SWIFT_ENABLE_TENSORFLOW -->
40+
41+
Swift for TensorFlow is a new programming language for TensorFlow. It is a copy of the compiler for the [Swift Programming Language](https://swift.org) that adds first-class compiler and language support for machine learning.
42+
43+
This repository covers the compiler and standard libraries. Please visit the [documentation repository](https://github.com/tensorflow/swift) for more information about the project, including a project overview, technical details, and guidelines for contributing. To use Swift for TensorFlow out of the box, follow the [installation instructions](https://github.com/tensorflow/swift/blob/master/Installation.md). To build from source, follow the instructions below.
44+
<!-- SWIFT_ENABLE_TENSORFLOW END -->
45+
3746
## Welcome to Swift
3847

3948
Swift is a high-performance system programming language. It has a clean
@@ -82,37 +91,36 @@ If you are interested in:
8291

8392
[Getting Started guide]: /docs/HowToGuides/GettingStarted.md
8493

85-
### Swift Toolchains
94+
### Swift For TensorFlow Toolchains
8695

8796
#### Building
8897

89-
Swift toolchains are created using the script
90-
[build-toolchain](https://github.com/apple/swift/blob/master/utils/build-toolchain). This
91-
script is used by swift.org's CI to produce snapshots and can allow for one to
98+
Swift for TensorFlow toolchains are created using the script
99+
[build-toolchain-tensorflow](https://github.com/apple/swift/blob/tensorflow/utils/build-toolchain-tensorflow).
100+
This script is used by swift.org's CI to produce snapshots and can allow for one to
92101
locally reproduce such builds for development or distribution purposes. A typical
93102
invocation looks like the following:
94103

95104
```
96-
$ ./swift/utils/build-toolchain $BUNDLE_PREFIX
105+
$ ./swift/utils/build-toolchain-tensorflow $BUNDLE_PREFIX
97106
```
98107

99-
where ``$BUNDLE_PREFIX`` is a string that will be prepended to the build
100-
date to give the bundle identifier of the toolchain's ``Info.plist``. For
101-
instance, if ``$BUNDLE_PREFIX`` was ``com.example``, the toolchain
102-
produced will have the bundle identifier ``com.example.YYYYMMDD``. It
103-
will be created in the directory you run the script with a filename
104-
of the form: ``swift-LOCAL-YYYY-MM-DD-a-osx.tar.gz``.
108+
where ``$BUNDLE_PREFIX`` is a string that will be prepended to the build
109+
date to give the bundle identifier of the toolchain's ``Info.plist``. For
110+
instance, if ``$BUNDLE_PREFIX`` was ``com.example``, the toolchain
111+
produced will have the bundle identifier ``com.example.YYYYMMDD``. It
112+
will be created in the directory you run the script with a filename
113+
of the form: ``swift-tensorflow-LOCAL-YYYY-MM-DD-a-osx.tar.gz``.
105114

106-
Beyond building the toolchain, ``build-toolchain`` also supports the
107-
following (non-exhaustive) set of useful options::
115+
Beyond building the toolchain, ``build-toolchain-tensorflow`` also supports the
116+
following (non-exhaustive) set of useful options:
108117

109118
- ``--dry-run``: Perform a dry run build. This is off by default.
110119
- ``--test``: Test the toolchain after it has been compiled. This is off by default.
111-
- ``--distcc``: Use distcc to speed up the build by distributing the c++ part of
112-
the swift build. This is off by default.
120+
- ``--pkg`` (macOS only): Build a toolchain installer package (`.pkg`). This is off by default.
113121

114122
More options may be added over time. Please pass ``--help`` to
115-
``build-toolchain`` to see the full set of options.
123+
``build-toolchain-tensorflow`` to see the full set of options.
116124

117125
#### Installing into Xcode
118126

cmake/modules/FindTensorFlow.cmake

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SWIFT_ENABLE_TENSORFLOW
2+
# Find TensorFlow.
3+
4+
include(FindPackageHandleStandardArgs)
5+
6+
find_path(TF_INCLUDE_DIR
7+
NAMES third_party/tensorflow/c tensorflow/c
8+
HINTS ${SWIFT_TENSORFLOW_TARGET_INCLUDE_DIR} /usr/include /usr/local/include)
9+
if (EXISTS ${TF_INCLUDE_DIR}/third_party/tensorflow/c/c_api.h)
10+
# This is experimental and not covered by CI.
11+
set(TF_PATH_ADJUSTMENT "third_party")
12+
else()
13+
# Note: This is the normal workflow.
14+
set(TF_PATH_ADJUSTMENT "")
15+
endif()
16+
17+
find_library(TF_LIBRARY
18+
NAMES tensorflow
19+
HINTS ${SWIFT_TENSORFLOW_TARGET_LIB_DIR} /usr/lib /usr/local/lib)
20+
set(TF_LIBRARIES ${TF_LIBRARY})
21+
22+
find_package_handle_standard_args(TensorFlow DEFAULT_MSG TF_INCLUDE_DIR TF_LIBRARIES)
23+
mark_as_advanced(${TF_INCLUDE_DIR} ${TF_LIBRARIES})

docs/ContinuousIntegration.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,21 @@ This page is designed to assist in the understanding of proper practices for tes
2828

2929
In order for the Swift project to be able to advance quickly, it is important that we maintain a green build [[1]](#footnote-1). In order to help maintain this green build, the Swift project heavily uses pull request (PR) testing. Specifically, an important general rule is that **all** non-trivial checkins to any Swift Project repository should at least perform a [smoke test](#smoke-testing) if simulators will not be impacted *or* a full [validation test](#validation-testing) if simulators may be impacted. If in addition one is attempting to make a source breaking change across multiple repositories, one should follow the cross repo source breaking changes workflow. We now continue by describing the Swift system for Pull Request testing, @swift-ci:
3030

31-
### @swift-ci
31+
### @swift-ci (Swift for TensorFlow)
32+
33+
34+
Platform | Comment
35+
------------ | -------
36+
All supported platforms | @swift-ci Please test tensorflow
37+
All supported platforms | @swift-ci Please clean test tensorflow
38+
Linux | @swift-ci Please test tensorflow Linux
39+
Linux GPU | @swift-ci Please test tensorflow Linux GPU
40+
macOS | @swift-ci Please test tensorflow macOS
41+
42+
Status can be checked at https://ci-external.swift.org/view/Pull%20Request/.
43+
44+
45+
### @swift-ci (general Swift)
3246

3347
Users with [commit access](https://swift.org/contributing/#commit-access) can trigger pull request testing by writing a comment on a PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment used. The current test types are:
3448

include/swift/AST/ASTContext.h

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ class ASTContext final {
296296

297297
/// Cached mapping from types to their associated tangent spaces.
298298
llvm::DenseMap<Type, Optional<TangentSpace>> AutoDiffTangentSpaces;
299-
299+
300300
/// A cache of derivative function types per configuration.
301301
llvm::DenseMap<SILAutoDiffDerivativeFunctionKey, CanSILFunctionType>
302302
SILAutoDiffDerivativeFunctions;
@@ -309,8 +309,10 @@ class ASTContext final {
309309
/// Cache of `@derivative` attributes keyed by parameter indices and
310310
/// derivative function kind. Used to diagnose duplicate `@derivative`
311311
/// attributes for the same key.
312-
// TODO(TF-1042): remove `DerivativeAttrs` from `ASTContext`. Serialize
313-
// derivative function configurations per original `AbstractFunctionDecl`.
312+
// NOTE(TF-680): relaxing the uniqueness condition to use derivative generic
313+
// signature as a key is possible. It requires derivative generic signature
314+
// mangling to avoid name collisions for SIL derivative functions with the
315+
// same parameter indices but different derivative generic signatures.
314316
llvm::DenseMap<
315317
std::tuple<Decl *, IndexSubset *, AutoDiffDerivativeFunctionKind>,
316318
llvm::SmallPtrSet<DerivativeAttr *, 1>>
@@ -336,6 +338,7 @@ class ASTContext final {
336338
/// Cache of module names that fail the 'canImport' test in this context.
337339
llvm::SmallPtrSet<Identifier, 8> FailedModuleImportNames;
338340

341+
public:
339342
/// Retrieve the allocator for the given arena.
340343
llvm::BumpPtrAllocator &
341344
getAllocator(AllocationArena arena = AllocationArena::Permanent) const;
@@ -485,6 +488,35 @@ class ASTContext final {
485488
/// Retrieve the type Swift.AnyObject.
486489
CanType getAnyObjectType() const;
487490

491+
// SWIFT_ENABLE_TENSORFLOW
492+
/// Retrieve the decl for TensorFlow.TensorHandle iff the TensorFlow module
493+
/// has been imported. Otherwise, this returns null.
494+
ClassDecl *getTensorHandleDecl() const;
495+
496+
/// Retrieve the decl for TensorFlow.TensorShape iff the TensorFlow module
497+
/// has been imported. Otherwise, this returns null.
498+
StructDecl *getTensorShapeDecl() const;
499+
500+
/// Retrieve the decl for TensorFlow.TensorDataType iff the TensorFlow module
501+
/// has been imported. Otherwise, this returns null.
502+
StructDecl *getTensorDataTypeDecl() const;
503+
504+
/// Retrieve the decl for the Quote module iff it has been imported.
505+
/// Otherwise, this returns null.
506+
ModuleDecl *getQuoteModule() const;
507+
508+
/// Retrieve the decl for Quote.Tree iff the Quote module has been imported.
509+
/// Otherwise, this returns null.
510+
ProtocolDecl *getTreeDecl() const;
511+
512+
/// Retrieve the decl for Quote.Quote iff the Quote module has been imported.
513+
/// Otherwise, this returns null.
514+
ClassDecl *getQuoteDecl() const;
515+
516+
/// Retrieve the decl for Quote.FunctionQuoteN iff the Quote module has been
517+
/// imported. Otherwise, this returns null.
518+
ClassDecl *getFunctionQuoteDecl(unsigned n) const;
519+
488520
/// Retrieve the type Swift.Never.
489521
CanType getNeverType() const;
490522

include/swift/AST/ASTMangler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ class ASTMangler : public Mangler {
342342
/// \returns \c true if a generic signature was appended, \c false
343343
/// if it was empty.
344344
bool appendGenericSignature(GenericSignature sig,
345-
GenericSignature contextSig = nullptr);
345+
GenericSignature contextSig = GenericSignature());
346346

347347
void appendRequirement(const Requirement &reqt);
348348

include/swift/AST/Attr.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,13 @@ SIMPLE_DECL_ATTR(asyncHandler, AsyncHandler,
566566
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
567567
101)
568568

569+
// SWIFT_ENABLE_TENSORFLOW
570+
SIMPLE_DECL_ATTR(compilerEvaluable, CompilerEvaluable,
571+
OnAccessor | OnFunc | OnConstructor | OnSubscript |
572+
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove |
573+
NotSerialized, 102)
574+
// SWIFT_ENABLE_TENSORFLOW END
575+
569576
#undef TYPE_ATTR
570577
#undef DECL_ATTR_ALIAS
571578
#undef CONTEXTUAL_DECL_ATTR_ALIAS

include/swift/AST/Attr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Decl;
5151
class AbstractFunctionDecl;
5252
class FuncDecl;
5353
class ClassDecl;
54+
class FuncDecl;
5455
class GenericFunctionType;
5556
class LazyConformanceLoader;
5657
class LazyMemberLoader;

include/swift/AST/Decl.h

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3502,6 +3502,20 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
35023502
/// Retrieve information about this type as a property wrapper.
35033503
PropertyWrapperTypeInfo getPropertyWrapperTypeInfo() const;
35043504

3505+
private:
3506+
/// Predicate used to filter StoredPropertyRange.
3507+
struct ToStoredProperty {
3508+
ToStoredProperty(bool skipInaccessible = false) :
3509+
skipUserInaccessible(skipInaccessible) {}
3510+
bool skipUserInaccessible;
3511+
Optional<VarDecl *> operator()(Decl *decl) const;
3512+
};
3513+
3514+
public:
3515+
/// A range for iterating the stored member variables of a structure.
3516+
using StoredPropertyRange = OptionalTransformRange<DeclRange,
3517+
ToStoredProperty>;
3518+
35053519
/// Return a collection of the stored member variables of this type.
35063520
ArrayRef<VarDecl *> getStoredProperties() const;
35073521

@@ -4198,6 +4212,15 @@ enum class KnownDerivableProtocolKind : uint8_t {
41984212
Decodable,
41994213
AdditiveArithmetic,
42004214
Differentiable,
4215+
// SWIFT_ENABLE_TENSORFLOW
4216+
PointwiseMultiplicative,
4217+
ElementaryFunctions,
4218+
KeyPathIterable,
4219+
TensorArrayProtocol,
4220+
TensorGroup,
4221+
VectorProtocol,
4222+
EuclideanDifferentiable,
4223+
// SWIFT_ENABLE_TENSORFLOW END
42014224
};
42024225

42034226
/// ProtocolDecl - A declaration of a protocol, for example:
@@ -6586,8 +6609,9 @@ AbstractStorageDecl::AccessorRecord::getAccessor(AccessorKind kind) const {
65866609

65876610
/// This represents a 'case' declaration in an 'enum', which may declare
65886611
/// one or more individual comma-separated EnumElementDecls.
6589-
class EnumCaseDecl final : public Decl,
6590-
private llvm::TrailingObjects<EnumCaseDecl, EnumElementDecl *> {
6612+
class EnumCaseDecl final
6613+
: public Decl,
6614+
private llvm::TrailingObjects<EnumCaseDecl, EnumElementDecl *> {
65916615
friend TrailingObjects;
65926616
friend class Decl;
65936617
SourceLoc CaseLoc;

include/swift/AST/DiagnosticsDriver.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,5 +190,12 @@ WARNING(warn_drv_darwin_sdk_invalid_settings, none,
190190
"SDK settings were ignored because 'SDKSettings.json' could not be parsed",
191191
())
192192

193+
// SWIFT_ENABLE_TENSORFLOW
194+
ERROR(error_tensorflow_toolchain_repl_not_supported, none,
195+
"The Swift for TensorFlow toolchain does not support the Swift REPL. Colab "
196+
"(https://github.com/tensorflow/swift/blob/master/Usage.md#colaboratory) and Swift-Jupyter "
197+
"(https://github.com/google/swift-jupyter) are supported alternatives.",
198+
())
199+
193200
#define UNDEFINE_DIAGNOSTIC_MACROS
194201
#include "DefineDiagnosticMacros.h"

include/swift/AST/DiagnosticsParse.def

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,5 +1765,22 @@ ERROR(expected_closure_literal,none,
17651765
ERROR(expected_multiple_closures_block_rbrace,none,
17661766
"expected '}' at the end of a trailing closures block", ())
17671767

1768+
// SWIFT_ENABLE_TENSORFLOW
1769+
ERROR(sil_const_expected_int_datatype,PointsToFirstBadToken,
1770+
"expected integer datatype ('i[0-9]+', e.g. 'i32')", ())
1771+
ERROR(sil_const_expected_int_value,PointsToFirstBadToken,
1772+
"expected integer value in SIL constant value", ())
1773+
ERROR(sil_const_expected_fp_datatype,PointsToFirstBadToken,
1774+
"expected floating point datatype ('f32' or 'f64')", ())
1775+
ERROR(sil_const_expected_fp_value,PointsToFirstBadToken,
1776+
"expected floating point value in SIL constant value", ())
1777+
ERROR(sil_const_array_expected_rsquare,PointsToFirstBadToken,
1778+
"expected ']' at end of array 'SymbolicValue'", ())
1779+
ERROR(sil_const_aggregate_expected_rparen,PointsToFirstBadToken,
1780+
"expected ')' at end of aggregate 'SymbolicValue'", ())
1781+
ERROR(sil_const_expected_fn_sub_conv,PointsToFirstBadToken,
1782+
"expected '(N)' or '(W)' function substitution convention", ())
1783+
// SWIFT_ENABLE_TENSORFLOW END
1784+
17681785
#define UNDEFINE_DIAGNOSTIC_MACROS
17691786
#include "DefineDiagnosticMacros.h"

0 commit comments

Comments
 (0)