Skip to content

Commit c79b73f

Browse files
authored
---
yaml --- r: 339647 b: refs/heads/rxwei-patch-1 c: b20dcc5 h: refs/heads/master i: 339645: 817fd2b 339643: 55d5987 339639: e7a1010 339631: a316d08 339615: 2886e2a 339583: 157ae1a
1 parent 2f9cdbf commit c79b73f

File tree

12 files changed

+100
-125
lines changed

12 files changed

+100
-125
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-08-18-a: b10b1fce14385faa6d44f6b933e95
10151015
refs/heads/rdar-43033749-fix-batch-mode-no-diags-swift-5.0-branch: a14e64eaad30de89f0f5f0b2a782eed7ecdcb255
10161016
refs/heads/revert-19006-error-bridging-integer-type: 8a9065a3696535305ea53fe9b71f91cbe6702019
10171017
refs/heads/revert-19050-revert-19006-error-bridging-integer-type: ecf752d54b05dd0a20f510f0bfa54a3fec3bcaca
1018-
refs/heads/rxwei-patch-1: b17b7665229ea12938603a03d7295351c065654b
1018+
refs/heads/rxwei-patch-1: b20dcc5cac452745cfc936193ca455f97dfff4e6
10191019
refs/heads/shahmishal-patch-1: e58ec0f7488258d42bef51bc3e6d7b3dc74d7b2a
10201020
refs/heads/typelist-existential: 4046359efd541fb5c72d69a92eefc0a784df8f5e
10211021
refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-20-a: 4319ba09e4fb8650ee86061075c74a016b6baab9

branches/rxwei-patch-1/include/swift/AST/KnownIdentifiers.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ IDENTIFIER(withArguments)
118118
IDENTIFIER(withKeywordArguments)
119119

120120
// SWIFT_ENABLE_TENSORFLOW
121-
IDENTIFIER(TensorFlow)
122121
// KeyPathIterable
123122
IDENTIFIER(AllKeyPaths)
124123
IDENTIFIER(allKeyPaths)

branches/rxwei-patch-1/include/swift/AST/KnownProtocols.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ PROTOCOL(FloatingPoint)
8383
PROTOCOL(KeyPathIterable)
8484
PROTOCOL(TensorArrayProtocol)
8585
PROTOCOL(TensorGroup)
86-
PROTOCOL_(TensorFlowDataTypeCompatible)
87-
PROTOCOL(TensorProtocol)
8886
PROTOCOL(VectorNumeric)
8987
PROTOCOL(Differentiable)
9088

branches/rxwei-patch-1/lib/AST/ASTContext.cpp

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -807,62 +807,20 @@ CanType ASTContext::getAnyObjectType() const {
807807
}
808808

809809
// SWIFT_ENABLE_TENSORFLOW
810-
/// Retrieve the decl for TensorFlow.TensorHandle iff the TensorFlow module has
811-
/// been imported. Otherwise, this returns null.
812-
ClassDecl *ASTContext::getTensorHandleDecl() const {
813-
if (getImpl().TensorHandleDecl)
814-
return getImpl().TensorHandleDecl;
815-
816-
// See if the TensorFlow module was imported. If not, return null.
817-
auto tfModule = getLoadedModule(Id_TensorFlow);
818-
if (!tfModule)
819-
return nullptr;
820-
821-
SmallVector<ValueDecl *, 1> results;
822-
tfModule->lookupValue({ }, getIdentifier("TensorHandle"),
823-
NLKind::UnqualifiedLookup, results);
824-
825-
for (auto result : results)
826-
if (auto CD = dyn_cast<ClassDecl>(result))
827-
return getImpl().TensorHandleDecl = CD;
828-
return nullptr;
829-
}
830-
831-
/// Retrieve the decl for TensorFlow.TensorShape iff the TensorFlow module has
832-
/// been imported. Otherwise, this returns null.
833-
StructDecl *ASTContext::getTensorShapeDecl() const {
834-
if (getImpl().TensorShapeDecl)
835-
return getImpl().TensorShapeDecl;
836-
837-
// See if the TensorFlow module was imported. If not, return null.
838-
auto tfModule = getLoadedModule(Id_TensorFlow);
839-
if (!tfModule)
840-
return nullptr;
841-
842-
SmallVector<ValueDecl *, 1> results;
843-
tfModule->lookupValue({}, getIdentifier("TensorShape"),
844-
NLKind::UnqualifiedLookup, results);
845810

846-
for (auto result : results)
847-
if (auto CD = dyn_cast<StructDecl>(result))
848-
return getImpl().TensorShapeDecl = CD;
849-
return nullptr;
850-
}
851-
852-
/// Retrieve the decl for TensorFlow.TensorDataType iff the TensorFlow module has
853-
/// been imported. Otherwise, this returns null.
811+
/// Retrieve the decl for TensorDataType.
854812
StructDecl *ASTContext::getTensorDataTypeDecl() const {
855813
if (getImpl().TensorDataTypeDecl)
856814
return getImpl().TensorDataTypeDecl;
857815

858-
// See if the TensorFlow module was imported. If not, return null.
859-
auto tfModule = getLoadedModule(Id_TensorFlow);
860-
if (!tfModule)
816+
// See if the Stdlib module was imported. If not, return null.
817+
auto stdlibModule = getStdlibModule();
818+
if (!stdlibModule)
861819
return nullptr;
862820

863821
SmallVector<ValueDecl *, 1> results;
864-
tfModule->lookupValue({}, getIdentifier("TensorDataType"),
865-
NLKind::UnqualifiedLookup, results);
822+
stdlibModule->lookupValue({}, getIdentifier("TensorDataType"),
823+
NLKind::UnqualifiedLookup, results);
866824

867825
for (auto result : results)
868826
if (auto CD = dyn_cast<StructDecl>(result))
@@ -946,10 +904,6 @@ ProtocolDecl *ASTContext::getProtocol(KnownProtocolKind kind) const {
946904
// SWIFT_ENABLE_TENSORFLOW
947905
case KnownProtocolKind::TensorArrayProtocol:
948906
case KnownProtocolKind::TensorGroup:
949-
case KnownProtocolKind::TensorFlowDataTypeCompatible:
950-
case KnownProtocolKind::TensorProtocol:
951-
M = getLoadedModule(Id_TensorFlow);
952-
break;
953907
default:
954908
M = getStdlibModule();
955909
break;

branches/rxwei-patch-1/lib/IRGen/GenMeta.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4211,8 +4211,6 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) {
42114211
case KnownProtocolKind::KeyPathIterable:
42124212
case KnownProtocolKind::TensorArrayProtocol:
42134213
case KnownProtocolKind::TensorGroup:
4214-
case KnownProtocolKind::TensorFlowDataTypeCompatible:
4215-
case KnownProtocolKind::TensorProtocol:
42164214
case KnownProtocolKind::VectorNumeric:
42174215
case KnownProtocolKind::Differentiable:
42184216
return SpecialProtocol::None;

branches/rxwei-patch-1/stdlib/public/TensorFlow/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,13 @@ if (TENSORFLOW_SWIFT_BINDINGS)
5959
file(GLOB_RECURSE TENSORFLOW_SWIFT_BINDINGS_SOURCES
6060
"${TENSORFLOW_SWIFT_BINDINGS}/*.swift")
6161
list(APPEND SOURCES "${TENSORFLOW_SWIFT_BINDINGS_SOURCES}")
62-
file(GLOB_RECURSE TENSORFLOW_SWIFT_BINDINGS_SOURCES_CORE
63-
"${TENSORFLOW_SWIFT_BINDINGS}/Core/*.swift")
64-
list(APPEND SOURCES "${TENSORFLOW_SWIFT_BINDINGS_SOURCES_CORE}")
6562
endif()
6663

6764
# Copy TensorFlow high-level API sources, if they exist.
6865
if (TENSORFLOW_SWIFT_APIS)
6966
file(GLOB_RECURSE TENSORFLOW_SWIFT_API_SOURCES
70-
"${TENSORFLOW_SWIFT_APIS}/Sources/*.swift")
67+
"${TENSORFLOW_SWIFT_APIS}/Sources/*.swift"
68+
"${TENSORFLOW_SWIFT_APIS}/Sources/Core/*.swift")
7169
message(STATUS "Using TensorFlow high-level APIs library.")
7270
list(APPEND SOURCES "${TENSORFLOW_SWIFT_API_SOURCES}")
7371
endif()

branches/rxwei-patch-1/stdlib/public/TensorFlow/DataTypes.swift

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,13 @@
2121

2222
import CTensorFlow
2323

24-
/// A TensorFlow dynamic type value that can be created from types that conform
25-
/// to `TensorFlowScalar`.
26-
// This simply wraps a `TF_DataType` and allows user code to handle
27-
// `TF_DataType` without importing CTensorFlow, which pollutes the namespace
28-
// with TensorFlow C API declarations.
29-
@_fixed_layout
30-
public struct TensorDataType {
31-
public var _cDataType: TF_DataType
24+
public extension TensorDataType {
25+
public var _cDataType: TF_DataType {
26+
return TF_DataType(rawValue: _internalStorageType)
27+
}
3228

33-
@inlinable
34-
internal init(_ cDataType: TF_DataType) {
35-
self._cDataType = cDataType
29+
public init(_ cDataType: TF_DataType) {
30+
self.init(rawValue: cDataType.rawValue)
3631
}
3732
}
3833

branches/rxwei-patch-1/stdlib/public/TensorFlow/TensorGroup.swift

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,57 +16,6 @@
1616

1717
import CTensorFlow
1818

19-
/// A protocol representing types that can be mapped to `Array<CTensorHandle>`.
20-
///
21-
/// This protocol is defined separately from `TensorGroup` in order for the
22-
/// number of tensors to be determined at runtime. For example,
23-
/// `[Tensor<Float>]` may have an unknown number of elements at compile time.
24-
///
25-
/// This protocol can be derived automatically for structs whose stored
26-
/// properties all conform to the `TensorGroup` protocol. It cannot be derived
27-
/// automatically for structs whose properties all conform to
28-
/// `TensorArrayProtocol` due to the constructor requirement (i.e., in such
29-
/// cases it would be impossible to know how to break down `count` among the
30-
/// stored properties).
31-
public protocol TensorArrayProtocol {
32-
/// Writes the tensor handles to `address`, which must be allocated
33-
/// with enough capacity to hold `_tensorHandleCount` handles. The tensor
34-
/// handles written to `address` are borrowed: this container still
35-
/// owns them.
36-
func _unpackTensorHandles(into address: UnsafeMutablePointer<CTensorHandle>?)
37-
38-
var _tensorHandleCount: Int32 { get }
39-
var _typeList: [TensorDataType] { get }
40-
41-
init(_owning tensorHandles: UnsafePointer<CTensorHandle>?, count: Int)
42-
}
43-
44-
/// A protocol representing types that can be mapped to and from
45-
/// `Array<CTensorHandle>`.
46-
///
47-
/// When a `TensorGroup` is used as an argument to a tensor operation, it is
48-
/// passed as an argument list whose elements are the tensor fields of the type.
49-
///
50-
/// When a `TensorGroup` is returned as a result of a tensor operation, it is
51-
/// initialized with its tensor fields set to the tensor operation's tensor
52-
/// results.
53-
public protocol TensorGroup : TensorArrayProtocol {
54-
/// The types of the tensor stored properties in this type.
55-
static var _typeList: [TensorDataType] { get }
56-
57-
/// An array of `nil`s with the same number of elements as `_outputTypeList`.
58-
/// The `nil` represents unknown shape.
59-
// TODO: This is a protocol requirement so that conformances can provide
60-
// custom const-evaluable implementations. When the const-evaluator is
61-
// powerful enough to evaluate the default implementation, remove this
62-
// requirement.
63-
static var _unknownShapeList: [TensorShape?] { get }
64-
65-
/// Initializes a value of this type, taking ownership of the
66-
/// `_tensorHandleCount` tensors starting at address `tensorHandles`.
67-
init(_owning tensorHandles: UnsafePointer<CTensorHandle>?)
68-
}
69-
7019
public extension TensorGroup {
7120
/// The number of tensor fields in this type.
7221
static var _tensorHandleCount: Int32 { return Int32(Self._typeList.count) }

branches/rxwei-patch-1/stdlib/public/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ set(SWIFTLIB_ESSENTIAL
184184
StringGraphemeBreaking.swift # ORDER DEPENDENCY: Must follow UTF16.swift
185185
ValidUTF8Buffer.swift
186186
WriteBackMutableSlice.swift
187+
HackyTensorflowMigrationSupport.swift
187188
MigrationSupport.swift)
188189

189190
set(SWIFTLIB_ESSENTIAL_GYB_SOURCES

branches/rxwei-patch-1/stdlib/public/core/GroupInfo.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@
176176
"AutoDiff": [
177177
"AutoDiff.swift",
178178
],
179+
"HackyTensorflowMigrationSupport": [
180+
"HackyTensorflowMigrationSupport.swift",
181+
],
179182
"Optional": [
180183
"Optional.swift"
181184
],
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//===-- HackyTensorflowMigrationSupport.swift -----------------*- swift -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines the TensorGroup,TensorDataType and TensorArrayProtocol
14+
// types.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
// This whole file is a hack in order to allow moving TensorFlow out of the
19+
// swift compiler and to build it independently. There is an obviously more
20+
// general version of this using associated types or something that can be
21+
// given a general name.
22+
23+
public typealias CTensorHandle = OpaquePointer
24+
25+
/// A TensorFlow dynamic type value that can be created from types that conform
26+
/// to `TensorFlowScalar`.
27+
// This simply wraps a `TF_DataType` and allows user code to handle
28+
// `TF_DataType` without importing CTensorFlow, which pollutes the namespace
29+
// with TensorFlow C API declarations.
30+
public struct TensorDataType {
31+
public var _internalStorageType: UInt32
32+
33+
public init(rawValue: UInt32) {
34+
self._internalStorageType = rawValue
35+
}
36+
}
37+
38+
/// A protocol representing types that can be mapped to `Array<CTensorHandle>`.
39+
///
40+
/// This protocol is defined separately from `TensorGroup` in order for the
41+
/// number of tensors to be determined at runtime. For example,
42+
/// `[Tensor<Float>]` may have an unknown number of elements at compile time.
43+
///
44+
/// This protocol can be derived automatically for structs whose stored
45+
/// properties all conform to the `TensorGroup` protocol. It cannot be derived
46+
/// automatically for structs whose properties all conform to
47+
/// `TensorArrayProtocol` due to the constructor requirement (i.e., in such
48+
/// cases it would be impossible to know how to break down `count` among the
49+
/// stored properties).
50+
public protocol TensorArrayProtocol {
51+
/// Writes the tensor handles to `address`, which must be allocated
52+
/// with enough capacity to hold `_tensorHandleCount` handles. The tensor
53+
/// handles written to `address` are borrowed: this container still
54+
/// owns them.
55+
func _unpackTensorHandles(into address: UnsafeMutablePointer<CTensorHandle>?)
56+
57+
var _tensorHandleCount: Int32 { get }
58+
var _typeList: [TensorDataType] { get }
59+
60+
init(_owning tensorHandles: UnsafePointer<CTensorHandle>?, count: Int)
61+
}
62+
63+
/// A protocol representing types that can be mapped to and from
64+
/// `Array<CTensorHandle>`.
65+
///
66+
/// When a `TensorGroup` is used as an argument to a tensor operation, it is
67+
/// passed as an argument list whose elements are the tensor fields of the type.
68+
///
69+
/// When a `TensorGroup` is returned as a result of a tensor operation, it is
70+
/// initialized with its tensor fields set to the tensor operation's tensor
71+
/// results.
72+
public protocol TensorGroup : TensorArrayProtocol {
73+
74+
/// The types of the tensor stored properties in this type.
75+
static var _typeList: [TensorDataType] { get }
76+
77+
/// Initializes a value of this type, taking ownership of the
78+
/// `_tensorHandleCount` tensors starting at address `tensorHandles`.
79+
init(_owning tensorHandles: UnsafePointer<CTensorHandle>?)
80+
}

branches/rxwei-patch-1/test/Index/Store/unit-one-file-multi-file-invocation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
// CHECK: [[SWIFT]]
1515
// CHECK: DEPEND START
16-
// CHECK: Record | system | Swift.Math.Floating | [[MODULE]] | {{.+}}.swiftmodule_Math_Floating-{{.*}}
1716
// CHECK: Record | system | Swift.String | [[MODULE]] | {{.+}}.swiftmodule_String-{{.*}}
17+
// CHECK: Record | system | Swift.Math.Floating | [[MODULE]] | {{.+}}.swiftmodule_Math_Floating-{{.*}}
1818
// CHECK: DEPEND END
1919

2020
func test1() {

0 commit comments

Comments
 (0)