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] [Sema] Include certain 'let' properties in 'Differentiable' derived conformances. #33700

Merged
merged 1 commit into from
Aug 30, 2020

Conversation

rxwei
Copy link
Contributor

@rxwei rxwei commented Aug 30, 2020

Today, let properties are treated as if they had @noDerivative and excluded from the derived Differentiable conformance implementation. This is limiting to properties that have a non-mutating move(along:) (e.g. class properties), which can be mathematically treated as differentiable variables.

This patch changes the derived conformances behavior such that let properties will be included as differentiable variables if they have a non-mutating move(along:). This unblocks the following code:

final class Foo: Differentiable {
   let x: ClassStuff // Class type with a non-mutating 'move(along:)'

   // Synthesized code:
   //   struct TangentVector {
   //     var x: ClassStuff.TangentVector
   //   }
   //   ...
   //   func move(along direction: TangentVector) {
   //     x.move(along: direction.x)
   //   }
}

Resolves SR-13474 (rdar://67982207).

@rxwei rxwei changed the title [AutoDiff] [Sema] Allow certain let properties in 'Differentiable' derived conformances. [AutoDiff] [Sema] Include certain 'let' properties in 'Differentiable' derived conformances. Aug 30, 2020
@rxwei rxwei force-pushed the SR-13474-differentiable-class-let branch from 4842e0e to 694e691 Compare August 30, 2020 02:11
…' derived conformances.

Today, `let` properties are treated as if they had `@noDerivative` and
excluded from the derived `Differentaible` conformance implementation.
This is limiting to properties that have a non-mutating `move(along:)`
(e.g. class properties), which can be mathematically treated as
differentiable variables.

This patch changes the derived conformances behavior such that `let`
properties will be included as differentiable variables if they have a
non-mutating 'move(along:)'. This unblocks the following code:

```swift
class Foo: Differentiable {
   let x: ClassStuff // Class type

   // Synthesized code:
   //   struct TangentVector {
   //     var x: ClassStuff.TangentVector
   //   }
   //   ...
   //   func move(along direction: TangentVector) {
   //     x.move(along: direction.x)
   //   }
}
```

Resolves SR-13474 (rdar://67982207).
@rxwei rxwei force-pushed the SR-13474-differentiable-class-let branch from 694e691 to 702f738 Compare August 30, 2020 02:13
@rxwei
Copy link
Contributor Author

rxwei commented Aug 30, 2020

@swift-ci please smoke test

Copy link
Contributor

@dan-zheng dan-zheng left a comment

Choose a reason for hiding this comment

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

👍

@rxwei rxwei merged commit 76d0648 into swiftlang:master Aug 30, 2020
@rxwei rxwei deleted the SR-13474-differentiable-class-let branch August 30, 2020 04:47
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.

2 participants