Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Fix ParameterlessLayer conformances. #1034

Merged
merged 1 commit into from
Jul 2, 2020

Conversation

dan-zheng
Copy link
Member

@dan-zheng dan-zheng commented Jul 1, 2020

Associated type inference behavior was changed in swiftlang/swift#32578:
derived conformances are now attempted before associated type inference.

This broke ParameterlessLayer, which relied on a
TangentVector == EmptyTangentVector same-type constraint to set a
default TangentVector type witness for conforming types.

Add explicit TangentVector type witnesses to
ParameterlessLayer-conforming types to fix this regression.

This workaround is forward- and backward-compatible, but makes code
more verbose.


This regression after swiftlang/swift#32578 is unfortunate, especially because
there doesn't seem to exist a workaround that doesn't produce a warning.

I'll write a minimal regression reproducer and ask on the PR if there's some principled
way to support the old behavior.


Fixes build errors from the 2020-06-30 master -> tensorflow merge:

tensorflow-swift-apis/Sources/TensorFlow/Layers/Core.swift:21:15: error: 'ParameterlessLayer' requires the types 'Flatten<Scalar>.TangentVector' and 'EmptyTangentVector' be equivalent
public struct Flatten<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
              ^
tensorflow-swift-apis/Sources/TensorFlow/Layers/Core.swift:21:15: note: requirement specified as 'Self.TangentVector' == 'EmptyTangentVector' [with Self = Flatten<Scalar>]
public struct Flatten<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
              ^
tensorflow-swift-apis/Sources/TensorFlow/Layers/Core.swift:21:15: error: type 'Flatten<Scalar>.TangentVector' does not conform to protocol 'VectorProtocol'
public struct Flatten<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
              ^
tensorflow-swift-apis/Sources/TensorFlow/Layers/Core.swift:39:15: error: 'ParameterlessLayer' requires the types 'Reshape<Scalar>.TangentVector' and 'EmptyTangentVector' be equivalent
public struct Reshape<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
              ^
tensorflow-swift-apis/Sources/TensorFlow/Layers/Core.swift:39:15: note: requirement specified as 'Self.TangentVector' == 'EmptyTangentVector' [with Self = Reshape<Scalar>]
public struct Reshape<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
              ^
tensorflow-swift-apis/Sources/TensorFlow/Layers/Core.swift:72:15: error: 'ParameterlessLayer' requires the types 'Function<Input, Output>.TangentVector' and 'EmptyTangentVector' be equivalent
public struct Function<Input: Differentiable, Output: Differentiable>: ParameterlessLayer {
              ^
tensorflow-swift-apis/Sources/TensorFlow/Layers/Core.swift:72:15: note: requirement specified as 'Self.TangentVector' == 'EmptyTangentVector' [with Self = Function<Input, Output>]
public struct Function<Input: Differentiable, Output: Differentiable>: ParameterlessLayer {
              ^
tensorflow-swift-apis/Sources/TensorFlow/Layers/Core.swift:72:15: error: type 'Function<Input, Output>.TangentVector' does not conform to protocol 'VectorProtocol'
public struct Function<Input: Differentiable, Output: Differentiable>: ParameterlessLayer {
              ^

Associated type inference behavior was changed in
swiftlang/swift#32578:
derived conformances are now attempted before associated type inference.

This broke `ParameterlessLayer`, which relied on a
`TangentVector == EmptyTangentVector` same-type constraint to set a
default `TangentVector` type witness for conforming types.

Add explicit `TangentVector` type witnesses to
`ParameterlessLayer`-conforming types to fix this regression.
@dan-zheng dan-zheng requested a review from texasmichelle July 1, 2020 23:48
@dan-zheng dan-zheng merged commit 6ecfd32 into master Jul 2, 2020
@dan-zheng dan-zheng deleted the fix-parameterlesslayer-conformances branch July 2, 2020 00:23
dan-zheng added a commit that referenced this pull request Jul 2, 2020
texasmichelle pushed a commit that referenced this pull request Jul 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants