swift-apis icon indicating copy to clipboard operation
swift-apis copied to clipboard

Remove `ParameterlessLayer` conformance workarounds

Open texasmichelle opened this issue 4 years ago • 1 comments

Associated type inference behavior was changed in apple/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.

A workaround was added in several PRs (#1034, #1035, swift-models#620, fastai/fastai_dev) and is forward-and backward-compatible, but makes code more verbose. If possible, identify a way to support the old behavior.

This caused build errors in 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 {
              ^

texasmichelle avatar Jul 03 '20 17:07 texasmichelle

@marcrasi: I wonder if this is effectively fixed by your recent TangentVector derived conformances changes?

dan-zheng avatar Dec 24 '20 12:12 dan-zheng