swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.28k stars 10.33k forks source link

[AutoDiff] Synthesized TangentVectors can no longer be extended #60461

Open BradLarson opened 2 years ago

BradLarson commented 2 years ago

Describe the bug Starting in roughly July, synthesized TangentVectors for Differentiable types can no longer be extended. Initially, these caused an assertion failure, then an error for a circular reference, and now (after PR #60373) they state that "Non-nominal type 'TestCase.TangentVector' cannot be extended". See below for a one-file reproducer.

Steps To Reproduce Place the following in a single file:

import _Differentiation

protocol TestProtocol {}

struct TestCase: Differentiable {
  var test1: Float
  var test2: Float
}

extension TestCase.TangentVector: TestProtocol {}

and build using swiftc test.swift.

Expected behavior Prior to ~July, the above code built cleanly. Nightly toolchain snapshots since then do not build this correctly.

Environment (please fill out the following information)

Both macOS and Linux, Swift nightly toolchain snapshots since July (latest tested: 2022-08-06)

BradLarson commented 2 years ago

@slavapestov - Based on your comments in #60364, you indicate that this wasn't working prior to the new diagnostic that now appears in this case. While we did see problems with circular references (with the same error as described in #60373) immediately prior to this new diagnostic, we have been able to use extensions to synthesized TangentVector types up until a few weeks ago. Should that never have worked to begin with, and we should not attempt to do this, or is the appearance of circular references for extensions to synthesized TangentVectors a more recent phenomenon that could be fixed?

jkshtj commented 4 months ago

Still an issue with the 05/24 toolchain.