From 50fe4a289ff85bcc8c2ee7ddc1ad6b1436c154d7 Mon Sep 17 00:00:00 2001 From: marcrasi Date: Wed, 30 Oct 2019 14:22:54 -0700 Subject: [PATCH 1/6] fix TF-489: stdlib ParseableInterface tests --- stdlib/public/core/Array.swift | 74 +++++++++---------- stdlib/public/core/KeyPathIterable.swift | 9 ++- .../ParseableInterface/verify_all_overlays.py | 4 +- .../ParseableInterface/verify_stdlib.swift | 4 - 4 files changed, 44 insertions(+), 47 deletions(-) diff --git a/stdlib/public/core/Array.swift b/stdlib/public/core/Array.swift index 44260a599c5cf..866c5815b2c6a 100644 --- a/stdlib/public/core/Array.swift +++ b/stdlib/public/core/Array.swift @@ -1911,54 +1911,50 @@ internal struct _ArrayAnyHashableBox } // 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.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.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.DifferentiableView + public typealias TangentVector = + Array.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]) } } } diff --git a/stdlib/public/core/KeyPathIterable.swift b/stdlib/public/core/KeyPathIterable.swift index bd674fcd32f25..8ad9268bd790f 100644 --- a/stdlib/public/core/KeyPathIterable.swift +++ b/stdlib/public/core/KeyPathIterable.swift @@ -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] public var allKeyPaths: [PartialKeyPath] { return [\Array.DifferentiableView.base] } } +// TODO(TF-938): Remove this. +// This is neccessary now because otherwise the compiler complains: +// error: conditional conformance of type 'Array.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] public var allKeyPaths: [PartialKeyPath] { diff --git a/validation-test/ParseableInterface/verify_all_overlays.py b/validation-test/ParseableInterface/verify_all_overlays.py index ffb76a2c9df0d..6be7cc4cef621 100755 --- a/validation-test/ParseableInterface/verify_all_overlays.py +++ b/validation-test/ParseableInterface/verify_all_overlays.py @@ -49,9 +49,7 @@ else: continue - # SWIFT_ENABLE_TENSORFLOW - # FIXME(TF-489): Re-enable this test after fixing `.swiftinterface` errors. - if module_name in ["Swift", "SwiftLang", "DifferentiationUnittest", "Python", "TensorFlow"]: + if module_name in ["Swift", "SwiftLang", "DifferentiationUnittest", "Python"]: continue # swift -build-module-from-parseable-interface diff --git a/validation-test/ParseableInterface/verify_stdlib.swift b/validation-test/ParseableInterface/verify_stdlib.swift index d34c2a21474d8..9b4e1da91e176 100644 --- a/validation-test/ParseableInterface/verify_stdlib.swift +++ b/validation-test/ParseableInterface/verify_stdlib.swift @@ -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 From 3d27f3ff7727eb151f01ddace4073eefe0a7f8a9 Mon Sep 17 00:00:00 2001 From: marcrasi Date: Wed, 30 Oct 2019 14:54:42 -0700 Subject: [PATCH 2/6] verify_all_overlays still has some disabled tests, so add TODO about that --- validation-test/ParseableInterface/verify_all_overlays.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/validation-test/ParseableInterface/verify_all_overlays.py b/validation-test/ParseableInterface/verify_all_overlays.py index 6be7cc4cef621..825cd91d97af7 100755 --- a/validation-test/ParseableInterface/verify_all_overlays.py +++ b/validation-test/ParseableInterface/verify_all_overlays.py @@ -49,6 +49,8 @@ else: continue + # SWIFT_ENABLE_TENSORFLOW + # TODO(TF-939): Enable this on DifferentiationUnittest and Python. if module_name in ["Swift", "SwiftLang", "DifferentiationUnittest", "Python"]: continue From 6c72bc82e59d117cb47891eb90d88eb18e38ef50 Mon Sep 17 00:00:00 2001 From: marcrasi Date: Wed, 30 Oct 2019 15:22:02 -0700 Subject: [PATCH 3/6] update swift-apis to latest commit hash --- utils/update_checkout/update-checkout-config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/update_checkout/update-checkout-config.json b/utils/update_checkout/update-checkout-config.json index 2e89fc5e7387e..829df55cab2de 100644 --- a/utils/update_checkout/update-checkout-config.json +++ b/utils/update_checkout/update-checkout-config.json @@ -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": "668d4ca530bf451fc543c4093216caf99b93842f", "tensorflow-swift-quote": "62c0a88dc64a201497a66cbbc087c0c7771edabc", "indexstore-db": "swift-DEVELOPMENT-SNAPSHOT-2019-10-13-a", "sourcekit-lsp": "swift-DEVELOPMENT-SNAPSHOT-2019-10-13-a" From 7ff21b9fa77541f0964839f0acc8478074ce562b Mon Sep 17 00:00:00 2001 From: Marc Rasi Date: Wed, 30 Oct 2019 19:37:04 -0700 Subject: [PATCH 4/6] update swift-apis commit hash --- utils/update_checkout/update-checkout-config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/update_checkout/update-checkout-config.json b/utils/update_checkout/update-checkout-config.json index 829df55cab2de..06e52f8dccbbd 100644 --- a/utils/update_checkout/update-checkout-config.json +++ b/utils/update_checkout/update-checkout-config.json @@ -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": "668d4ca530bf451fc543c4093216caf99b93842f", + "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" From 44fd2f1497fc44324d88606b5a72e3aa1bf2ffa1 Mon Sep 17 00:00:00 2001 From: Marc Rasi Date: Thu, 31 Oct 2019 15:15:33 -0700 Subject: [PATCH 5/6] disable TensorFlow in verify_all_overlays because it is still failing --- validation-test/ParseableInterface/verify_all_overlays.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/validation-test/ParseableInterface/verify_all_overlays.py b/validation-test/ParseableInterface/verify_all_overlays.py index 825cd91d97af7..4cfbf5b2f2d3c 100755 --- a/validation-test/ParseableInterface/verify_all_overlays.py +++ b/validation-test/ParseableInterface/verify_all_overlays.py @@ -50,8 +50,9 @@ continue # SWIFT_ENABLE_TENSORFLOW - # TODO(TF-939): Enable this on DifferentiationUnittest and Python. - if module_name in ["Swift", "SwiftLang", "DifferentiationUnittest", "Python"]: + # TODO(TF-939): Enable this on DifferentiationUnittest, Python, and + # TensorFlow. + if module_name in ["Swift", "SwiftLang", "DifferentiationUnittest", "Python", "TensorFlow"]: continue # swift -build-module-from-parseable-interface From 415118d480eeaa99d42e770814d05fbb33240f99 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 23 Oct 2019 23:50:30 -0400 Subject: [PATCH 6/6] AST: Fix crash in getContextSubstitutions() when a class has a malformed superclass type It is possible for getSuperclassDecl() to return a non-null type, while getSuperclass() returns an ErrorType. In this case, getContextSubstitutions() could crash because the walk of the superclass chain via getSuperclass() might not find the context class. Instead of crashing in asserts builds, let getContextSubstitutions() silently build an invalid substitution map here, just as it does in no-asserts builds. --- lib/AST/Type.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 2e41a0cbd6aa6..444c1a202e1a3 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -3487,8 +3487,6 @@ TypeBase::getContextSubstitutions(const DeclContext *dc, if (auto *ownerClass = dyn_cast(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) @@ -3498,6 +3496,9 @@ TypeBase::getContextSubstitutions(const DeclContext *dc, unsigned n = params.size(); while (baseTy && n > 0) { + if (baseTy->is()) + break; + // For a bound generic type, gather the generic parameter -> generic // argument substitutions. if (auto boundGeneric = baseTy->getAs()) {