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
5 changes: 3 additions & 2 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3487,8 +3487,6 @@ TypeBase::getContextSubstitutions(const DeclContext *dc,
if (auto *ownerClass = dyn_cast<ClassDecl>(ownerNominal))
baseTy = baseTy->getSuperclassForDecl(ownerClass);

assert(ownerNominal == baseTy->getAnyNominal());

// Gather all of the substitutions for all levels of generic arguments.
auto genericSig = dc->getGenericSignatureOfContext();
if (!genericSig)
Expand All @@ -3498,6 +3496,9 @@ TypeBase::getContextSubstitutions(const DeclContext *dc,
unsigned n = params.size();

while (baseTy && n > 0) {
if (baseTy->is<ErrorType>())
break;

// For a bound generic type, gather the generic parameter -> generic
// argument substitutions.
if (auto boundGeneric = baseTy->getAs<BoundGenericType>()) {
Expand Down
74 changes: 35 additions & 39 deletions stdlib/public/core/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1911,54 +1911,50 @@ internal struct _ArrayAnyHashableBox<Element: Hashable>
}

// SWIFT_ENABLE_TENSORFLOW
extension Array where Element : Differentiable {
// TODO(TF-938): Add 'Element : Differentiable' constraint.
extension Array {
/// The view of an array as the differentiable product manifold of `Element`
/// multiplied with itself `count` times.
@frozen
public struct DifferentiableView : Differentiable {
private var _base: [Element]

/// The viewed array.
// I'm implementing this as a computed property instead of directly
// exposing `_base` because the `@differentiable` annotation does not make
// the stored property actually differentiable. I think this is a bug.
// Maybe it's related to `@frozen`?
// TODO: Determine if that is a bug, and fix.
public var base: [Element] {
@differentiable(wrt: self, vjp: _vjpBase)
get { return _base }
_modify { yield &_base }
}
public struct DifferentiableView {
var _base: [Element]
}
}

@usableFromInline
func _vjpBase() ->
([Element], (Array<Element>.TangentVector) -> TangentVector) {
return (base, { $0 })
}
extension Array.DifferentiableView : Differentiable where Element : Differentiable {
/// The viewed array.
public var base: [Element] {
@differentiable(wrt: self, vjp: _vjpBase)
get { return _base }
_modify { yield &_base }
}

/// Creates a differentiable view of the given array.
@differentiable(wrt: base, vjp: _vjpInit)
public init(_ base: [Element]) { self._base = base }
@usableFromInline
func _vjpBase() ->
([Element], (Array<Element>.TangentVector) -> TangentVector) {
return (base, { $0 })
}

@usableFromInline
static func _vjpInit(_ base: [Element]) ->
(Array.DifferentiableView, (TangentVector) -> TangentVector) {
return (Array.DifferentiableView(base), { $0 })
}
/// Creates a differentiable view of the given array.
@differentiable(wrt: base, vjp: _vjpInit)
public init(_ base: [Element]) { self._base = base }

// MARK: - Differentiable conformance.
@usableFromInline
static func _vjpInit(_ base: [Element]) ->
(Array.DifferentiableView, (TangentVector) -> TangentVector) {
return (Array.DifferentiableView(base), { $0 })
}

public typealias TangentVector =
Array<Element.TangentVector>.DifferentiableView
public typealias TangentVector =
Array<Element.TangentVector>.DifferentiableView

public mutating func move(along direction: TangentVector) {
precondition(
base.count == direction.base.count,
"cannot move Array.DifferentiableView with count \(base.count) along " +
"direction with different count \(direction.base.count)")
for i in base.indices {
base[i].move(along: direction.base[i])
}
public mutating func move(along direction: TangentVector) {
precondition(
base.count == direction.base.count,
"cannot move Array.DifferentiableView with count \(base.count) along " +
"direction with different count \(direction.base.count)")
for i in base.indices {
base[i].move(along: direction.base[i])
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion stdlib/public/core/KeyPathIterable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,20 @@ extension Array : KeyPathIterable {
}
}

extension Array.DifferentiableView : KeyPathIterable {
// TODO(TF-938): Remove 'Element : Differentiable' constraint.
extension Array.DifferentiableView : KeyPathIterable where Element : Differentiable {
public typealias AllKeyPaths = [PartialKeyPath<Array.DifferentiableView>]
public var allKeyPaths: [PartialKeyPath<Array.DifferentiableView>] {
return [\Array.DifferentiableView.base]
}
}

// TODO(TF-938): Remove this.
// This is neccessary now because otherwise the compiler complains:
// error: conditional conformance of type 'Array<Element>.DifferentiableView' to protocol
// 'KeyPathIterable' does not imply conformance to inherited protocol '_KeyPathIterableBase'
extension Array.DifferentiableView : _KeyPathIterableBase where Element : Differentiable {}

extension Dictionary : KeyPathIterable {
public typealias AllKeyPaths = [PartialKeyPath<Dictionary>]
public var allKeyPaths: [PartialKeyPath<Dictionary>] {
Expand Down
2 changes: 1 addition & 1 deletion utils/update_checkout/update-checkout-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@
"clang-tools-extra": "swift-DEVELOPMENT-SNAPSHOT-2019-10-13-a",
"libcxx": "swift-DEVELOPMENT-SNAPSHOT-2019-10-13-a",
"tensorflow": "7c7d924821a8b1b20433c2f3f484bbd409873a84",
"tensorflow-swift-apis": "f4f88d924d71eedb0709e26d0d5e4b7cfe94d830",
"tensorflow-swift-apis": "e70b979b7a3c2ebd38457b8d4058a0b310b4e4b0",
"tensorflow-swift-quote": "62c0a88dc64a201497a66cbbc087c0c7771edabc",
"indexstore-db": "swift-DEVELOPMENT-SNAPSHOT-2019-10-13-a",
"sourcekit-lsp": "swift-DEVELOPMENT-SNAPSHOT-2019-10-13-a"
Expand Down
3 changes: 2 additions & 1 deletion validation-test/ParseableInterface/verify_all_overlays.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
continue

# SWIFT_ENABLE_TENSORFLOW
# FIXME(TF-489): Re-enable this test after fixing `.swiftinterface` errors.
# TODO(TF-939): Enable this on DifferentiationUnittest, Python, and
# TensorFlow.
if module_name in ["Swift", "SwiftLang", "DifferentiationUnittest", "Python", "TensorFlow"]:
continue

Expand Down
4 changes: 0 additions & 4 deletions validation-test/ParseableInterface/verify_stdlib.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// Note that this test should still "pass" when Swift.swiftinterface has not
// been generated.

// SWIFT_ENABLE_TENSORFLOW
// FIXME(TF-489): Re-enable this test after fixing `.swiftinterface` errors.
// UNSUPPORTED: nonexecutable_test

// RUN: %empty-directory(%t)
// RUN: not ls %platform-module-dir/Swift.swiftmodule/%target-cpu.swiftinterface || %target-swift-frontend -build-module-from-parseable-interface %platform-module-dir/Swift.swiftmodule/%target-cpu.swiftinterface -parse-stdlib -o %t/Swift.swiftmodule

Expand Down