Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AutoDiff] Fix incorrectly sorted members of synthesized 'TangentVector'. #36154

Merged
merged 1 commit into from
Feb 26, 2021

Conversation

rxwei
Copy link
Contributor

@rxwei rxwei commented Feb 25, 2021

Do not mark synthesized TangentVector members as synthesized so that the type checker won't sort them. We would like tangent vector members to have the same order as the properties in the parent declaration.

Also add typealias TangentVector = Self to the synthesized TangentVector so that it will not need its own Differentiable conformance derivation.

Resolves SR-14241 / rdar://74659803.

@rxwei rxwei requested review from CodaFi and dan-zheng February 25, 2021 06:31
@rxwei
Copy link
Contributor Author

rxwei commented Feb 25, 2021

@CodaFi With this fix, things seems to work fine without the need to manually evaluate TangentVector's conformances to the inherited protocols. Let me know if you still think it's the right fix.

  struct TangentVector : AdditiveArithmetic, Differentiable {
    @_hasStorage var simd: Array<Float>.DifferentiableView { get set }
    @_hasStorage var scalar: Float { get set }
    init(simd: Array<Float>.DifferentiableView, scalar: Float)
    typealias TangentVector = Thing.TangentVector
    static var zero: Thing.TangentVector { get }
    static func + (lhs: Thing.TangentVector, rhs: Thing.TangentVector) -> Thing.TangentVector
    static func - (lhs: Thing.TangentVector, rhs: Thing.TangentVector) -> Thing.TangentVector
    static func __derived_struct_equals(_ a: Thing.TangentVector, _ b: Thing.TangentVector) -> Bool
  }

I also tried your other suggestion to call getABIMembers() instead of getStoredProperties(), but that didn't seem to fix it.

@rxwei
Copy link
Contributor Author

rxwei commented Feb 25, 2021

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 4f531c3f148f73ce3a60cd0629718d8cbb245f8b

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 4f531c3f148f73ce3a60cd0629718d8cbb245f8b

@rxwei
Copy link
Contributor Author

rxwei commented Feb 25, 2021

@swift-ci please test

@rxwei rxwei requested a review from slavapestov February 25, 2021 20:58
Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make this specific to TangentVector, not cover all implicit decls.

@slavapestov
Copy link
Contributor

@rxwei Perhaps either the getParsedMembers() or getMembers() request on TangentVector should be where the stored properties are generated?

@rxwei
Copy link
Contributor Author

rxwei commented Feb 26, 2021

@rxwei Perhaps either the getParsedMembers() or getMembers() request on TangentVector should be where the stored properties are generated?

They are generated by the parent decl's conformance request, since Differentiable conformance derivation generates the nested TangentVector and its properties. I think the getStoredProperties() that caused the bug is when the Differentiable conformance of the TangentVector itself gets requested.

@rxwei
Copy link
Contributor Author

rxwei commented Feb 26, 2021

I attempted calling getParsedMembers() and getABIMembers() instead of calling getStoredProperties() in various places but it did not work; it looks like synthesized members are always sorted. What ended up working is marking TangentVector members as not synthesized. Thanks @CodaFi and @slavapestov for the suggestions!

…or'.

Do not mark synthesized `TangentVector` members as synthesized so that the type checker won't sort them. We would like tangent vector members to have the same order as the properties in the parent declaration.

Also add `typealias TangentVector = Self` to the synthesized `TangentVector` so that it will not need its own `Differentiable` conformance derivation.

Resolves SR-14241 / rdar://74659803.
@rxwei
Copy link
Contributor Author

rxwei commented Feb 26, 2021

@swift-ci please test

@rxwei
Copy link
Contributor Author

rxwei commented Feb 26, 2021

Since this change is now local to Differentiable derived conformances and does not touch other parts of the compiler, I'll go ahead and merge this in. Any additional feedback is welcome.

@rxwei rxwei merged commit 66ede5a into swiftlang:main Feb 26, 2021
@rxwei rxwei deleted the SR-14241 branch February 26, 2021 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants