Skip to content

[SR-14021] Functions accepting multiple inout parameters aren't differentiable #56412

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

Open
porterchild opened this issue Jan 7, 2021 · 2 comments
Labels
AutoDiff compiler The Swift compiler itself new feature

Comments

@porterchild
Copy link

Previous ID SR-14021
Radar None
Original Reporter @porterchild
Type New Feature
Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels New Feature, AutoDiff
Assignee None
Priority Medium

md5: aec1df3f108a4e0b962fbcb0167a08a4

is blocked by:

  • TF-1250 Support differentiation of functions with multiple results

Issue Description:

Declaring a differentiable function with more than one inout parameter results in the compiler error:

"Cannot differentiate functions with both an 'inout' parameter and a result"

@typesanitizer
Copy link

cc @dan-zheng

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@philipturner
Copy link
Contributor

I found something interesting when narrowing the reproducer found in #57331 (formerly SR-14989). If you make setA only differentiable with respect to a, then it triggers an incorrect error like the one described in this issue. This should be fixed in #41174.

Reproducer:

import _Differentiation

protocol P: Differentiable {
  @differentiable(reverse, wrt: self)
  var a: Double { get set }
}

struct Holder<ConcreteP: P>: Differentiable {
  var p: ConcreteP

  @differentiable(reverse, wrt: a)
  mutating func setA(a: Double) -> Double {
    fatalError()
  }
}

Built output:

(base) philipturner@m1-max-mbp bug % swiftc file.swift
file.swift:12:4: error: cannot differentiate functions with both an 'inout' parameter and a result
  @differentiable(reverse, wrt: a)
   ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoDiff compiler The Swift compiler itself new feature
Projects
None yet
Development

No branches or pull requests

3 participants